Chromium Code Reviews| Index: components/suggestions/suggestions_service.cc |
| diff --git a/components/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc |
| index db1e3fc9632156cf08337286ea1201c93acd7051..3d5cd6aa92bc727868d2c96e76bbccba2b050557 100644 |
| --- a/components/suggestions/suggestions_service.cc |
| +++ b/components/suggestions/suggestions_service.cc |
| @@ -156,8 +156,24 @@ bool SuggestionsService::IsControlGroup() { |
| } |
| void SuggestionsService::FetchSuggestionsData( |
| + SyncState sync_state, |
| SuggestionsService::ResponseCallback callback) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (sync_state == NOT_INITIALIZED_ENABLED) { |
| + // Sync is not initialized yet, but enabled. Serve previously cached |
| + // suggestions if available. |
| + waiting_requestors_.push_back(callback); |
| + ServeFromCache(); |
| + return; |
| + } else if (sync_state == SYNC_OR_HISTORY_SYNC_DISABLED) { |
| + // Cancel any ongoing request (and the timeout closure). We must no longer |
| + // interact with the server. |
| + pending_request_.reset(NULL); |
| + pending_timeout_closure_.reset(NULL); |
| + suggestions_store_->ClearSuggestions(); |
| + callback.Run(SuggestionsProfile()); |
|
manzagop (departed)
2014/08/20 19:28:14
Also serve the waiting requestors?
Mathieu
2014/08/20 21:37:48
Done.
|
| + return; |
| + } |
| FetchSuggestionsDataNoTimeout(callback); |
| @@ -170,21 +186,6 @@ void SuggestionsService::FetchSuggestionsData( |
| base::TimeDelta::FromMilliseconds(request_timeout_ms_)); |
| } |
| -void SuggestionsService::FetchSuggestionsDataNoTimeout( |
| - SuggestionsService::ResponseCallback callback) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - if (pending_request_.get()) { |
| - // Request already exists, so just add requestor to queue. |
| - waiting_requestors_.push_back(callback); |
| - return; |
| - } |
| - |
| - // Form new request. |
| - DCHECK(waiting_requestors_.empty()); |
| - waiting_requestors_.push_back(callback); |
| - IssueRequest(suggestions_url_); |
| -} |
| - |
| void SuggestionsService::GetPageThumbnail( |
| const GURL& url, |
| base::Callback<void(const GURL&, const SkBitmap*)> callback) { |
| @@ -235,6 +236,33 @@ void SuggestionsService::RegisterProfilePrefs( |
| BlacklistStore::RegisterProfilePrefs(registry); |
| } |
| +void SuggestionsService::SetDefaultExpiryTimestamp( |
| + SuggestionsProfile* suggestions, int64 default_timestamp_usec) { |
| + for (int i = 0; i < suggestions->suggestions_size(); ++i) { |
| + ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); |
| + // Do not set expiry if the server has already provided a more specific |
| + // expiry time for this suggestion. |
| + if (!suggestion->has_expiry_ts()) { |
| + suggestion->set_expiry_ts(default_timestamp_usec); |
| + } |
| + } |
| +} |
| + |
| +void SuggestionsService::FetchSuggestionsDataNoTimeout( |
| + SuggestionsService::ResponseCallback callback) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (pending_request_.get()) { |
| + // Request already exists, so just add requestor to queue. |
| + waiting_requestors_.push_back(callback); |
| + return; |
| + } |
| + |
| + // Form new request. |
| + DCHECK(waiting_requestors_.empty()); |
| + waiting_requestors_.push_back(callback); |
| + IssueRequest(suggestions_url_); |
| +} |
| + |
| void SuggestionsService::IssueRequest(const GURL& url) { |
| pending_request_.reset(CreateSuggestionsRequest(url)); |
| pending_request_->Start(); |
| @@ -330,18 +358,6 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| ScheduleBlacklistUpload(true); |
| } |
| -void SuggestionsService::SetDefaultExpiryTimestamp( |
| - SuggestionsProfile* suggestions, int64 default_timestamp_usec) { |
| - for (int i = 0; i < suggestions->suggestions_size(); ++i) { |
| - ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); |
| - // Do not set expiry if the server has already provided a more specific |
| - // expiry time for this suggestion. |
| - if (!suggestion->has_expiry_ts()) { |
| - suggestion->set_expiry_ts(default_timestamp_usec); |
| - } |
| - } |
| -} |
| - |
| void SuggestionsService::Shutdown() { |
| // Cancel pending request and timeout closure, then serve existing requestors |
| // from cache. |