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

Side by Side Diff: components/ntp_snippets/ntp_snippets_status_service.h

Issue 2158373002: [NTP Snippets] Add a pref to disable the NTPSnippetsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 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 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/scoped_observer.h" 10 #include "base/scoped_observer.h"
11 #include "components/prefs/pref_change_registrar.h"
11 #include "components/sync_driver/sync_service_observer.h" 12 #include "components/sync_driver/sync_service_observer.h"
12 13
14 class PrefRegistrySimple;
15 class PrefService;
13 class SigninManagerBase; 16 class SigninManagerBase;
14 17
15 namespace sync_driver { 18 namespace sync_driver {
16 class SyncService; 19 class SyncService;
17 } 20 }
18 21
19 namespace ntp_snippets { 22 namespace ntp_snippets {
20 23
21 // On Android builds, a Java counterpart will be generated for this enum. 24 // On Android builds, a Java counterpart will be generated for this enum.
22 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets 25 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets
(...skipping 14 matching lines...) Expand all
37 HISTORY_SYNC_STATE_UNKNOWN 40 HISTORY_SYNC_STATE_UNKNOWN
38 }; 41 };
39 42
40 // Aggregates data from sync and signin to notify the snippet service of 43 // Aggregates data from sync and signin to notify the snippet service of
41 // relevant changes in their states. 44 // relevant changes in their states.
42 class NTPSnippetsStatusService : public sync_driver::SyncServiceObserver { 45 class NTPSnippetsStatusService : public sync_driver::SyncServiceObserver {
43 public: 46 public:
44 typedef base::Callback<void(DisabledReason)> DisabledReasonChangeCallback; 47 typedef base::Callback<void(DisabledReason)> DisabledReasonChangeCallback;
45 48
46 NTPSnippetsStatusService(SigninManagerBase* signin_manager, 49 NTPSnippetsStatusService(SigninManagerBase* signin_manager,
47 sync_driver::SyncService* sync_service); 50 sync_driver::SyncService* sync_service,
51 PrefService* pref_service);
48 52
49 ~NTPSnippetsStatusService() override; 53 ~NTPSnippetsStatusService() override;
50 54
55 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
56
51 // Starts listening for changes from the dependencies. |callback| will be 57 // Starts listening for changes from the dependencies. |callback| will be
52 // called when a significant change in state is detected. 58 // called when a significant change in state is detected.
53 void Init(const DisabledReasonChangeCallback& callback); 59 void Init(const DisabledReasonChangeCallback& callback);
54 60
55 DisabledReason disabled_reason() const { return disabled_reason_; } 61 DisabledReason disabled_reason() const { return disabled_reason_; }
56 62
57 private: 63 private:
58 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest, 64 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest,
59 SyncStateCompatibility); 65 SyncStateCompatibility);
66 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest, DisabledViaPref);
60 67
61 // sync_driver::SyncServiceObserver implementation 68 // sync_driver::SyncServiceObserver implementation. Also used as a callback
69 // for the PrefChangeRegistrar.
62 void OnStateChanged() override; 70 void OnStateChanged() override;
63 71
64 DisabledReason GetDisabledReasonFromDeps() const; 72 DisabledReason GetDisabledReasonFromDeps() const;
65 73
66 DisabledReason disabled_reason_; 74 DisabledReason disabled_reason_;
67 DisabledReasonChangeCallback disabled_reason_change_callback_; 75 DisabledReasonChangeCallback disabled_reason_change_callback_;
68 76
69 SigninManagerBase* signin_manager_; 77 SigninManagerBase* signin_manager_;
70 sync_driver::SyncService* sync_service_; 78 sync_driver::SyncService* sync_service_;
79 PrefService* pref_service_;
80
81 PrefChangeRegistrar pref_change_registrar_;
71 82
72 // The observer for the SyncService. When the sync state changes, 83 // The observer for the SyncService. When the sync state changes,
73 // SyncService will call |OnStateChanged|. 84 // SyncService will call |OnStateChanged|.
74 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> 85 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver>
75 sync_service_observer_; 86 sync_service_observer_;
76 87
77 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService); 88 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService);
78 }; 89 };
79 90
80 } // namespace ntp_snippets 91 } // namespace ntp_snippets
81 92
82 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_ 93 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698