OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_TRACKER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_TRACKER_H_ |
| 7 |
| 8 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 9 #include "content/public/browser/notification_observer.h" |
| 10 #include "content/public/browser/notification_registrar.h" |
| 11 #include "content/public/browser/notification_types.h" |
| 12 |
| 13 class Profile; |
| 14 |
| 15 // The signin flow logic is spread across several classes with varying |
| 16 // responsibilities: |
| 17 // |
| 18 // SigninTracker (this class) - This class listens to notifications from various |
| 19 // services (SigninManager, ProfileSyncService, etc) and coalesces them into |
| 20 // 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 // callbacks to SyncSetupHandler (login failed, login succeeded, services |
| 23 // started up) to help drive the login wizard. |
| 24 // |
| 25 // SyncSetupHandler - This class is primarily responsible for interacting with |
| 26 // 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 // translates system state (login errors, etc) into the appropriate calls into |
| 29 // the UI to reflect this status to the user. Various subclasses |
| 30 // (OptionsSyncSetupHandler and SyncPromoHandler provide different UIs to the |
| 31 // user, but the core logic lies in the base SyncSetupHandler class). |
| 32 // |
| 33 // LoginUIService - Our desktop UI flows rely on having only a single login flow |
| 34 // visible to the user at once. This is achieved via LoginUIService (a |
| 35 // ProfileKeyedService that keeps track of the currently visible login UI). |
| 36 // |
| 37 // SigninManager - Records the currently-logged-in user and handles all |
| 38 // interaction with the GAIA backend during the signin process. Unlike |
| 39 // SigninTracker, SigninManager only knows about the GAIA login state and is |
| 40 // not aware of the state of any signed in services. |
| 41 // |
| 42 // TokenService - Uses credentials provided by SigninManager to generate tokens |
| 43 // for all signed-in services in Chrome. |
| 44 // |
| 45 // ProfileSyncService - Provides the external API for interacting with the |
| 46 // sync framework. Listens for notifications from the TokenService to know |
| 47 // when to startup sync, and provides an Observer interface to notify the UI |
| 48 // layer of changes in sync state so they can be reflected in the UI. |
| 49 class SigninTracker : public ProfileSyncServiceObserver, |
| 50 public content::NotificationObserver { |
| 51 public: |
| 52 class Observer { |
| 53 public: |
| 54 // The GAIA credentials entered by the user have been validated. |
| 55 virtual void GaiaCredentialsValid() = 0; |
| 56 |
| 57 // The signin attempt failed. If this is called after GaiaCredentialsValid() |
| 58 // then it means there was an error launching one of the dependent services. |
| 59 virtual void SigninFailed() = 0; |
| 60 |
| 61 // The signin attempt succeeded. |
| 62 virtual void SigninSuccess() = 0; |
| 63 }; |
| 64 |
| 65 // Creates a SigninTracker that tracks the signin status on the passed |
| 66 // |profile|, and notifies the |observer| on status changes. |observer| must |
| 67 // be non-null and must outlive the SigninTracker. |
| 68 SigninTracker(Profile* profile, Observer* observer); |
| 69 virtual ~SigninTracker(); |
| 70 |
| 71 // content::NotificationObserver implementation. |
| 72 virtual void Observe(int type, |
| 73 const content::NotificationSource& source, |
| 74 const content::NotificationDetails& details) OVERRIDE; |
| 75 |
| 76 // ProfileSyncServiceObserver implementation. |
| 77 virtual void OnStateChanged() OVERRIDE; |
| 78 |
| 79 // Returns true if the various authenticated services are properly signed in |
| 80 // (no auth errors, etc). |
| 81 static bool AreServicesSignedIn(Profile* profile); |
| 82 |
| 83 private: |
| 84 // The various states the login process can be in. |
| 85 enum LoginState { |
| 86 WAITING_FOR_GAIA_VALIDATION, |
| 87 SERVICES_INITIALIZING, |
| 88 SIGNIN_COMPLETE |
| 89 }; |
| 90 |
| 91 // The current state of the login process. |
| 92 LoginState state_; |
| 93 |
| 94 // The profile whose signin status we are tracking. |
| 95 Profile* profile_; |
| 96 |
| 97 // Weak pointer to the observer we call when the signin state changes. |
| 98 Observer* observer_; |
| 99 |
| 100 // Set to true when SigninManager has validated our credentials. |
| 101 bool credentials_valid_; |
| 102 |
| 103 // Used to listen to notifications from the SigninManager. |
| 104 content::NotificationRegistrar registrar_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(SigninTracker); |
| 107 }; |
| 108 |
| 109 #endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_TRACKER_H_ |
| 110 |
OLD | NEW |