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

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

Issue 2321273003: Extend VariationParamsManager to support feature associations. (Closed)
Patch Set: Last comments 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_
7
8 #include "base/callback.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/scoped_observer.h"
11 #include "components/prefs/pref_change_registrar.h"
12
13 class PrefRegistrySimple;
14 class PrefService;
15 class SigninManagerBase;
16
17 namespace ntp_snippets {
18
19 enum class SnippetsStatus : int {
20 // Snippets are enabled and the user is signed in.
21 ENABLED_AND_SIGNED_IN,
22 // Snippets are enabled and the user is signed out (sign in is not required).
23 ENABLED_AND_SIGNED_OUT,
24 // Snippets have been disabled as part of the service configuration.
25 EXPLICITLY_DISABLED,
26 // The user is not signed in, and the service requires it to be enabled.
27 SIGNED_OUT_AND_DISABLED,
28 };
29
30 // Aggregates data from preferences and signin to notify the snippet service of
31 // relevant changes in their states.
32 class NTPSnippetsStatusService {
33 public:
34 using SnippetsStatusChangeCallback =
35 base::Callback<void(SnippetsStatus /*old_status*/,
36 SnippetsStatus /*new_status*/)>;
37
38 NTPSnippetsStatusService(SigninManagerBase* signin_manager,
39 PrefService* pref_service);
40
41 virtual ~NTPSnippetsStatusService();
42
43 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
44
45 // Starts listening for changes from the dependencies. |callback| will be
46 // called when a significant change in state is detected.
47 void Init(const SnippetsStatusChangeCallback& callback);
48
49 // To be called when the signin state changed. Will compute the new
50 // state considering the initialisation configuration and the preferences,
51 // and notify via the registered callback if appropriate.
52 void OnSignInStateChanged();
53
54 private:
55 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest,
56 SigninStateCompatibility);
57 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest, DisabledViaPref);
58
59 // Callback for the PrefChangeRegistrar.
60 void OnSnippetsEnabledChanged();
61
62 void OnStateChanged(SnippetsStatus new_snippets_status);
63
64 bool IsSignedIn() const;
65
66 SnippetsStatus GetSnippetsStatusFromDeps() const;
67
68 SnippetsStatus snippets_status_;
69 SnippetsStatusChangeCallback snippets_status_change_callback_;
70
71 bool require_signin_;
72 SigninManagerBase* signin_manager_;
73 PrefService* pref_service_;
74
75 PrefChangeRegistrar pref_change_registrar_;
76
77 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService);
78 };
79
80 } // namespace ntp_snippets
81
82 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698