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

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

Issue 2657673004: Add shutdown notification and service refs to SyncServiceObserver. (Closed)
Patch Set: Use parameter 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 thumbnail_manager_(std::move(thumbnail_manager)), 202 thumbnail_manager_(std::move(thumbnail_manager)),
203 blacklist_store_(std::move(blacklist_store)), 203 blacklist_store_(std::move(blacklist_store)),
204 scheduling_delay_(TimeDelta::FromSeconds(kDefaultSchedulingDelaySec)), 204 scheduling_delay_(TimeDelta::FromSeconds(kDefaultSchedulingDelaySec)),
205 token_fetcher_(new AccessTokenFetcher(signin_manager, token_service)), 205 token_fetcher_(new AccessTokenFetcher(signin_manager, token_service)),
206 weak_ptr_factory_(this) { 206 weak_ptr_factory_(this) {
207 // |sync_service_| is null if switches::kDisableSync is set (tests use that). 207 // |sync_service_| is null if switches::kDisableSync is set (tests use that).
208 if (sync_service_) 208 if (sync_service_)
209 sync_service_observer_.Add(sync_service_); 209 sync_service_observer_.Add(sync_service_);
210 // Immediately get the current sync state, so we'll flush the cache if 210 // Immediately get the current sync state, so we'll flush the cache if
211 // necessary. 211 // necessary.
212 OnStateChanged(); 212 OnStateChanged(sync_service_);
213 } 213 }
214 214
215 SuggestionsServiceImpl::~SuggestionsServiceImpl() {} 215 SuggestionsServiceImpl::~SuggestionsServiceImpl() {}
216 216
217 bool SuggestionsServiceImpl::FetchSuggestionsData() { 217 bool SuggestionsServiceImpl::FetchSuggestionsData() {
218 DCHECK(thread_checker_.CalledOnValidThread()); 218 DCHECK(thread_checker_.CalledOnValidThread());
219 // If sync state allows, issue a network request to refresh the suggestions. 219 // If sync state allows, issue a network request to refresh the suggestions.
220 if (GetSyncState(sync_service_) != INITIALIZED_ENABLED_HISTORY) 220 if (GetSyncState(sync_service_) != INITIALIZED_ENABLED_HISTORY)
221 return false; 221 return false;
222 IssueRequestIfNoneOngoing(BuildSuggestionsURL()); 222 IssueRequestIfNoneOngoing(BuildSuggestionsURL());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 net::EscapeQueryParamValue(candidate_url.spec(), true)); 341 net::EscapeQueryParamValue(candidate_url.spec(), true));
342 } 342 }
343 343
344 // static 344 // static
345 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistClearURL() { 345 GURL SuggestionsServiceImpl::BuildSuggestionsBlacklistClearURL() {
346 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat, 346 return GURL(base::StringPrintf(kSuggestionsBlacklistClearURLFormat,
347 GetGoogleBaseURL().spec().c_str(), 347 GetGoogleBaseURL().spec().c_str(),
348 kDeviceType)); 348 kDeviceType));
349 } 349 }
350 350
351 void SuggestionsServiceImpl::OnStateChanged() { 351 void SuggestionsServiceImpl::OnStateChanged(syncer::SyncService* sync) {
352 switch (GetSyncState(sync_service_)) { 352 switch (GetSyncState(sync_service_)) {
353 case SYNC_OR_HISTORY_SYNC_DISABLED: 353 case SYNC_OR_HISTORY_SYNC_DISABLED:
354 // Cancel any ongoing request, to stop interacting with the server. 354 // Cancel any ongoing request, to stop interacting with the server.
355 pending_request_.reset(nullptr); 355 pending_request_.reset(nullptr);
356 suggestions_store_->ClearSuggestions(); 356 suggestions_store_->ClearSuggestions();
357 callback_list_.Notify(SuggestionsProfile()); 357 callback_list_.Notify(SuggestionsProfile());
358 break; 358 break;
359 case NOT_INITIALIZED_ENABLED: 359 case NOT_INITIALIZED_ENABLED:
360 // Keep the cache (if any), but don't refresh. 360 // Keep the cache (if any), but don't refresh.
361 break; 361 break;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec); 558 scheduling_delay_ = TimeDelta::FromSeconds(kDefaultSchedulingDelaySec);
559 } else { 559 } else {
560 TimeDelta candidate_delay = 560 TimeDelta candidate_delay =
561 scheduling_delay_ * kSchedulingBackoffMultiplier; 561 scheduling_delay_ * kSchedulingBackoffMultiplier;
562 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec)) 562 if (candidate_delay < TimeDelta::FromSeconds(kSchedulingMaxDelaySec))
563 scheduling_delay_ = candidate_delay; 563 scheduling_delay_ = candidate_delay;
564 } 564 }
565 } 565 }
566 566
567 } // namespace suggestions 567 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698