Home | History | Annotate | Download | only in signin
      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_SIGNIN_SIGNIN_TRACKER_H_
      6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
      7 
      8 #include "content/public/browser/notification_observer.h"
      9 #include "content/public/browser/notification_registrar.h"
     10 #include "content/public/browser/notification_types.h"
     11 #include "google_apis/gaia/google_service_auth_error.h"
     12 #include "google_apis/gaia/oauth2_token_service.h"
     13 
     14 class Profile;
     15 
     16 // The signin flow logic is spread across several classes with varying
     17 // responsibilities:
     18 //
     19 // SigninTracker (this class) - This class listens to notifications from various
     20 // services (SigninManager, OAuth2TokenService) and coalesces them into
     21 // notifications for the UI layer. This is the class that encapsulates the logic
     22 // that determines whether a user is fully logged in or not, and exposes
     23 // callbacks so various pieces of the UI (OneClickSyncStarter) can track the
     24 // current startup state.
     25 //
     26 // SyncSetupHandler - This class is primarily responsible for interacting with
     27 // the web UI for performing system login and sync configuration. Receives
     28 // callbacks from the UI when the user wishes to initiate a login, and
     29 // translates system state (login errors, etc) into the appropriate calls into
     30 // the UI to reflect this status to the user.
     31 //
     32 // LoginUIService - Our desktop UI flows rely on having only a single login flow
     33 // visible to the user at once. This is achieved via LoginUIService
     34 // (a BrowserContextKeyedService that keeps track of the currently visible
     35 // 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 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
     43 // connected to this profile.
     44 //
     45 // ProfileSyncService - Provides the external API for interacting with the
     46 // sync framework. Listens for notifications for tokens to know when to startup
     47 // sync, and provides an Observer interface to notify the UI layer of changes
     48 // in sync state so they can be reflected in the UI.
     49 class SigninTracker : public content::NotificationObserver,
     50                       public OAuth2TokenService::Observer {
     51  public:
     52   class Observer {
     53    public:
     54     // The signin attempt failed, and the cause is passed in |error|.
     55     virtual void SigninFailed(const GoogleServiceAuthError& error) = 0;
     56 
     57     // The signin attempt succeeded.
     58     virtual void SigninSuccess() = 0;
     59   };
     60 
     61   // Creates a SigninTracker that tracks the signin status on the passed
     62   // |profile|, and notifies the |observer| on status changes. |observer| must
     63   // be non-null and must outlive the SigninTracker.
     64   SigninTracker(Profile* profile, Observer* observer);
     65   virtual ~SigninTracker();
     66 
     67   // content::NotificationObserver implementation.
     68   virtual void Observe(int type,
     69                        const content::NotificationSource& source,
     70                        const content::NotificationDetails& details) OVERRIDE;
     71 
     72   // OAuth2TokenService::Observer implementation.
     73   virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
     74   virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
     75 
     76  private:
     77   // Initializes this by adding notifications and observers.
     78   void Initialize();
     79 
     80   // The profile whose signin status we are tracking.
     81   Profile* profile_;
     82 
     83   // Weak pointer to the observer we call when the signin state changes.
     84   Observer* observer_;
     85 
     86   // Used to listen to notifications from the SigninManager.
     87   content::NotificationRegistrar registrar_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(SigninTracker);
     90 };
     91 
     92 #endif  // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
     93