1 // Copyright 2013 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_GOOGLE_AUTO_LOGIN_HELPER_H_
6 #define CHROME_BROWSER_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_
10 #include "base/observer_list.h"
11 #include "google_apis/gaia/gaia_auth_consumer.h"
12 #include "google_apis/gaia/ubertoken_fetcher.h"
14 class GaiaAuthFetcher
;
15 class GoogleServiceAuthError
;
18 // Merges a Google account known to Chrome into the cookie jar. Once the
19 // account is merged, successfully or not, a NOTIFICATION_MERGE_SESSION_COMPLETE
20 // notification is sent out. When merging multiple accounts, one instance of
21 // the helper is better than multiple instances if there is the possibility
22 // that they run concurrently, since changes to the cookie must be serialized.
24 // By default instances of GoogleAutoLoginHelper delete themselves when done.
25 class GoogleAutoLoginHelper
: public GaiaAuthConsumer
,
26 public UbertokenConsumer
{
30 // Called whenever a merge session is completed. The account that was
31 // merged is given by |account_id|. If |error| is equal to
32 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded.
33 virtual void MergeSessionCompleted(const std::string
& account_id
,
34 const GoogleServiceAuthError
& error
) = 0;
36 virtual ~Observer() {}
39 GoogleAutoLoginHelper(Profile
* profile
, Observer
* observer
);
40 virtual ~GoogleAutoLoginHelper();
42 void LogIn(const std::string
& account_id
);
44 // Add or remove observers of this helper.
45 void AddObserver(Observer
* observer
);
46 void RemoveObserver(Observer
* observer
);
48 // Cancel all login requests.
52 // Overridden from UbertokenConsumer.
53 virtual void OnUbertokenSuccess(const std::string
& token
) OVERRIDE
;
54 virtual void OnUbertokenFailure(const GoogleServiceAuthError
& error
) OVERRIDE
;
56 // Overridden from GaiaAuthConsumer.
57 virtual void OnMergeSessionSuccess(const std::string
& data
) OVERRIDE
;
58 virtual void OnMergeSessionFailure(const GoogleServiceAuthError
& error
)
61 // Starts the proess of fetching the uber token and performing a merge session
62 // for the next account. Virtual so that it can be overriden in tests.
63 virtual void StartFetching();
65 // Call observer when merge session completes.
66 void SignalComplete(const std::string
& account_id
,
67 const GoogleServiceAuthError
& error
);
69 // Start the next merge session, if needed.
70 void MergeNextAccount();
73 scoped_ptr
<GaiaAuthFetcher
> gaia_auth_fetcher_
;
74 scoped_ptr
<UbertokenFetcher
> uber_token_fetcher_
;
75 std::deque
<std::string
> accounts_
;
77 // List of observers to notify when merge session completes.
78 // Makes sure list is empty on destruction.
79 ObserverList
<Observer
, true> observer_list_
;
81 DISALLOW_COPY_AND_ASSIGN(GoogleAutoLoginHelper
);
84 #endif // CHROME_BROWSER_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_