Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / signin / signin_tracker.h
blobb5e522ba75f8930f9ff99547aa6dad7ba36f9176
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 "base/memory/scoped_ptr.h"
9 #include "chrome/browser/signin/google_auto_login_helper.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
12 #include "content/public/browser/notification_types.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "google_apis/gaia/oauth2_token_service.h"
16 class Profile;
18 // The signin flow logic is spread across several classes with varying
19 // responsibilities:
21 // SigninTracker (this class) - This class listens to notifications from various
22 // services (SigninManager, OAuth2TokenService) and coalesces them into
23 // notifications for the UI layer. This is the class that encapsulates the logic
24 // that determines whether a user is fully logged in or not, and exposes
25 // callbacks so various pieces of the UI (OneClickSyncStarter) can track the
26 // current startup state.
28 // SyncSetupHandler - This class is primarily responsible for interacting with
29 // the web UI for performing system login and sync configuration. Receives
30 // callbacks from the UI when the user wishes to initiate a login, and
31 // translates system state (login errors, etc) into the appropriate calls into
32 // the UI to reflect this status to the user.
34 // LoginUIService - Our desktop UI flows rely on having only a single login flow
35 // visible to the user at once. This is achieved via LoginUIService
36 // (a BrowserContextKeyedService that keeps track of the currently visible
37 // login UI).
39 // SigninManager - Records the currently-logged-in user and handles all
40 // interaction with the GAIA backend during the signin process. Unlike
41 // SigninTracker, SigninManager only knows about the GAIA login state and is
42 // not aware of the state of any signed in services.
44 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
45 // connected to this profile.
47 // ProfileSyncService - Provides the external API for interacting with the
48 // sync framework. Listens for notifications for tokens to know when to startup
49 // sync, and provides an Observer interface to notify the UI layer of changes
50 // in sync state so they can be reflected in the UI.
51 class SigninTracker : public content::NotificationObserver,
52 public OAuth2TokenService::Observer,
53 public GoogleAutoLoginHelper::Observer {
54 public:
55 class Observer {
56 public:
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;
63 // The signed in account has been merged into the content area cookie jar.
64 // This will be called only after a call to SigninSuccess().
65 virtual void MergeSessionComplete(const GoogleServiceAuthError& error) = 0;
68 // Creates a SigninTracker that tracks the signin status on the passed
69 // |profile|, and notifies the |observer| on status changes. |observer| must
70 // be non-null and must outlive the SigninTracker.
71 SigninTracker(Profile* profile, Observer* observer);
72 virtual ~SigninTracker();
74 // content::NotificationObserver implementation.
75 virtual void Observe(int type,
76 const content::NotificationSource& source,
77 const content::NotificationDetails& details) OVERRIDE;
79 // OAuth2TokenService::Observer implementation.
80 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
81 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
83 private:
84 // Initializes this by adding notifications and observers.
85 void Initialize();
87 // GoogleAutoLoginHelper::Observer implementation.
88 virtual void MergeSessionCompleted(
89 const std::string& account_id,
90 const GoogleServiceAuthError& error) OVERRIDE;
92 // The profile whose signin status we are tracking.
93 Profile* profile_;
95 // Weak pointer to the observer we call when the signin state changes.
96 Observer* observer_;
98 // Used to listen to notifications from the SigninManager.
99 content::NotificationRegistrar registrar_;
101 DISALLOW_COPY_AND_ASSIGN(SigninTracker);
104 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_