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

Side by Side Diff: chrome/browser/signin/signin_tracker.h

Issue 19567004: Convert SigninTracker to use OAuth2TokenService notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/signin/signin_manager.cc ('k') | chrome/browser/signin/signin_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
7 7
8 #include "content/public/browser/notification_observer.h" 8 #include "content/public/browser/notification_observer.h"
9 #include "content/public/browser/notification_registrar.h" 9 #include "content/public/browser/notification_registrar.h"
10 #include "content/public/browser/notification_types.h" 10 #include "content/public/browser/notification_types.h"
11 #include "google_apis/gaia/google_service_auth_error.h" 11 #include "google_apis/gaia/google_service_auth_error.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
12 13
13 class Profile; 14 class Profile;
14 15
15 // The signin flow logic is spread across several classes with varying 16 // The signin flow logic is spread across several classes with varying
16 // responsibilities: 17 // responsibilities:
17 // 18 //
18 // SigninTracker (this class) - This class listens to notifications from various 19 // SigninTracker (this class) - This class listens to notifications from various
19 // services (SigninManager, tokenService, etc) and coalesces them into 20 // services (SigninManager, OAuth2TokenService) and coalesces them into
20 // notifications for the UI layer. This is the class that encapsulates the logic 21 // notifications for the UI layer. This is the class that encapsulates the logic
21 // that determines whether a user is fully logged in or not, and exposes 22 // that determines whether a user is fully logged in or not, and exposes
22 // callbacks so various pieces of the UI (OneClickSyncStarter, SyncSetupHandler) 23 // callbacks so various pieces of the UI (OneClickSyncStarter) can track the
23 // can track the current startup state. 24 // current startup state.
24 // 25 //
25 // SyncSetupHandler - This class is primarily responsible for interacting with 26 // SyncSetupHandler - This class is primarily responsible for interacting with
26 // the web UI for performing system login and sync configuration. Receives 27 // the web UI for performing system login and sync configuration. Receives
27 // callbacks from the UI when the user wishes to initiate a login, and 28 // callbacks from the UI when the user wishes to initiate a login, and
28 // translates system state (login errors, etc) into the appropriate calls into 29 // translates system state (login errors, etc) into the appropriate calls into
29 // the UI to reflect this status to the user. 30 // the UI to reflect this status to the user.
30 // 31 //
31 // LoginUIService - Our desktop UI flows rely on having only a single login flow 32 // LoginUIService - Our desktop UI flows rely on having only a single login flow
32 // visible to the user at once. This is achieved via LoginUIService 33 // visible to the user at once. This is achieved via LoginUIService
33 // (a BrowserContextKeyedService that keeps track of the currently visible 34 // (a BrowserContextKeyedService that keeps track of the currently visible
34 // login UI). 35 // login UI).
35 // 36 //
36 // SigninManager - Records the currently-logged-in user and handles all 37 // SigninManager - Records the currently-logged-in user and handles all
37 // interaction with the GAIA backend during the signin process. Unlike 38 // interaction with the GAIA backend during the signin process. Unlike
38 // SigninTracker, SigninManager only knows about the GAIA login state and is 39 // SigninTracker, SigninManager only knows about the GAIA login state and is
39 // not aware of the state of any signed in services. 40 // not aware of the state of any signed in services.
40 // 41 //
41 // TokenService - Uses credentials provided by SigninManager to generate tokens 42 // TokenService - Uses credentials provided by SigninManager to generate tokens
42 // for all signed-in services in Chrome. 43 // for all signed-in services in Chrome.
43 // 44 //
45 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
46 // connected to this profile.
47 //
44 // ProfileSyncService - Provides the external API for interacting with the 48 // ProfileSyncService - Provides the external API for interacting with the
45 // sync framework. Listens for notifications from the TokenService to know 49 // sync framework. Listens for notifications from the TokenService to know
46 // when to startup sync, and provides an Observer interface to notify the UI 50 // when to startup sync, and provides an Observer interface to notify the UI
47 // layer of changes in sync state so they can be reflected in the UI. 51 // layer of changes in sync state so they can be reflected in the UI.
48 class SigninTracker : public content::NotificationObserver { 52 class SigninTracker : public content::NotificationObserver,
53 public OAuth2TokenService::Observer {
49 public: 54 public:
50 class Observer { 55 class Observer {
51 public: 56 public:
52 // The signin attempt failed, and the cause is passed in |error|. 57 // The signin attempt failed, and the cause is passed in |error|.
53 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0; 58 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0;
54 59
55 // The signin attempt succeeded. 60 // The signin attempt succeeded.
56 virtual void SigninSuccess() = 0; 61 virtual void SigninSuccess() = 0;
57 }; 62 };
58 63
59 // The various states the login process can be in.
60 enum LoginState {
61 WAITING_FOR_GAIA_VALIDATION,
62 SERVICES_INITIALIZING,
63 SIGNIN_COMPLETE
64 };
65
66 // Creates a SigninTracker that tracks the signin status on the passed 64 // Creates a SigninTracker that tracks the signin status on the passed
67 // |profile|, and notifies the |observer| on status changes. |observer| must 65 // |profile|, and notifies the |observer| on status changes. |observer| must
68 // be non-null and must outlive the SigninTracker. 66 // be non-null and must outlive the SigninTracker.
69 SigninTracker(Profile* profile, Observer* observer); 67 SigninTracker(Profile* profile, Observer* observer);
70 virtual ~SigninTracker(); 68 virtual ~SigninTracker();
71 69
72 // content::NotificationObserver implementation. 70 // content::NotificationObserver implementation.
73 virtual void Observe(int type, 71 virtual void Observe(int type,
74 const content::NotificationSource& source, 72 const content::NotificationSource& source,
75 const content::NotificationDetails& details) OVERRIDE; 73 const content::NotificationDetails& details) OVERRIDE;
76 74
77 // Returns true if the tokens are loaded for all signed-in services. 75 // OAuth2TokenService::Observer implementation.
78 static bool AreServiceTokensLoaded(Profile* profile); 76 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
79 77 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
80 // Returns the sign in state for |profile|. If the profile is not signed in,
81 // or is authenticating with GAIA, WAITING_FOR_GAIA_VALIDATION is returned.
82 // If SigninManager in has completed but TokenService is not ready,
83 // SERVICES_INITIALIZING is returned. Otherwise SIGNIN_COMPLETE is returned.
84 static LoginState GetSigninState(Profile* profile,
85 GoogleServiceAuthError* error);
86 78
87 private: 79 private:
88 // Initializes this by adding notifications and observers. 80 // Initializes this by adding notifications and observers.
89 void Initialize(); 81 void Initialize();
90 82
91 // Invoked when one of the services potentially changed its signin status so
92 // we can check to see whether we need to notify our observer.
93 void HandleServiceStateChange();
94
95 // The current state of the login process.
96 LoginState state_;
97
98 // The profile whose signin status we are tracking. 83 // The profile whose signin status we are tracking.
99 Profile* profile_; 84 Profile* profile_;
100 85
101 // Weak pointer to the observer we call when the signin state changes. 86 // Weak pointer to the observer we call when the signin state changes.
102 Observer* observer_; 87 Observer* observer_;
103 88
104 // Set to true when SigninManager has validated our credentials.
105 bool credentials_valid_;
106
107 // Used to listen to notifications from the SigninManager. 89 // Used to listen to notifications from the SigninManager.
108 content::NotificationRegistrar registrar_; 90 content::NotificationRegistrar registrar_;
109 91
110 DISALLOW_COPY_AND_ASSIGN(SigninTracker); 92 DISALLOW_COPY_AND_ASSIGN(SigninTracker);
111 }; 93 };
112 94
113 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_ 95 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_manager.cc ('k') | chrome/browser/signin/signin_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698