Bug 1446951 - 1 - Remove nsINavHistory::ExecuteQueries. r=standard8

MozReview-Commit-ID: ATQLGKzMtnn

--HG--
extra : rebase_source : 17fe8abde9832bd475137eb9b629096bc4d0d1a8
This commit is contained in:
Marco Bonardo 2018-03-16 15:38:05 +01:00
Родитель af2626f976
Коммит 240b8426bf
16 изменённых файлов: 49 добавлений и 294 удалений

Просмотреть файл

@ -55,11 +55,8 @@ PlacesViewBase.prototype = {
let history = PlacesUtils.history;
let queries = { }, options = { };
history.queryStringToQueries(val, queries, { }, options);
if (!queries.value.length)
queries.value = [history.getNewQuery()];
let result = history.executeQueries(queries.value, queries.value.length,
options.value);
let query = queries.value.length ? queries.value[0] : history.getNewQuery();
let result = history.executeQuery(query, options.value);
result.addObserver(this);
return val;
},

Просмотреть файл

@ -86,7 +86,7 @@ function searchHistory(aInput) {
// call load() on the tree manually
// instead of setting the place attribute in history-panel.xul
// otherwise, we will end up calling load() twice
gHistoryTree.load([query], options);
gHistoryTree.load(query, options);
if (gHistoryGrouping == "lastvisited")
this.TelemetryStopwatch.finish("HISTORY_LASTVISITED_TREE_QUERY_TIME_MS");

Просмотреть файл

@ -98,17 +98,16 @@
options.includeHidden = !!includeHidden;
this.load([query], options);
this.load(query, options);
]]></body>
</method>
<method name="load">
<parameter name="queries"/>
<parameter name="query"/>
<parameter name="options"/>
<body><![CDATA[
let result = PlacesUtils.history
.executeQueries(queries, queries.length,
options);
.executeQuery(query, options);
let callback;
if (this.flatList) {
let onOpenFlatContainer = this.onOpenFlatContainer;
@ -292,12 +291,11 @@
var queryCountRef = { };
var optionsRef = { };
PlacesUtils.history.queryStringToQueries(val, queriesRef, queryCountRef, optionsRef);
if (queryCountRef.value == 0)
queriesRef.value = [PlacesUtils.history.getNewQuery()];
if (!optionsRef.value)
optionsRef.value = PlacesUtils.history.getNewQueryOptions();
let query = queriesRef.value.length ? queriesRef.value[0] : PlacesUtils.history.getNewQuery();
this.load(queriesRef.value, optionsRef.value);
this.load(query, optionsRef.value);
return val;
]]></setter>

Просмотреть файл

@ -421,13 +421,9 @@ var DownloadHistoryList = function(publicList, place) {
publicList.addView(this).catch(Cu.reportError);
let queries = {}, options = {};
PlacesUtils.history.queryStringToQueries(place, queries, {}, options);
if (!queries.value.length) {
queries.value = [PlacesUtils.history.getNewQuery()];
}
let query = queries.value.length ? queries.value[0] : PlacesUtils.history.getNewQuery();
let result = PlacesUtils.history.executeQueries(queries.value,
queries.value.length,
options.value);
let result = PlacesUtils.history.executeQuery(query, options.value);
result.addObserver(this);
};

Просмотреть файл

@ -1314,9 +1314,7 @@ var PlacesUtils = {
this.history.queryStringToQueries(aNode.uri, queries, {}, options);
options.value.excludeItems = aExcludeItems;
options.value.expandQueries = aExpandQueries;
return this.history.executeQueries(queries.value,
queries.value.length,
options.value).root;
return this.history.executeQuery(queries.value[0], options.value).root;
},
/**

Просмотреть файл

@ -941,9 +941,6 @@ interface nsINavHistoryQuery : nsISupports
* will return an array of strings sorted ascending in lexicographical order.
* The array may be empty in either case. Duplicate tags may be specified
* when setting the attribute, but the getter returns only unique tags.
*
* To search for items that are tagged with any given tags rather than all,
* multiple queries may be passed to nsINavHistoryService.executeQueries().
*/
attribute nsIVariant tags;
@ -1343,18 +1340,8 @@ interface nsINavHistoryService : nsISupports
in nsINavHistoryQueryOptions options);
/**
* Executes an array of queries. All of the query objects are ORed
* together. Within a query, all the terms are ANDed together as in
* executeQuery. See executeQuery()
*/
nsINavHistoryResult executeQueries(
[array,size_is(aQueryCount)] in nsINavHistoryQuery aQueries,
in unsigned long aQueryCount,
in nsINavHistoryQueryOptions options);
/**
* Converts a query URI-like string to an array of actual query objects for
* use to executeQueries(). The output query array may be empty if there is
* Converts a query URI-like string to an array of actual query objects.
* The output query array may be empty if there is
* no information. However, there will always be an options structure returned
* (if nothing is defined, it will just have the default values).
*/

