Chromium Code Reviews| Index: components/suggestions/suggestions_service.cc |
| diff --git a/chrome/browser/search/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc |
| similarity index 91% |
| rename from chrome/browser/search/suggestions/suggestions_service.cc |
| rename to components/suggestions/suggestions_service.cc |
| index 60e7dbe66543a2dc8bc059c99124e8e18be39fc6..3be9a12b0161c71e13739bfa65796962636add8f 100644 |
| --- a/chrome/browser/search/suggestions/suggestions_service.cc |
| +++ b/components/suggestions/suggestions_service.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/search/suggestions/suggestions_service.h" |
| +#include "components/suggestions/suggestions_service.h" |
| #include <sstream> |
| #include <string> |
| @@ -10,15 +10,15 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/metrics/histogram.h" |
| #include "base/metrics/sparse_histogram.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/time/time.h" |
| -#include "chrome/browser/search/suggestions/blacklist_store.h" |
| -#include "chrome/browser/search/suggestions/suggestions_store.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| +#include "components/suggestions/blacklist_store.h" |
| +#include "components/suggestions/suggestions_store.h" |
| #include "components/variations/variations_associated_data.h" |
| #include "components/variations/variations_http_header_provider.h" |
| -#include "content/public/browser/browser_thread.h" |
| #include "net/base/escape.h" |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| @@ -31,7 +31,6 @@ |
| #include "url/gurl.h" |
| using base::CancelableClosure; |
| -using content::BrowserThread; |
| namespace suggestions { |
| @@ -120,8 +119,10 @@ SuggestionsService::SuggestionsService( |
| net::URLRequestContextGetter* url_request_context, |
| scoped_ptr<SuggestionsStore> suggestions_store, |
| scoped_ptr<ImageManager> thumbnail_manager, |
| - scoped_ptr<BlacklistStore> blacklist_store) |
| - : suggestions_store_(suggestions_store.Pass()), |
| + scoped_ptr<BlacklistStore> blacklist_store, |
| + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) |
|
blundell
2014/07/24 08:31:45
It looks like this object is created and used enti
|
| + : ui_task_runner_(ui_task_runner), |
| + suggestions_store_(suggestions_store.Pass()), |
| blacklist_store_(blacklist_store.Pass()), |
| thumbnail_manager_(thumbnail_manager.Pass()), |
| url_request_context_(url_request_context), |
| @@ -156,7 +157,7 @@ bool SuggestionsService::IsControlGroup() { |
| void SuggestionsService::FetchSuggestionsData( |
| SuggestionsService::ResponseCallback callback) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| FetchSuggestionsDataNoTimeout(callback); |
| @@ -164,14 +165,14 @@ void SuggestionsService::FetchSuggestionsData( |
| // after some time. Cancels the previous such task, if one existed. |
| pending_timeout_closure_.reset(new CancelableClosure(base::Bind( |
| &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); |
| - BrowserThread::PostDelayedTask( |
| - BrowserThread::UI, FROM_HERE, pending_timeout_closure_->callback(), |
| + ui_task_runner_->PostDelayedTask( |
| + FROM_HERE, pending_timeout_closure_->callback(), |
| base::TimeDelta::FromMilliseconds(request_timeout_ms_)); |
| } |
| void SuggestionsService::FetchSuggestionsDataNoTimeout( |
| SuggestionsService::ResponseCallback callback) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| if (pending_request_.get()) { |
| // Request already exists, so just add requestor to queue. |
| waiting_requestors_.push_back(callback); |
| @@ -193,7 +194,7 @@ void SuggestionsService::GetPageThumbnail( |
| void SuggestionsService::BlacklistURL( |
| const GURL& candidate_url, |
| const SuggestionsService::ResponseCallback& callback) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| waiting_requestors_.push_back(callback); |
| // Blacklist locally, for immediate effect. |
| @@ -204,7 +205,6 @@ void SuggestionsService::BlacklistURL( |
| // If there's an ongoing request, let it complete. |
| if (pending_request_.get()) return; |
| - |
| IssueRequest(BuildBlacklistRequestURL(blacklist_url_prefix_, candidate_url)); |
| } |
| @@ -255,14 +255,13 @@ net::URLFetcher* SuggestionsService::CreateSuggestionsRequest(const GURL& url) { |
| } |
| void SuggestionsService::OnRequestTimeout() { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| ServeFromCache(); |
| } |
| void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK_EQ(pending_request_.get(), source); |
| - |
| // We no longer need the timeout closure. Delete it whether or not it has run. |
| // If it hasn't, this cancels it. |
| pending_timeout_closure_.reset(); |
| @@ -346,7 +345,7 @@ void SuggestionsService::FilterAndServe(SuggestionsProfile* suggestions) { |
| } |
| void SuggestionsService::ScheduleBlacklistUpload(bool last_request_successful) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| UpdateBlacklistDelay(last_request_successful); |
| @@ -356,14 +355,14 @@ void SuggestionsService::ScheduleBlacklistUpload(bool last_request_successful) { |
| base::Closure blacklist_cb = |
| base::Bind(&SuggestionsService::UploadOneFromBlacklist, |
| weak_ptr_factory_.GetWeakPtr()); |
| - BrowserThread::PostDelayedTask( |
| - BrowserThread::UI, FROM_HERE, blacklist_cb, |
| + ui_task_runner_->PostDelayedTask( |
| + FROM_HERE, blacklist_cb, |
| base::TimeDelta::FromSeconds(blacklist_delay_sec_)); |
| } |
| } |
| void SuggestionsService::UploadOneFromBlacklist() { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| // If there's an ongoing request, let it complete. |
| if (pending_request_.get()) return; |
| @@ -377,7 +376,7 @@ void SuggestionsService::UploadOneFromBlacklist() { |
| } |
| void SuggestionsService::UpdateBlacklistDelay(bool last_request_successful) { |
| - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| if (last_request_successful) { |
| blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |