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.
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_
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"
16 // The signin flow logic is spread across several classes with varying
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.
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.
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
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.
42 // TokenService - Uses credentials provided by SigninManager to generate tokens
43 // for all signed-in services in Chrome.
45 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
46 // connected to this profile.
48 // ProfileSyncService - Provides the external API for interacting with the
49 // sync framework. Listens for notifications from the TokenService to know
50 // when to startup sync, and provides an Observer interface to notify the UI
51 // layer of changes in sync state so they can be reflected in the UI.
52 class SigninTracker : public content::NotificationObserver,
53 public OAuth2TokenService::Observer {
57 // The signin attempt failed, and the cause is passed in |error|.
58 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0;
60 // The signin attempt succeeded.
61 virtual void SigninSuccess() = 0;
64 // Creates a SigninTracker that tracks the signin status on the passed
65 // |profile|, and notifies the |observer| on status changes. |observer| must
66 // be non-null and must outlive the SigninTracker.
67 SigninTracker(Profile* profile, Observer* observer);
68 virtual ~SigninTracker();
70 // content::NotificationObserver implementation.
71 virtual void Observe(int type,
72 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE;
75 // OAuth2TokenService::Observer implementation.
76 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
77 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
80 // Initializes this by adding notifications and observers.
83 // The profile whose signin status we are tracking.
86 // Weak pointer to the observer we call when the signin state changes.
89 // Used to listen to notifications from the SigninManager.
90 content::NotificationRegistrar registrar_;
92 DISALLOW_COPY_AND_ASSIGN(SigninTracker);
95 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_