Просмотреть файл

@ -33,6 +33,7 @@
#include "nsIEffectiveTLDService.h"
#include "nsIClassInfoImpl.h"
#include "nsIIDNService.h"
#include "nsQueryObject.h"
#include "nsThreadUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsMathUtils.h"
@ -192,9 +193,8 @@ NS_IMPL_CI_INTERFACE_GETTER(nsNavHistory,
namespace {
static int64_t GetSimpleBookmarksQueryFolder(
const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions);
static int64_t GetSimpleBookmarksQueryFolder(nsNavHistoryQuery* aQuery,
nsNavHistoryQueryOptions* aOptions);
static void ParseSearchTermsFromQueries(const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsTArray<nsTArray<nsString>*>* aTerms);
@ -1233,11 +1233,10 @@ nsNavHistory::GetNewQueryOptions(nsINavHistoryQueryOptions **_retval)
return NS_OK;
}
// nsNavHistory::ExecuteQuery
//
NS_IMETHODIMP
nsNavHistory::ExecuteQuery(nsINavHistoryQuery *aQuery, nsINavHistoryQueryOptions *aOptions,
nsNavHistory::ExecuteQuery(nsINavHistoryQuery *aQuery,
nsINavHistoryQueryOptions *aOptions,
nsINavHistoryResult** _retval)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
@ -1245,33 +1244,6 @@ nsNavHistory::ExecuteQuery(nsINavHistoryQuery *aQuery, nsINavHistoryQueryOptions
NS_ENSURE_ARG(aOptions);
NS_ENSURE_ARG_POINTER(_retval);
return ExecuteQueries(&aQuery, 1, aOptions, _retval);
}
// nsNavHistory::ExecuteQueries
//
// This function is actually very simple, we just create the proper root node (either
// a bookmark folder or a complex query node) and assign it to the result. The node
// will then populate itself accordingly.
//
// Quick overview of query operation: When you call this function, we will construct
// the correct container node and set the options you give it. This node will then
// fill itself. Folder nodes will call nsNavBookmarks::QueryFolderChildren, and
// all other queries will call GetQueryResults. If these results contain other
// queries, those will be populated when the container is opened.
NS_IMETHODIMP
nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, uint32_t aQueryCount,
nsINavHistoryQueryOptions *aOptions,
nsINavHistoryResult** _retval)
{
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
NS_ENSURE_ARG(aQueries);
NS_ENSURE_ARG(aOptions);
NS_ENSURE_ARG(aQueryCount);
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
// concrete options
nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions);
@ -1279,15 +1251,14 @@ nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, uint32_t aQueryCount
// concrete queries array
nsCOMArray<nsNavHistoryQuery> queries;
for (uint32_t i = 0; i < aQueryCount; i ++) {
nsCOMPtr<nsNavHistoryQuery> query = do_QueryInterface(aQueries[i], &rv);
NS_ENSURE_SUCCESS(rv, rv);
queries.AppendElement(query.forget());
}
RefPtr<nsNavHistoryQuery> query = do_QueryObject(aQuery);
NS_ENSURE_STATE(query);
queries.AppendObject(query);
// Create the root node.
RefPtr<nsNavHistoryContainerResultNode> rootNode;
int64_t folderId = GetSimpleBookmarksQueryFolder(queries, options);
int64_t folderId = GetSimpleBookmarksQueryFolder(query, options);
if (folderId) {
// In the simple case where we're just querying children of a single
// bookmark folder, we can more efficiently generate results.
@ -1315,7 +1286,7 @@ nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, uint32_t aQueryCount
// Create the result that will hold nodes. Inject batching status into it.
RefPtr<nsNavHistoryResult> result;
rv = nsNavHistoryResult::NewHistoryResult(aQueries, aQueryCount, options,
rv = nsNavHistoryResult::NewHistoryResult(queries, 1, options,
rootNode, isBatching(),
getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
@ -4000,7 +3971,9 @@ nsNavHistory::QueryRowToResult(int64_t itemId,
// handle it later.
if (NS_SUCCEEDED(rv)) {
// Check if this is a folder shortcut, so we can take a faster path.
int64_t targetFolderId = GetSimpleBookmarksQueryFolder(queries, options);
RefPtr<nsNavHistoryQuery> query = do_QueryObject(queries[0]);
NS_ENSURE_STATE(query);
int64_t targetFolderId = GetSimpleBookmarksQueryFolder(query, options);
if (targetFolderId) {
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
@ -4299,7 +4272,7 @@ namespace {
// GetSimpleBookmarksQueryFolder
//
// Determines if this set of queries is a simple bookmarks query for a
// Determines if this is a simple bookmarks query for a
// folder with no other constraints. In these common cases, we can more
// efficiently compute the results.
//
@ -4308,33 +4281,29 @@ namespace {
//
// Returns the folder ID if it is a simple folder query, 0 if not.
static int64_t
GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries,
GetSimpleBookmarksQueryFolder(nsNavHistoryQuery* aQuery,
nsNavHistoryQueryOptions* aOptions)
{
if (aQueries.Count() != 1)
return 0;
nsNavHistoryQuery* query = aQueries[0];
if (query->Folders().Length() != 1)
if (aQuery->Folders().Length() != 1)
return 0;
bool hasIt;
query->GetHasBeginTime(&hasIt);
aQuery->GetHasBeginTime(&hasIt);
if (hasIt)
return 0;
query->GetHasEndTime(&hasIt);
aQuery->GetHasEndTime(&hasIt);
if (hasIt)
return 0;
query->GetHasDomain(&hasIt);
aQuery->GetHasDomain(&hasIt);
if (hasIt)
return 0;
query->GetHasUri(&hasIt);
aQuery->GetHasUri(&hasIt);
if (hasIt)
return 0;
(void)query->GetHasSearchTerms(&hasIt);
(void)aQuery->GetHasSearchTerms(&hasIt);
if (hasIt)
return 0;
if (query->Tags().Length() > 0)
if (aQuery->Tags().Length() > 0)
return 0;
if (aOptions->MaxResults() > 0)
return 0;
@ -4347,7 +4316,7 @@ GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// Don't care about onlyBookmarked flag, since specifying a bookmark
// folder is inferring onlyBookmarked.
return query->Folders()[0];
return aQuery->Folders()[0];
}

Просмотреть файл

@ -4083,13 +4083,13 @@ nsNavHistoryResult::StopObserving()
* register ourselves.
*/
nsresult
nsNavHistoryResult::Init(nsINavHistoryQuery** aQueries,
nsNavHistoryResult::Init(nsCOMArray<nsNavHistoryQuery>& aQueries,
uint32_t aQueryCount,
nsNavHistoryQueryOptions *aOptions)
{
nsresult rv;
NS_ASSERTION(aOptions, "Must have valid options");
NS_ASSERTION(aQueries && aQueryCount > 0, "Must have >1 query in result");
NS_ASSERTION(aQueries.Count() == aQueryCount && aQueryCount > 0, "Must have >1 query in result");
// Fill saved source queries with copies of the original (the caller might
// change their original objects, and we always want to reflect the source
@ -4119,7 +4119,7 @@ nsNavHistoryResult::Init(nsINavHistoryQuery** aQueries,
* Constructs a new history result object.
*/
nsresult // static
nsNavHistoryResult::NewHistoryResult(nsINavHistoryQuery** aQueries,
nsNavHistoryResult::NewHistoryResult(nsCOMArray<nsNavHistoryQuery>& aQueries,
uint32_t aQueryCount,
nsNavHistoryQueryOptions* aOptions,
nsNavHistoryContainerResultNode* aRoot,

Просмотреть файл

@ -101,7 +101,7 @@ class nsNavHistoryResult final : public nsSupportsWeakReference,
public nsINavHistoryObserver
{
public:
static nsresult NewHistoryResult(nsINavHistoryQuery** aQueries,
static nsresult NewHistoryResult(nsCOMArray<nsNavHistoryQuery>& aQueries,
uint32_t aQueryCount,
nsNavHistoryQueryOptions* aOptions,
nsNavHistoryContainerResultNode* aRoot,
@ -135,7 +135,7 @@ public:
public:
// two-stage init, use NewHistoryResult to construct
explicit nsNavHistoryResult(nsNavHistoryContainerResultNode* mRoot);
nsresult Init(nsINavHistoryQuery** aQueries,
nsresult Init(nsCOMArray<nsNavHistoryQuery>& aQueries,
uint32_t aQueryCount,
nsNavHistoryQueryOptions *aOptions);

Просмотреть файл

@ -1,76 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function check_queries_results(aQueries, aOptions, aExpectedBookmarks) {
var result = PlacesUtils.history.executeQueries(aQueries, aQueries.length, aOptions);
var root = result.root;
root.containerOpen = true;
// Dump found nodes.
for (let i = 0; i < root.childCount; i++) {
dump("nodes[" + i + "]: " + root.getChild(0).title + "\n");
}
Assert.equal(root.childCount, aExpectedBookmarks.length);
for (let i = 0; i < root.childCount; i++) {
Assert.equal(root.getChild(i).bookmarkGuid, aExpectedBookmarks[i].guid);
}
root.containerOpen = false;
}
// main
add_task(async function run_test() {
let bookmarks = await PlacesUtils.bookmarks.insertTree({
guid: PlacesUtils.bookmarks.menuGuid,
children: [{
title: "123 0",
url: "http://foo.tld",
}, {
title: "456",
url: "http://foo.tld",
}, {
title: "123 456",
url: "http://foo.tld",
}, {
title: "789 456",
url: "http://foo.tld",
}]
});
/**
* All of the query objects are ORed together. Within a query, all the terms
* are ANDed together. See nsINavHistory.idl.
*/
var queries = [];
queries.push(PlacesUtils.history.getNewQuery());
queries.push(PlacesUtils.history.getNewQuery());
var options = PlacesUtils.history.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
// Test 1
dump("Test searching for 123 OR 789\n");
queries[0].searchTerms = "123";
queries[1].searchTerms = "789";
check_queries_results(queries, options, [
bookmarks[0],
bookmarks[2],
bookmarks[3]
]);
// Test 2
dump("Test searching for 123 OR 456\n");
queries[0].searchTerms = "123";
queries[1].searchTerms = "456";
check_queries_results(queries, options, bookmarks);
// Test 3
dump("Test searching for 00 OR 789\n");
queries[0].searchTerms = "00";
queries[1].searchTerms = "789";
check_queries_results(queries, options, [bookmarks[3]]);
});

Просмотреть файл

@ -8,7 +8,6 @@ skip-if = toolkit == 'android'
[test_385829.js]
[test_388695.js]
[test_393498.js]
[test_395593.js]
[test_405938_restore_queries.js]
[test_424958-json-quoted-folders.js]
[test_448584.js]

Просмотреть файл

@ -469,45 +469,6 @@ add_task(async function ORed_queries() {
PlacesUtils.tagging.tagURI(nsiuri, tags);
}
info("Query for /1 OR query for /2 should match both /1 and /2");
var [query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
var [query2] = makeQuery(urisAndTags["http://example.com/2"]);
var root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
info("Query for /1 OR query on bogus tag should match only /1");
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
[query2] = makeQuery(["bogus"]);
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1"]);
info("Query for /1 OR query for /1 should match only /1");
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
[query2] = makeQuery(urisAndTags["http://example.com/1"]);
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1"]);
info("Query for /1 with tagsAreNot OR query for /2 with tagsAreNot " +
"should match both /1 and /2");
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"], true);
[query2] = makeQuery(urisAndTags["http://example.com/2"], true);
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
info("Query for /1 OR query for /2 with tagsAreNot should match " +
"only /1");
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
[query2] = makeQuery(urisAndTags["http://example.com/2"], true);
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1"]);
info("Query for /1 OR query for /1 with tagsAreNot should match " +
"both URIs");
[query1, opts] = makeQuery(urisAndTags["http://example.com/1"]);
[query2] = makeQuery(urisAndTags["http://example.com/1"], true);
root = PlacesUtils.history.executeQueries([query1, query2], 2, opts).root;
queryResultsAre(root, ["http://example.com/1", "http://example.com/2"]);
// Clean up.
for (let [pURI, tags] of Object.entries(urisAndTags)) {
let nsiuri = uri(pURI);

Просмотреть файл

@ -12,15 +12,12 @@
* @returns the folder id of the folder of the root node of the query.
*/
function folder_id(aQuery) {
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
dump("Checking query '" + aQuery + "'\n");
info("Checking query '" + aQuery + "'\n");
var options = { };
var queries = { };
var size = { };
hs.queryStringToQueries(aQuery, queries, size, options);
var result = hs.executeQueries(queries.value, size.value, options.value);
PlacesUtils.history.queryStringToQueries(aQuery, queries, size, options);
var result = PlacesUtils.history.executeQuery(queries.value, options.value);
var root = result.root;
root.containerOpen = true;
Assert.ok(root.hasChildren);
@ -53,9 +50,7 @@ add_task(async function test_history_string_to_query() {
});
// add something to the tags folder
var ts = Cc["@mozilla.org/browser/tagging-service;1"].
getService(Ci.nsITaggingService);
ts.tagURI(uri("http://www.example.com/"), ["tag"]);
PlacesUtils.tagging.tagURI(uri("http://www.example.com/"), ["tag"]);
// add something to the unfiled bookmarks folder
await PlacesUtils.bookmarks.insert({
@ -71,9 +66,8 @@ add_task(async function test_history_string_to_query() {
url: "http://example.com/tf/",
});
for (var i = 0; i < QUERIES.length; i++) {
var result = folder_id(QUERIES[i]);
dump("expected " + FOLDER_IDS[i] + ", got " + result + "\n");
for (let i = 0; i < QUERIES.length; i++) {
let result = folder_id(QUERIES[i]);
Assert.equal(FOLDER_IDS[i], result);
}
});

Просмотреть файл

@ -36,28 +36,8 @@ async function addBookmarks() {
await PlacesUtils.bookmarks.insert({
url, parentGuid: PlacesUtils.bookmarks.menuGuid
});
Assert.ok(await PlacesUtils.bookmarks.fetch({ url }), "Url is bookmarked");
}
checkBookmarksExist();
}
/**
* Checks that all of the bookmarks created for |uris| exist. It works by
* creating one query per URI and then ORing all the queries. The number of
* results returned should be uris.length.
*/
function checkBookmarksExist() {
let hs = PlacesUtils.history;
let queries = uris.map(function(u) {
let q = hs.getNewQuery();
q.uri = uri(u);
return q;
});
let options = hs.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_BOOKMARKS;
let root = hs.executeQueries(queries, uris.length, options).root;
root.containerOpen = true;
Assert.equal(root.childCount, uris.length);
root.containerOpen = false;
}
/**

Просмотреть файл

@ -1,47 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* Adds a test URI visit to history.
*
* @param aURI
* The URI to add a visit for.
* @param aReferrer
* The referring URI for the given URI. This can be null.
*/
async function add_visit(aURI, aDayOffset, aTransition) {
await PlacesTestUtils.addVisits({
uri: aURI,
transition: aTransition,
visitDate: (Date.now() + aDayOffset * 86400000) * 1000
});
}
add_task(async function test_execute() {
await add_visit(uri("http://mirror1.mozilla.com/a"), -1, TRANSITION_LINK);
await add_visit(uri("http://mirror2.mozilla.com/b"), -2, TRANSITION_LINK);
await add_visit(uri("http://mirror3.mozilla.com/c"), -4, TRANSITION_FRAMED_LINK);
await add_visit(uri("http://mirror1.google.com/b"), -1, TRANSITION_EMBED);
await add_visit(uri("http://mirror2.google.com/a"), -2, TRANSITION_LINK);
await add_visit(uri("http://mirror1.apache.org/b"), -3, TRANSITION_LINK);
await add_visit(uri("http://mirror2.apache.org/a"), -4, TRANSITION_FRAMED_LINK);
let queries = [
PlacesUtils.history.getNewQuery(),
PlacesUtils.history.getNewQuery()
];
queries[0].domain = "mozilla.com";
queries[1].domain = "google.com";
let root = PlacesUtils.history.executeQueries(
queries, queries.length, PlacesUtils.history.getNewQueryOptions()
).root;
root.containerOpen = true;
let childCount = root.childCount;
root.containerOpen = false;
Assert.equal(childCount, 3);
});

Просмотреть файл

@ -90,7 +90,6 @@ skip-if = (os == 'win' && ccov) # Bug 1423667
[test_markpageas.js]
[test_metadata.js]
[test_mozIAsyncLivemarks.js]
[test_multi_queries.js]
[test_multi_word_tags.js]
[test_nsINavHistoryViewer.js]
[test_null_interfaces.js]