Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / components / signin / core / browser / signin_tracker.h
blob2dcd5c91c8bbf291acbf1680a1d53efafcd22611
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 AccountReconcilor;
14 class ProfileOAuth2TokenService;
15 class SigninClient;
17 // The signin flow logic is spread across several classes with varying
18 // responsibilities:
20 // SigninTracker (this class) - This class listens to notifications from various
21 // services (SigninManager, OAuth2TokenService) and coalesces them into
22 // notifications for the UI layer. This is the class that encapsulates the logic
23 // that determines whether a user is fully logged in or not, and exposes
24 // callbacks so various pieces of the UI (OneClickSyncStarter) can track the
25 // current startup state.
27 // SyncSetupHandler - This class is primarily responsible for interacting with
28 // the web UI for performing system login and sync configuration. Receives
29 // callbacks from the UI when the user wishes to initiate a login, and
30 // translates system state (login errors, etc) into the appropriate calls into
31 // the UI to reflect this status to the user.
33 // LoginUIService - Our desktop UI flows rely on having only a single login flow
34 // visible to the user at once. This is achieved via LoginUIService
35 // (a KeyedService that keeps track of the currently visible
36 // login UI).
38 // SigninManager - Records the currently-logged-in user and handles all
39 // interaction with the GAIA backend during the signin process. Unlike
40 // SigninTracker, SigninManager only knows about the GAIA login state and is
41 // not aware of the state of any signed in services.
43 // OAuth2TokenService - Maintains and manages OAuth2 tokens for the accounts
44 // connected to this profile.
46 // GaiaCookieManagerService - Responsible for adding or removing cookies from
47 // the cookie jar from the browser process. A single source of information about
48 // GAIA cookies in the cookie jar that are fetchable via /ListAccounts.
50 // ProfileSyncService - Provides the external API for interacting with the
51 // sync framework. Listens for notifications for tokens to know when to startup
52 // sync, and provides an Observer interface to notify the UI layer of changes
53 // in sync state so they can be reflected in the UI.
54 class SigninTracker : public SigninManagerBase::Observer,
55 public OAuth2TokenService::Observer,
56 public GaiaCookieManagerService::Observer {
57 public:
58 class Observer {
59 public:
60 // The signin attempt failed, and the cause is passed in |error|.
61 virtual void SigninFailed(const GoogleServiceAuthError& error) = 0;
63 // The signin attempt succeeded.
64 virtual void SigninSuccess() = 0;
66 // The signed in account has been added into the content area cookie jar.
67 // This will be called only after a call to SigninSuccess().
68 virtual void MergeSessionComplete(const GoogleServiceAuthError& error) = 0;
71 // Creates a SigninTracker that tracks the signin status on the passed
72 // classes, and notifies the |observer| on status changes. All of the
73 // instances with the exception of |account_reconcilor| must be non-null and
74 // must outlive the SigninTracker. |account_reconcilor| will be used if it is
75 // non-null.
76 SigninTracker(ProfileOAuth2TokenService* token_service,
77 SigninManagerBase* signin_manager,
78 AccountReconcilor* account_reconcilor,
79 GaiaCookieManagerService* cookie_manager_service,
80 SigninClient* client,
81 Observer* observer);
82 ~SigninTracker() override;
84 // SigninManagerBase::Observer implementation.
85 void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
87 // OAuth2TokenService::Observer implementation.
88 void OnRefreshTokenAvailable(const std::string& account_id) override;
89 void OnRefreshTokenRevoked(const std::string& account_id) override;
91 private:
92 // Initializes this by adding notifications and observers.
93 void Initialize();
95 // GaiaCookieManagerService::Observer implementation.
96 void OnAddAccountToCookieCompleted(
97 const std::string& account_id,
98 const GoogleServiceAuthError& error) override;
100 // The classes whose collective signin status we are tracking.
101 ProfileOAuth2TokenService* token_service_;
102 SigninManagerBase* signin_manager_;
103 AccountReconcilor* account_reconcilor_;
104 GaiaCookieManagerService* cookie_manager_service_;
106 // The client associated with this instance.
107 SigninClient* client_;
109 // Weak pointer to the observer we call when the signin state changes.
110 Observer* observer_;
112 DISALLOW_COPY_AND_ASSIGN(SigninTracker);
115 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_TRACKER_H_