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 "components/signin/core/browser/signin_manager_base.h"
10 #include "google_apis/gaia/google_service_auth_error.h"
11 #include "google_apis/gaia/merge_session_helper.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 KeyedService 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 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
43 // connected to this profile.
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 SigninManagerBase::Observer,
50 public OAuth2TokenService::Observer,
51 public MergeSessionHelper::Observer {
55 // The signin attempt failed, and the cause is passed in |error|.
56 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0;
58 // The signin attempt succeeded.
59 virtual void SigninSuccess() = 0;
61 // The signed in account has been merged into the content area cookie jar.
62 // This will be called only after a call to SigninSuccess().
63 virtual void MergeSessionComplete(const GoogleServiceAuthError& error) = 0;
66 // Creates a SigninTracker that tracks the signin status on the passed
67 // |profile|, and notifies the |observer| on status changes. |observer| must
68 // be non-null and must outlive the SigninTracker.
69 SigninTracker(Profile* profile, Observer* observer);
70 virtual ~SigninTracker();
72 // SigninManagerBase::Observer implementation.
73 virtual void GoogleSigninFailed(const GoogleServiceAuthError& error) 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 // MergeSessionHelper::Observer implementation.
84 virtual void MergeSessionCompleted(
85 const std::string& account_id,
86 const GoogleServiceAuthError& error) OVERRIDE;
88 // The profile whose signin status we are tracking.
91 // Weak pointer to the observer we call when the signin state changes.
94 DISALLOW_COPY_AND_ASSIGN(SigninTracker);
97 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_TRACKER_H_