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

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

Issue 2519053002: 📰 Let the backend trigger sign in related refreshes (Closed)
Patch Set: Fix iOS build Created 4 years, 1 month 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_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_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/prefs/pref_change_registrar.h"
12 #include "components/signin/core/browser/signin_manager.h"
13 12
14 class PrefRegistrySimple; 13 class PrefRegistrySimple;
15 class PrefService; 14 class PrefService;
15 class SigninManagerBase;
16 16
17 namespace ntp_snippets { 17 namespace ntp_snippets {
18 18
19 enum class SnippetsStatus : int { 19 enum class SnippetsStatus : int {
20 // Snippets are enabled and the user is signed in. 20 // Snippets are enabled and the user is signed in.
21 ENABLED_AND_SIGNED_IN, 21 ENABLED_AND_SIGNED_IN,
22 // Snippets are enabled and the user is signed out (sign in is not required). 22 // Snippets are enabled and the user is signed out (sign in is not required).
23 ENABLED_AND_SIGNED_OUT, 23 ENABLED_AND_SIGNED_OUT,
24 // Snippets have been disabled as part of the service configuration. 24 // Snippets have been disabled as part of the service configuration.
25 EXPLICITLY_DISABLED, 25 EXPLICITLY_DISABLED,
26 // The user is not signed in, and the service requires it to be enabled. 26 // The user is not signed in, and the service requires it to be enabled.
27 SIGNED_OUT_AND_DISABLED, 27 SIGNED_OUT_AND_DISABLED,
28 }; 28 };
29 29
30 // Aggregates data from preferences and signin to notify the snippet service of 30 // Aggregates data from preferences and signin to notify the snippet service of
31 // relevant changes in their states. 31 // relevant changes in their states.
32 class NTPSnippetsStatusService : public SigninManagerBase::Observer { 32 class NTPSnippetsStatusService {
33 public: 33 public:
34 using SnippetsStatusChangeCallback = 34 using SnippetsStatusChangeCallback =
35 base::Callback<void(SnippetsStatus /*old_status*/, 35 base::Callback<void(SnippetsStatus /*old_status*/,
36 SnippetsStatus /*new_status*/)>; 36 SnippetsStatus /*new_status*/)>;
37 37
38 NTPSnippetsStatusService(SigninManagerBase* signin_manager, 38 NTPSnippetsStatusService(SigninManagerBase* signin_manager,
39 PrefService* pref_service); 39 PrefService* pref_service);
40 40
41 ~NTPSnippetsStatusService() override; 41 virtual ~NTPSnippetsStatusService();
42 42
43 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 43 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
44 44
45 // Starts listening for changes from the dependencies. |callback| will be 45 // Starts listening for changes from the dependencies. |callback| will be
46 // called when a significant change in state is detected. 46 // called when a significant change in state is detected.
47 void Init(const SnippetsStatusChangeCallback& callback); 47 void Init(const SnippetsStatusChangeCallback& callback);
48 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
49 private: 54 private:
50 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest, DisabledViaPref); 55 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest, DisabledViaPref);
51 56
52 // SigninManagerBase::Observer implementation
53 void GoogleSigninSucceeded(const std::string& account_id,
54 const std::string& username,
55 const std::string& password) override;
56 void GoogleSignedOut(const std::string& account_id,
57 const std::string& username) override;
58
59 // Callback for the PrefChangeRegistrar. 57 // Callback for the PrefChangeRegistrar.
60 void OnSnippetsEnabledChanged(); 58 void OnSnippetsEnabledChanged();
61 59
62 void OnStateChanged(SnippetsStatus new_snippets_status); 60 void OnStateChanged(SnippetsStatus new_snippets_status);
63 61
64 bool IsSignedIn() const; 62 bool IsSignedIn() const;
65 63
66 SnippetsStatus GetSnippetsStatusFromDeps() const; 64 SnippetsStatus GetSnippetsStatusFromDeps() const;
67 65
68 SnippetsStatus snippets_status_; 66 SnippetsStatus snippets_status_;
69 SnippetsStatusChangeCallback snippets_status_change_callback_; 67 SnippetsStatusChangeCallback snippets_status_change_callback_;
70 68
71 bool require_signin_; 69 bool require_signin_;
72 SigninManagerBase* signin_manager_; 70 SigninManagerBase* signin_manager_;
73 PrefService* pref_service_; 71 PrefService* pref_service_;
74 72
75 PrefChangeRegistrar pref_change_registrar_; 73 PrefChangeRegistrar pref_change_registrar_;
76 74
77 // The observer for the SigninManager.
78 ScopedObserver<SigninManagerBase, SigninManagerBase::Observer>
79 signin_observer_;
80
81 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService); 75 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService);
82 }; 76 };
83 77
84 } // namespace ntp_snippets 78 } // namespace ntp_snippets
85 79
86 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_ 80 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_STATUS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698