Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 SyncState sync_state, | |
| 159 SuggestionsService::ResponseCallback callback) { | 160 SuggestionsService::ResponseCallback callback) { |
| 160 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
| 162 if (sync_state == NOT_INITIALIZED_ENABLED) { | |
| 163 // Sync is not initialized yet, but enabled. Serve previously cached | |
| 164 // suggestions if available. | |
| 165 waiting_requestors_.push_back(callback); | |
| 166 ServeFromCache(); | |
| 167 return; | |
| 168 } else if (sync_state == DISABLED) { | |
| 169 suggestions_store_->ClearSuggestions(); | |
|
manzagop (departed)
2014/08/20 15:43:51
Also cancel any ongoing request and serve the wait
Mathieu
2014/08/20 18:41:29
We shouldn't interact with the server anymore when
| |
| 170 callback.Run(SuggestionsProfile()); | |
| 171 return; | |
| 172 } | |
| 161 | 173 |
| 162 FetchSuggestionsDataNoTimeout(callback); | 174 FetchSuggestionsDataNoTimeout(callback); |
| 163 | 175 |
| 164 // Post a task to serve the cached suggestions if the request hasn't completed | 176 // 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. | 177 // after some time. Cancels the previous such task, if one existed. |
| 166 pending_timeout_closure_.reset(new CancelableClosure(base::Bind( | 178 pending_timeout_closure_.reset(new CancelableClosure(base::Bind( |
| 167 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); | 179 &SuggestionsService::OnRequestTimeout, weak_ptr_factory_.GetWeakPtr()))); |
| 168 base::MessageLoopProxy::current()->PostDelayedTask( | 180 base::MessageLoopProxy::current()->PostDelayedTask( |
| 169 FROM_HERE, pending_timeout_closure_->callback(), | 181 FROM_HERE, pending_timeout_closure_->callback(), |
| 170 base::TimeDelta::FromMilliseconds(request_timeout_ms_)); | 182 base::TimeDelta::FromMilliseconds(request_timeout_ms_)); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 if (last_request_successful) { | 411 if (last_request_successful) { |
| 400 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; | 412 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; |
| 401 } else { | 413 } else { |
| 402 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; | 414 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; |
| 403 if (candidate_delay < kBlacklistMaxDelaySec) | 415 if (candidate_delay < kBlacklistMaxDelaySec) |
| 404 blacklist_delay_sec_ = candidate_delay; | 416 blacklist_delay_sec_ = candidate_delay; |
| 405 } | 417 } |
| 406 } | 418 } |
| 407 | 419 |
| 408 } // namespace suggestions | 420 } // namespace suggestions |
| OLD | NEW |