Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ | 6 #define CHROME_BROWSER_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/observer_list.h" | |
| 10 #include "chrome/browser/signin/ubertoken_fetcher.h" | 11 #include "chrome/browser/signin/ubertoken_fetcher.h" |
| 11 #include "google_apis/gaia/gaia_auth_consumer.h" | 12 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 12 | 13 |
| 13 class GaiaAuthFetcher; | 14 class GaiaAuthFetcher; |
| 15 class GoogleServiceAuthError; | |
| 14 class Profile; | 16 class Profile; |
| 15 | 17 |
| 16 // Logs in the current signed in user into Google services. Populates the cookie | 18 // Merges a Google account known to Chrome into the cookie jar. Once the |
| 17 // jar with Google credentials of the signed in user. | 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. | |
| 23 // | |
| 24 // By default instances of GoogleAutoLoginHelper delete themselves when done. | |
| 18 class GoogleAutoLoginHelper : public GaiaAuthConsumer, | 25 class GoogleAutoLoginHelper : public GaiaAuthConsumer, |
|
guohui
2013/12/20 16:11:09
The class has changed a lot to the point that its
| |
| 19 public UbertokenConsumer { | 26 public UbertokenConsumer { |
| 20 public: | 27 public: |
| 21 explicit GoogleAutoLoginHelper(Profile* profile); | 28 class Observer { |
| 29 public: | |
| 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; | |
| 35 protected: | |
| 36 virtual ~Observer() {} | |
| 37 }; | |
| 38 | |
| 39 GoogleAutoLoginHelper(Profile* profile, Observer* observer); | |
| 22 virtual ~GoogleAutoLoginHelper(); | 40 virtual ~GoogleAutoLoginHelper(); |
| 23 | 41 |
| 24 void LogIn(); | 42 void LogIn(); |
| 25 void LogIn(const std::string& account_id); | 43 void LogIn(const std::string& account_id); |
| 26 | 44 |
| 45 // Add or remove observers of this helper. | |
| 46 void AddObserver(Observer* observer); | |
| 47 void RemoveObserver(Observer* observer); | |
| 48 | |
| 49 protected: | |
| 50 Profile* profile() { return profile_; } | |
| 51 | |
| 52 // Overridden from UbertokenConsumer. | |
| 53 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE; | |
| 54 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | |
| 55 | |
| 27 // Overridden from GaiaAuthConsumer. | 56 // Overridden from GaiaAuthConsumer. |
| 28 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE; | 57 virtual void OnMergeSessionSuccess(const std::string& data) OVERRIDE; |
| 29 virtual void OnMergeSessionFailure(const GoogleServiceAuthError& error) | 58 virtual void OnMergeSessionFailure(const GoogleServiceAuthError& error) |
| 30 OVERRIDE; | 59 OVERRIDE; |
| 31 | 60 |
| 32 // Overridden from UbertokenConsumer. | 61 private: |
| 33 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE; | 62 // Starts the proess of fetching the uber token and performing a merge session |
| 34 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 63 // for the next account. Virtual so that it can be overriden in tests. |
| 64 virtual void StartFetching(); | |
| 35 | 65 |
| 36 // For testing. | 66 // Call observer when merge session completes. |
| 37 virtual UbertokenFetcher* CreateNewUbertokenFetcher(); | 67 void SignalComplete(const std::string& account_id, |
| 38 virtual GaiaAuthFetcher* CreateNewGaiaAuthFetcher(); | 68 const GoogleServiceAuthError& error); |
| 39 | 69 |
| 40 private: | 70 // Start the next merge session, if needed. |
| 71 void MergeNextAccount(); | |
| 72 | |
| 41 Profile* profile_; | 73 Profile* profile_; |
| 42 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 74 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
| 43 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; | 75 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; |
| 44 std::deque<std::string> accounts_; | 76 std::deque<std::string> accounts_; |
| 45 | 77 |
| 78 // List of observers to notify when merge session completes. | |
| 79 // Makes sure list is empty on destruction. | |
| 80 ObserverList<Observer, true> observer_list_; | |
| 81 | |
| 46 DISALLOW_COPY_AND_ASSIGN(GoogleAutoLoginHelper); | 82 DISALLOW_COPY_AND_ASSIGN(GoogleAutoLoginHelper); |
| 47 }; | 83 }; |
| 48 | 84 |
| 49 #endif // CHROME_BROWSER_ANDROID_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ | 85 #endif // CHROME_BROWSER_SIGNIN_GOOGLE_AUTO_LOGIN_HELPER_H_ |
| OLD | NEW |