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/signin_manager.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"
14 class AccountReconcilor
;
15 class ProfileOAuth2TokenService
;
18 // The signin flow logic is spread across several classes with varying
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 KeyedService that keeps track of the currently visible
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 SigninManagerBase::Observer
,
52 public OAuth2TokenService::Observer
,
53 public MergeSessionHelper::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;
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 // classes, and notifies the |observer| on status changes. All of the
70 // instances with the exception of |account_reconcilor| must be non-null and
71 // must outlive the SigninTracker. |account_reconcilor| will be used if it is
73 SigninTracker(ProfileOAuth2TokenService
* token_service
,
74 SigninManagerBase
* signin_manager
,
75 AccountReconcilor
* account_reconcilor
,
78 ~SigninTracker() override
;
80 // SigninManagerBase::Observer implementation.
81 void GoogleSigninFailed(const GoogleServiceAuthError
& error
) override
;
83 // OAuth2TokenService::Observer implementation.
84 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
85 void OnRefreshTokenRevoked(const std::string
& account_id
) override
;
88 // Initializes this by adding notifications and observers.
91 // MergeSessionHelper::Observer implementation.
92 void MergeSessionCompleted(const std::string
& account_id
,
93 const GoogleServiceAuthError
& error
) override
;
95 // The classes whose collective signin status we are tracking.
96 ProfileOAuth2TokenService
* token_service_
;
97 SigninManagerBase
* signin_manager_
;
98 AccountReconcilor
* account_reconcilor_
;
100 // The client associated with this instance.
101 SigninClient
* client_
;
103 // Weak pointer to the observer we call when the signin state changes.
106 DISALLOW_COPY_AND_ASSIGN(SigninTracker
);
109 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_TRACKER_H_