diff options
-rw-r--r-- | chrome/browser/extensions/api/history/history_api.cc | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/api/history/history_api.h | 3 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 20 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.h | 6 | ||||
-rw-r--r-- | chrome/browser/history/history_marshaling.h | 4 | ||||
-rw-r--r-- | chrome/browser/history/history_querying_unittest.cc | 14 | ||||
-rw-r--r-- | chrome/browser/history/history_service.cc | 19 | ||||
-rw-r--r-- | chrome/browser/history/history_service.h | 12 | ||||
-rw-r--r-- | chrome/browser/importer/profile_writer_unittest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/supervised_user/supervised_user_browsertest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/history_menu_bridge.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/history_menu_bridge.mm | 5 | ||||
-rw-r--r-- | chrome/browser/ui/sync/profile_signin_confirmation_helper.cc | 10 | ||||
-rw-r--r-- | chrome/browser/ui/webui/history_ui.cc | 19 | ||||
-rw-r--r-- | chrome/browser/ui/webui/history_ui.h | 5 | ||||
-rw-r--r-- | chrome/test/base/ui_test_utils.cc | 13 | ||||
-rw-r--r-- | chrome/test/base/ui_test_utils.h | 3 |
17 files changed, 78 insertions, 84 deletions
diff --git a/chrome/browser/extensions/api/history/history_api.cc b/chrome/browser/extensions/api/history/history_api.cc index a454ce2..381dacd 100644 --- a/chrome/browser/extensions/api/history/history_api.cc +++ b/chrome/browser/extensions/api/history/history_api.cc @@ -344,16 +344,16 @@ bool HistorySearchFunction::RunAsyncImpl() { HistoryService* hs = HistoryServiceFactory::GetForProfile( GetProfile(), Profile::EXPLICIT_ACCESS); - hs->QueryHistory(search_text, options, &cancelable_consumer_, + hs->QueryHistory(search_text, + options, base::Bind(&HistorySearchFunction::SearchComplete, - base::Unretained(this))); + base::Unretained(this)), + &task_tracker_); return true; } -void HistorySearchFunction::SearchComplete( - HistoryService::Handle request_handle, - history::QueryResults* results) { +void HistorySearchFunction::SearchComplete(history::QueryResults* results) { HistoryItemList history_item_vec; if (results && !results->empty()) { for (history::QueryResults::URLResultVector::const_iterator iterator = diff --git a/chrome/browser/extensions/api/history/history_api.h b/chrome/browser/extensions/api/history/history_api.h index cd1e942..e6895fd 100644 --- a/chrome/browser/extensions/api/history/history_api.h +++ b/chrome/browser/extensions/api/history/history_api.h @@ -151,8 +151,7 @@ class HistorySearchFunction : public HistoryFunctionWithCallback { virtual bool RunAsyncImpl() OVERRIDE; // Callback for the history function to provide results. - void SearchComplete(HistoryService::Handle request_handle, - history::QueryResults* results); + void SearchComplete(history::QueryResults* results); }; class HistoryAddUrlFunction : public HistoryFunction { diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index b0b7220..a919679 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -1195,26 +1195,20 @@ void HistoryBackend::RemoveDownloads(const std::set<uint32>& ids) { ids.size() - num_downloads_deleted); } -void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, - const base::string16& text_query, - const QueryOptions& options) { - if (request->canceled()) - return; - - TimeTicks beginning_time = TimeTicks::Now(); - +void HistoryBackend::QueryHistory(const base::string16& text_query, + const QueryOptions& options, + QueryResults* query_results) { + DCHECK(query_results); + base::TimeTicks beginning_time = base::TimeTicks::Now(); if (db_) { if (text_query.empty()) { // Basic history query for the main database. - QueryHistoryBasic(options, &request->value); + QueryHistoryBasic(options, query_results); } else { // Text history query. - QueryHistoryText(text_query, options, &request->value); + QueryHistoryText(text_query, options, query_results); } } - - request->ForwardResult(request->handle(), &request->value); - UMA_HISTOGRAM_TIMES("History.QueryHistory", TimeTicks::Now() - beginning_time); } diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index abab141..393cd1f 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -152,9 +152,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, void QueryURL(const GURL& url, bool want_visits, QueryURLResult* query_url_result); - void QueryHistory(scoped_refptr<QueryHistoryRequest> request, - const base::string16& text_query, - const QueryOptions& options); + void QueryHistory(const base::string16& text_query, + const QueryOptions& options, + QueryResults* query_results); void QueryRedirectsFrom(scoped_refptr<QueryRedirectsRequest> request, const GURL& url); void QueryRedirectsTo(scoped_refptr<QueryRedirectsRequest> request, diff --git a/chrome/browser/history/history_marshaling.h b/chrome/browser/history/history_marshaling.h index 549f6409..eaf66f1 100644 --- a/chrome/browser/history/history_marshaling.h +++ b/chrome/browser/history/history_marshaling.h @@ -21,10 +21,6 @@ namespace history { // Querying ------------------------------------------------------------------- -typedef CancelableRequest1<HistoryService::QueryHistoryCallback, - QueryResults> - QueryHistoryRequest; - typedef CancelableRequest1<HistoryService::QueryRedirectsCallback, history::RedirectList> QueryRedirectsRequest; diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc index 9f274ac..e6a49f2 100644 --- a/chrome/browser/history/history_querying_unittest.cc +++ b/chrome/browser/history/history_querying_unittest.cc @@ -10,6 +10,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/path_service.h" #include "base/strings/utf_string_conversions.h" +#include "base/task/cancelable_task_tracker.h" #include "chrome/browser/history/history_service.h" #include "testing/gtest/include/gtest/gtest.h" @@ -78,10 +79,11 @@ class HistoryQueryTest : public testing::Test { void QueryHistory(const std::string& text_query, const QueryOptions& options, QueryResults* results) { - history_->QueryHistory( - base::UTF8ToUTF16(text_query), options, &consumer_, - base::Bind(&HistoryQueryTest::QueryHistoryComplete, - base::Unretained(this))); + history_->QueryHistory(base::UTF8ToUTF16(text_query), + options, + base::Bind(&HistoryQueryTest::QueryHistoryComplete, + base::Unretained(this)), + &tracker_); // Will go until ...Complete calls Quit. base::MessageLoop::current()->Run(); results->Swap(&last_query_results_); @@ -186,7 +188,7 @@ class HistoryQueryTest : public testing::Test { } } - void QueryHistoryComplete(HistoryService::Handle, QueryResults* results) { + void QueryHistoryComplete(QueryResults* results) { results->Swap(&last_query_results_); base::MessageLoop::current()->Quit(); // Will return out to QueryHistory. } @@ -197,7 +199,7 @@ class HistoryQueryTest : public testing::Test { base::FilePath history_dir_; - CancelableRequestConsumer consumer_; + base::CancelableTaskTracker tracker_; // The QueryHistoryComplete callback will put the results here so QueryHistory // can return them. diff --git a/chrome/browser/history/history_service.cc b/chrome/browser/history/history_service.cc index 8c6405e..2d8883c 100644 --- a/chrome/browser/history/history_service.cc +++ b/chrome/browser/history/history_service.cc @@ -779,15 +779,22 @@ void HistoryService::RemoveDownloads(const std::set<uint32>& ids) { &HistoryBackend::RemoveDownloads, ids); } -HistoryService::Handle HistoryService::QueryHistory( +base::CancelableTaskTracker::TaskId HistoryService::QueryHistory( const base::string16& text_query, const history::QueryOptions& options, - CancelableRequestConsumerBase* consumer, - const QueryHistoryCallback& callback) { + const QueryHistoryCallback& callback, + base::CancelableTaskTracker* tracker) { DCHECK(thread_checker_.CalledOnValidThread()); - return Schedule(PRIORITY_UI, &HistoryBackend::QueryHistory, consumer, - new history::QueryHistoryRequest(callback), - text_query, options); + history::QueryResults* query_results = new history::QueryResults(); + return tracker->PostTaskAndReply( + thread_->message_loop_proxy().get(), + FROM_HERE, + base::Bind(&HistoryBackend::QueryHistory, + history_backend_.get(), + text_query, + options, + base::Unretained(query_results)), + base::Bind(callback, base::Owned(query_results))); } HistoryService::Handle HistoryService::QueryRedirectsFrom( diff --git a/chrome/browser/history/history_service.h b/chrome/browser/history/history_service.h index 1bc53f4..da5cfee 100644 --- a/chrome/browser/history/history_service.h +++ b/chrome/browser/history/history_service.h @@ -250,16 +250,16 @@ class HistoryService : public CancelableRequestProvider, // Provides the result of a query. See QueryResults in history_types.h. // The common use will be to use QueryResults.Swap to suck the contents of // the results out of the passed in parameter and take ownership of them. - typedef base::Callback<void(Handle, history::QueryResults*)> - QueryHistoryCallback; + typedef base::Callback<void(history::QueryResults*)> QueryHistoryCallback; // Queries all history with the given options (see QueryOptions in // history_types.h). If empty, all results matching the given options // will be returned. - Handle QueryHistory(const base::string16& text_query, - const history::QueryOptions& options, - CancelableRequestConsumerBase* consumer, - const QueryHistoryCallback& callback); + base::CancelableTaskTracker::TaskId QueryHistory( + const base::string16& text_query, + const history::QueryOptions& options, + const QueryHistoryCallback& callback, + base::CancelableTaskTracker* tracker); // Called when the results of QueryRedirectsFrom are available. // The given vector will contain a list of all redirects, not counting diff --git a/chrome/browser/importer/profile_writer_unittest.cc b/chrome/browser/importer/profile_writer_unittest.cc index 4e58c16..e56867c 100644 --- a/chrome/browser/importer/profile_writer_unittest.cc +++ b/chrome/browser/importer/profile_writer_unittest.cc @@ -95,18 +95,17 @@ class ProfileWriterTest : public testing::Test { HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); history::QueryOptions options; - CancelableRequestConsumer history_request_consumer; + base::CancelableTaskTracker history_task_tracker; history_service->QueryHistory( base::string16(), options, - &history_request_consumer, base::Bind(&ProfileWriterTest::HistoryQueryComplete, - base::Unretained(this))); + base::Unretained(this)), + &history_task_tracker); base::MessageLoop::current()->Run(); } - void HistoryQueryComplete(HistoryService::Handle handle, - history::QueryResults* results) { + void HistoryQueryComplete(history::QueryResults* results) { base::MessageLoop::current()->Quit(); history_count_ = results->size(); } diff --git a/chrome/browser/supervised_user/supervised_user_browsertest.cc b/chrome/browser/supervised_user/supervised_user_browsertest.cc index 3400638..0377463 100644 --- a/chrome/browser/supervised_user/supervised_user_browsertest.cc +++ b/chrome/browser/supervised_user/supervised_user_browsertest.cc @@ -136,22 +136,21 @@ class SupervisedUserBlockModeTest : public InProcessBrowserTest { const std::string& text_query, const history::QueryOptions& options, history::QueryResults* results) { - CancelableRequestConsumer history_request_consumer; base::RunLoop run_loop; + base::CancelableTaskTracker history_task_tracker; history_service->QueryHistory( base::UTF8ToUTF16(text_query), options, - &history_request_consumer, base::Bind(&SupervisedUserBlockModeTest::QueryHistoryComplete, base::Unretained(this), results, - &run_loop)); + &run_loop), + &history_task_tracker); run_loop.Run(); // Will go until ...Complete calls Quit. } void QueryHistoryComplete(history::QueryResults* new_results, base::RunLoop* run_loop, - HistoryService::Handle /* handle */, history::QueryResults* results) { results->Swap(new_results); run_loop->Quit(); // Will return out to QueryHistory. diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.h b/chrome/browser/ui/cocoa/history_menu_bridge.h index f90094b..91d531a 100644 --- a/chrome/browser/ui/cocoa/history_menu_bridge.h +++ b/chrome/browser/ui/cocoa/history_menu_bridge.h @@ -179,8 +179,7 @@ class HistoryMenuBridge : public content::NotificationObserver, // Callback method for when HistoryService query results are ready with the // most recently-visited sites. - void OnVisitedHistoryResults(CancelableRequestProvider::Handle handle, - history::QueryResults* results); + void OnVisitedHistoryResults(history::QueryResults* results); // Creates a HistoryItem* for the given tab entry. Caller takes ownership of // the result and must delete it when finished. diff --git a/chrome/browser/ui/cocoa/history_menu_bridge.mm b/chrome/browser/ui/cocoa/history_menu_bridge.mm index 1c20e78..715998f 100644 --- a/chrome/browser/ui/cocoa/history_menu_bridge.mm +++ b/chrome/browser/ui/cocoa/history_menu_bridge.mm @@ -402,13 +402,12 @@ void HistoryMenuBridge::CreateMenu() { history_service_->QueryHistory( base::string16(), options, - &cancelable_request_consumer_, base::Bind(&HistoryMenuBridge::OnVisitedHistoryResults, - base::Unretained(this))); + base::Unretained(this)), + &cancelable_task_tracker_); } void HistoryMenuBridge::OnVisitedHistoryResults( - CancelableRequestProvider::Handle handle, history::QueryResults* results) { NSMenu* menu = HistoryMenu(); ClearMenuSection(menu, kVisited); diff --git a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc index 6bf0535..40cf713 100644 --- a/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc +++ b/chrome/browser/ui/sync/profile_signin_confirmation_helper.cc @@ -8,6 +8,7 @@ #include "base/memory/ref_counted.h" #include "base/prefs/pref_service.h" #include "base/strings/string16.h" +#include "base/task/cancelable_task_tracker.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/common/cancelable_request.h" #include "chrome/browser/extensions/extension_service.h" @@ -84,7 +85,6 @@ class ProfileSigninConfirmationHelper ~ProfileSigninConfirmationHelper(); void OnHistoryQueryResults(size_t max_entries, - CancelableRequestProvider::Handle handle, history::QueryResults* results); void ReturnResult(bool result); @@ -93,6 +93,7 @@ class ProfileSigninConfirmationHelper // Used for async tasks. CancelableRequestConsumer request_consumer_; + base::CancelableTaskTracker task_tracker_; // Keep track of how many async requests are pending. int pending_requests_; @@ -120,7 +121,6 @@ ProfileSigninConfirmationHelper::~ProfileSigninConfirmationHelper() { void ProfileSigninConfirmationHelper::OnHistoryQueryResults( size_t max_entries, - CancelableRequestProvider::Handle handle, history::QueryResults* results) { history::QueryResults owned_results; results->Swap(&owned_results); @@ -142,10 +142,12 @@ void ProfileSigninConfirmationHelper::CheckHasHistory(int max_entries) { history::QueryOptions opts; opts.max_count = max_entries; service->QueryHistory( - base::string16(), opts, &request_consumer_, + base::string16(), + opts, base::Bind(&ProfileSigninConfirmationHelper::OnHistoryQueryResults, this, - max_entries)); + max_entries), + &task_tracker_); } void ProfileSigninConfirmationHelper::CheckHasTypedURLs() { diff --git a/chrome/browser/ui/webui/history_ui.cc b/chrome/browser/ui/webui/history_ui.cc index 12b3470..8b4f6aa 100644 --- a/chrome/browser/ui/webui/history_ui.cc +++ b/chrome/browser/ui/webui/history_ui.cc @@ -391,7 +391,7 @@ BrowsingHistoryHandler::BrowsingHistoryHandler() } BrowsingHistoryHandler::~BrowsingHistoryHandler() { - history_request_consumer_.CancelAllRequests(); + query_task_tracker_.TryCancelAll(); web_history_request_.reset(); } @@ -434,7 +434,7 @@ bool BrowsingHistoryHandler::ExtractIntegerValueAtIndex( void BrowsingHistoryHandler::WebHistoryTimeout() { // TODO(dubroy): Communicate the failure to the front end. - if (!history_request_consumer_.HasPendingRequests()) + if (!query_task_tracker_.HasTrackedTasks()) ReturnResultsToFrontEnd(); UMA_HISTOGRAM_ENUMERATION( @@ -447,7 +447,7 @@ void BrowsingHistoryHandler::QueryHistory( Profile* profile = Profile::FromWebUI(web_ui()); // Anything in-flight is invalid. - history_request_consumer_.CancelAllRequests(); + query_task_tracker_.TryCancelAll(); web_history_request_.reset(); query_results_.clear(); @@ -456,10 +456,12 @@ void BrowsingHistoryHandler::QueryHistory( HistoryService* hs = HistoryServiceFactory::GetForProfile( profile, Profile::EXPLICIT_ACCESS); hs->QueryHistory(search_text, - options, - &history_request_consumer_, - base::Bind(&BrowsingHistoryHandler::QueryComplete, - base::Unretained(this), search_text, options)); + options, + base::Bind(&BrowsingHistoryHandler::QueryComplete, + base::Unretained(this), + search_text, + options), + &query_task_tracker_); history::WebHistoryService* web_history = WebHistoryServiceFactory::GetForProfile(profile); @@ -756,7 +758,6 @@ void BrowsingHistoryHandler::ReturnResultsToFrontEnd() { void BrowsingHistoryHandler::QueryComplete( const base::string16& search_text, const history::QueryOptions& options, - HistoryService::Handle request_handle, history::QueryResults* results) { DCHECK_EQ(0U, query_results_.size()); query_results_.reserve(results->size()); @@ -881,7 +882,7 @@ void BrowsingHistoryHandler::WebHistoryQueryComplete( NOTREACHED() << "Failed to parse JSON response."; } results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); - if (!history_request_consumer_.HasPendingRequests()) + if (!query_task_tracker_.HasTrackedTasks()) ReturnResultsToFrontEnd(); } diff --git a/chrome/browser/ui/webui/history_ui.h b/chrome/browser/ui/webui/history_ui.h index bb3d147..62b85fe 100644 --- a/chrome/browser/ui/webui/history_ui.h +++ b/chrome/browser/ui/webui/history_ui.h @@ -144,7 +144,6 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler, // Callback from the history system when a history query has completed. void QueryComplete(const base::string16& search_text, const history::QueryOptions& options, - HistoryService::Handle request_handle, history::QueryResults* results); // Callback from the WebHistoryService when a query has completed. @@ -174,8 +173,8 @@ class BrowsingHistoryHandler : public content::WebUIMessageHandler, content::NotificationRegistrar registrar_; - // Consumer for search requests to the history service. - CancelableRequestConsumerT<int, 0> history_request_consumer_; + // Tracker for search requests to the history service. + base::CancelableTaskTracker query_task_tracker_; // The currently-executing request for synced history results. // Deleting the request will cancel it. diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc index dafacf1..0783626 100644 --- a/chrome/test/base/ui_test_utils.cc +++ b/chrome/test/base/ui_test_utils.cc @@ -571,12 +571,12 @@ HistoryEnumerator::HistoryEnumerator(Profile* profile) { HistoryService* hs = HistoryServiceFactory::GetForProfile( profile, Profile::EXPLICIT_ACCESS); - hs->QueryHistory( - base::string16(), - history::QueryOptions(), - &consumer_, - base::Bind(&HistoryEnumerator::HistoryQueryComplete, - base::Unretained(this), message_loop_runner->QuitClosure())); + hs->QueryHistory(base::string16(), + history::QueryOptions(), + base::Bind(&HistoryEnumerator::HistoryQueryComplete, + base::Unretained(this), + message_loop_runner->QuitClosure()), + &tracker_); message_loop_runner->Run(); } @@ -584,7 +584,6 @@ HistoryEnumerator::~HistoryEnumerator() {} void HistoryEnumerator::HistoryQueryComplete( const base::Closure& quit_task, - HistoryService::Handle request_handle, history::QueryResults* results) { for (size_t i = 0; i < results->size(); ++i) urls_.push_back((*results)[i].url()); diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h index 8ed553a..7c15ce8 100644 --- a/chrome/test/base/ui_test_utils.h +++ b/chrome/test/base/ui_test_utils.h @@ -301,12 +301,11 @@ class HistoryEnumerator { private: void HistoryQueryComplete( const base::Closure& quit_task, - HistoryService::Handle request_handle, history::QueryResults* results); std::vector<GURL> urls_; - CancelableRequestConsumer consumer_; + base::CancelableTaskTracker tracker_; DISALLOW_COPY_AND_ASSIGN(HistoryEnumerator); }; |