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

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

Issue 2657673004: Add shutdown notification and service refs to SyncServiceObserver. (Closed)
Patch Set: Chromeos fix Created 3 years, 10 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
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_impl.h" 5 #include "components/suggestions/suggestions_service_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 suggestions_store_(std::move(suggestions_store)), 153 suggestions_store_(std::move(suggestions_store)),
154 thumbnail_manager_(std::move(thumbnail_manager)), 154 thumbnail_manager_(std::move(thumbnail_manager)),
155 blacklist_store_(std::move(blacklist_store)), 155 blacklist_store_(std::move(blacklist_store)),
156 scheduling_delay_(TimeDelta::FromSeconds(kDefaultSchedulingDelaySec)), 156 scheduling_delay_(TimeDelta::FromSeconds(kDefaultSchedulingDelaySec)),
157 weak_ptr_factory_(this) { 157 weak_ptr_factory_(this) {
158 // |sync_service_| is null if switches::kDisableSync is set (tests use that). 158 // |sync_service_| is null if switches::kDisableSync is set (tests use that).
159 if (sync_service_) 159 if (sync_service_)
160 sync_service_observer_.Add(sync_service_); 160 sync_service_observer_.Add(sync_service_);
161 // Immediately get the current sync state, so we'll flush the cache if 161 // Immediately get the current sync state, so we'll flush the cache if
162 // necessary. 162 // necessary.
163 OnStateChanged(); 163 OnStateChanged(sync_service_);
164 } 164 }
165 165
166 SuggestionsServiceImpl::~SuggestionsServiceImpl() {} 166 SuggestionsServiceImpl::~SuggestionsServiceImpl() {}
167 167
168 bool SuggestionsServiceImpl::FetchSuggestionsData() { 168 bool SuggestionsServiceImpl::FetchSuggestionsData() {
169 DCHECK(thread_checker_.CalledOnValidThread()); 169 DCHECK(thread_checker_.CalledOnValidThread());
170 // If sync state allows, issue a network request to refresh the suggestions. 170 // If sync state allows, issue a network request to refresh the suggestions.
171 if (GetSyncState(sync_service_) != INITIALIZED_ENABLED_HISTORY) 171 if (GetSyncState(sync_service_) != INITIALIZED_ENABLED_HISTORY)
172 return false; 172 return false;
173 IssueRequestIfNoneOngoing(BuildSuggestionsURL()); 173 IssueRequestIfNoneOngoing(BuildSuggestionsURL());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 net::EscapeQueryParamValue(candidate_url.spec(), true)); 292 net::EscapeQueryParamValue(candidate_url.spec(), true));
293 } 293 }
294 294
295 // static 295 // static
296 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistClearURL() { 296 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistClearURL() {
297 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat, 297 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat,
298 GetGoogleBaseURL().spec().c_str(), 298 GetGoogleBaseURL().spec().c_str(),
299 kDeviceType)); 299 kDeviceType));
300 } 300 }
301 301
302 void SuggestionsServiceImpl::OnStateChanged() { 302 void SuggestionsServiceImpl::OnStateChanged(syncer::SyncService* sync) {
303 switch (GetSyncState(sync_service_)) { 303 switch (GetSyncState(sync_service_)) {
304 case SYNC_OR_HISTORY_SYNC_DISABLED: 304 case SYNC_OR_HISTORY_SYNC_DISABLED:
305 // Cancel any ongoing request, to stop interacting with the server. 305 // Cancel any ongoing request, to stop interacting with the server.
306 pending_request_.reset(nullptr); 306 pending_request_.reset(nullptr);
307 suggestions_store_->ClearSuggestions(); 307 suggestions_store_->ClearSuggestions();
308 callback_list_.Notify(SuggestionsProfile()); 308 callback_list_.Notify(SuggestionsProfile());
309 break; 309 break;
310 case NOT_INITIALIZED_ENABLED: 310 case NOT_INITIALIZED_ENABLED:
311 // Keep the cache (if any), but don't refresh. 311 // Keep the cache (if any), but don't refresh.
312 break; 312 break;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); 527 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec);
528 } else { 528 } else {
529 TimeDelta candidate_delay = 529 TimeDelta candidate_delay =
530 scheduling_delay_ * kSchedulingBackoffMultiplier; 530 scheduling_delay_ * kSchedulingBackoffMultiplier;
531 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) 531 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec))
532 scheduling_delay_ = candidate_delay; 532 scheduling_delay_ = candidate_delay;
533 } 533 }
534 } 534 }
535 535
536 } // namespace suggestions 536 } // namespace suggestions
OLDNEW
« no previous file with comments | « components/suggestions/suggestions_service_impl.h ('k') | components/suggestions/suggestions_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698