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

Side by Side Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2557363002: [NTP Snippets] Refactor background scheduling for remote suggestions (Closed)
Patch Set: Marc's comments #1 Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_snippets/content_suggestions_service.h" 5 #include "components/ntp_snippets/content_suggestions_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 11 matching lines...) Expand all
22 namespace ntp_snippets { 22 namespace ntp_snippets {
23 23
24 ContentSuggestionsService::ContentSuggestionsService( 24 ContentSuggestionsService::ContentSuggestionsService(
25 State state, 25 State state,
26 SigninManagerBase* signin_manager, 26 SigninManagerBase* signin_manager,
27 history::HistoryService* history_service, 27 history::HistoryService* history_service,
28 PrefService* pref_service) 28 PrefService* pref_service)
29 : state_(state), 29 : state_(state),
30 signin_observer_(this), 30 signin_observer_(this),
31 history_service_observer_(this), 31 history_service_observer_(this),
32 ntp_snippets_service_(nullptr), 32 remote_suggestions_provider_(nullptr),
33 pref_service_(pref_service), 33 pref_service_(pref_service),
34 user_classifier_(pref_service) { 34 user_classifier_(pref_service) {
35 // Can be null in tests. 35 // Can be null in tests.
36 if (signin_manager) { 36 if (signin_manager) {
37 signin_observer_.Add(signin_manager); 37 signin_observer_.Add(signin_manager);
38 } 38 }
39 39
40 if (history_service) { 40 if (history_service) {
41 history_service_observer_.Add(history_service); 41 history_service_observer_.Add(history_service);
42 } 42 }
43 43
44 RestoreDismissedCategoriesFromPrefs(); 44 RestoreDismissedCategoriesFromPrefs();
45 } 45 }
46 46
47 ContentSuggestionsService::~ContentSuggestionsService() = default; 47 ContentSuggestionsService::~ContentSuggestionsService() = default;
48 48
49 void ContentSuggestionsService::Shutdown() { 49 void ContentSuggestionsService::Shutdown() {
50 ntp_snippets_service_ = nullptr; 50 remote_suggestions_provider_ = nullptr;
51 suggestions_by_category_.clear(); 51 suggestions_by_category_.clear();
52 providers_by_category_.clear(); 52 providers_by_category_.clear();
53 categories_.clear(); 53 categories_.clear();
54 providers_.clear(); 54 providers_.clear();
55 state_ = State::DISABLED; 55 state_ = State::DISABLED;
56 for (Observer& observer : observers_) { 56 for (Observer& observer : observers_) {
57 observer.ContentSuggestionsServiceShutdown(); 57 observer.ContentSuggestionsServiceShutdown();
58 } 58 }
59 } 59 }
60 60
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() { 495 void ContentSuggestionsService::StoreDismissedCategoriesToPrefs() {
496 base::ListValue list; 496 base::ListValue list;
497 for (const auto& category_provider_pair : dismissed_providers_by_category_) { 497 for (const auto& category_provider_pair : dismissed_providers_by_category_) {
498 list.AppendInteger(category_provider_pair.first.id()); 498 list.AppendInteger(category_provider_pair.first.id());
499 } 499 }
500 500
501 pref_service_->Set(prefs::kDismissedCategories, list); 501 pref_service_->Set(prefs::kDismissedCategories, list);
502 } 502 }
503 503
504 } // namespace ntp_snippets 504 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698