Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: components/suggestions/suggestions_service.cc

Issue 473123002: [Most Visited] Check for Sync state when using SuggestionsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/suggestions/suggestions_service.h" 5 #include "components/suggestions/suggestions_service.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 kSuggestionsFieldTrialStateEnabled; 149 kSuggestionsFieldTrialStateEnabled;
150 } 150 }
151 151
152 // static 152 // static
153 bool SuggestionsService::IsControlGroup() { 153 bool SuggestionsService::IsControlGroup() {
154 return GetExperimentParam(kSuggestionsFieldTrialControlParam) == 154 return GetExperimentParam(kSuggestionsFieldTrialControlParam) ==
155 kSuggestionsFieldTrialStateEnabled; 155 kSuggestionsFieldTrialStateEnabled;
156 } 156 }
157 157
158 void SuggestionsService::FetchSuggestionsData( 158 void SuggestionsService::FetchSuggestionsData(
159 bool sync_initialized,
160 bool history_sync_enabled,
159 SuggestionsService::ResponseCallback callback) { 161 SuggestionsService::ResponseCallback callback) {
160 DCHECK(thread_checker_.CalledOnValidThread()); 162 DCHECK(thread_checker_.CalledOnValidThread());
163 if (!sync_initialized) {
164 // Serve from cache.
165 waiting_requestors_.push_back(callback);
166 ServeFromCache();
167 return;
168 } else if (!history_sync_enabled) {
169 // User hasn't enabled history sync.
170 callback.Run(SuggestionsProfile());
manzagop (departed) 2014/08/15 13:01:52 Why not clear the cache, then push back requestors
Mathieu 2014/08/20 14:21:32 Done.
171 return;
172 }
173 // Sync is initialized and history sync is enabled.
161 174
162 FetchSuggestionsDataNoTimeout(callback); 175 FetchSuggestionsDataNoTimeout(callback);
163 176
164 // Post a task to serve the cached suggestions if the request hasn't completed 177 // Post a task to serve the cached suggestions if the request hasn't completed
165 // after some time. Cancels the previous such task, if one existed. 178 // after some time. Cancels the previous such task, if one existed.
166 pending_timeout_closure_.reset(new CancelableClosure(base::Bind( 179 pending_timeout_closure_.reset(new CancelableClosure(base::Bind(
167 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); 180 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr())));
168 base::MessageLoopProxy::current()->PostDelayedTask( 181 base::MessageLoopProxy::current()->PostDelayedTask(
169 FROM_HERE, pending_timeout_closure_->callback(), 182 FROM_HERE, pending_timeout_closure_->callback(),
170 base::TimeDelta::FromMilliseconds(request_timeout_ms_)); 183 base::TimeDelta::FromMilliseconds(request_timeout_ms_));
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (last_request_successful) { 412 if (last_request_successful) {
400 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; 413 blacklist_delay_sec_ = kBlacklistDefaultDelaySec;
401 } else { 414 } else {
402 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; 415 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier;
403 if (candidate_delay < kBlacklistMaxDelaySec) 416 if (candidate_delay < kBlacklistMaxDelaySec)
404 blacklist_delay_sec_ = candidate_delay; 417 blacklist_delay_sec_ = candidate_delay;
405 } 418 }
406 } 419 }
407 420
408 } // namespace suggestions 421 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698