1 // Copyright 2014 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 COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_TRACKER_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_TRACKER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "components/signin/core/browser/gaia_cookie_manager_service.h"
10 #include "components/signin/core/browser/signin_manager.h"
11 #include "google_apis/gaia/google_service_auth_error.h"
13 class ProfileOAuth2TokenService
;
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 // GaiaCookieManagerService - Responsible for adding or removing cookies from
46 // the cookie jar from the browser process. A single source of information about
47 // GAIA cookies in the cookie jar that are fetchable via /ListAccounts.
49 // ProfileSyncService - Provides the external API for interacting with the
50 // sync framework. Listens for notifications for tokens to know when to startup
51 // sync, and provides an Observer interface to notify the UI layer of changes
52 // in sync state so they can be reflected in the UI.
53 class SigninTracker
: public SigninManagerBase::Observer
,
54 public OAuth2TokenService::Observer
,
55 public GaiaCookieManagerService::Observer
{
59 // The signin attempt failed, and the cause is passed in |error|.
60 virtual void SigninFailed(const GoogleServiceAuthError
& error
) = 0;
62 // The signin attempt succeeded.
63 virtual void SigninSuccess() = 0;
65 // The signed in account has been added into the content area cookie jar.
66 // This will be called only after a call to SigninSuccess().
67 virtual void AccountAddedToCookie(const GoogleServiceAuthError
& error
) = 0;
70 // Creates a SigninTracker that tracks the signin status on the passed
71 // classes, and notifies the |observer| on status changes. All of the
72 // instances with the exception of |account_reconcilor| must be non-null and
73 // must outlive the SigninTracker. |account_reconcilor| will be used if it is
75 SigninTracker(ProfileOAuth2TokenService
* token_service
,
76 SigninManagerBase
* signin_manager
,
77 GaiaCookieManagerService
* cookie_manager_service
,
80 ~SigninTracker() override
;
82 // SigninManagerBase::Observer implementation.
83 void GoogleSigninFailed(const GoogleServiceAuthError
& error
) override
;
85 // OAuth2TokenService::Observer implementation.
86 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
87 void OnRefreshTokenRevoked(const std::string
& account_id
) override
;
90 // Initializes this by adding notifications and observers.
93 // GaiaCookieManagerService::Observer implementation.
94 void OnAddAccountToCookieCompleted(
95 const std::string
& account_id
,
96 const GoogleServiceAuthError
& error
) override
;
98 // The classes whose collective signin status we are tracking.
99 ProfileOAuth2TokenService
* token_service_
;
100 SigninManagerBase
* signin_manager_
;
101 GaiaCookieManagerService
* cookie_manager_service_
;
103 // The client associated with this instance.
104 SigninClient
* client_
;
106 // Weak pointer to the observer we call when the signin state changes.
109 DISALLOW_COPY_AND_ASSIGN(SigninTracker
);
112 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_TRACKER_H_