Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / signin / core / browser / account_reconcilor.h
index 9ec3aae..8b87f20 100644 (file)
@@ -17,6 +17,7 @@
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/scoped_vector.h"
 #include "components/keyed_service/core/keyed_service.h"
+#include "components/signin/core/browser/signin_client.h"
 #include "components/signin/core/browser/signin_manager.h"
 #include "google_apis/gaia/gaia_auth_consumer.h"
 #include "google_apis/gaia/google_service_auth_error.h"
@@ -46,6 +47,11 @@ class AccountReconcilor : public KeyedService,
 
   void Initialize(bool start_reconcile_if_tokens_available);
 
+  // Signal that the status of the new_profile_management flag has changed.
+  // Pass the new status as an explicit parameter since disabling the flag
+  // doesn't remove it from the CommandLine::ForCurrentProcess().
+  void OnNewProfileManagementFlagChanged(bool new_flag_status);
+
   // KeyedService implementation.
   virtual void Shutdown() OVERRIDE;
 
@@ -56,6 +62,16 @@ class AccountReconcilor : public KeyedService,
   ProfileOAuth2TokenService* token_service() { return token_service_; }
   SigninClient* client() { return client_; }
 
+ protected:
+  // Used during GetAccountsFromCookie.
+  // Stores a callback for the next action to perform.
+  typedef base::Callback<
+      void(const GoogleServiceAuthError& error,
+           const std::vector<std::pair<std::string, bool> >&)>
+      GetAccountsFromCookieCallback;
+
+  virtual void GetAccountsFromCookie(GetAccountsFromCookieCallback callback);
+
  private:
   // An std::set<> for use with email addresses that uses
   // gaia::CanonicalizeEmail() during comparisons.
@@ -94,12 +110,8 @@ class AccountReconcilor : public KeyedService,
     return invalid_chrome_accounts_;
   }
 
-  // Used during GetAccountsFromCookie.
-  // Stores a callback for the next action to perform.
-  typedef base::Callback<
-      void(const GoogleServiceAuthError& error,
-           const std::vector<std::pair<std::string, bool> >&)>
-      GetAccountsFromCookieCallback;
+  // Virtual so that it can be overridden in tests.
+  virtual void StartFetchingExternalCcResult();
 
   friend class AccountReconcilorTest;
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, SigninManagerRegistration);
@@ -116,11 +128,15 @@ class AccountReconcilor : public KeyedService,
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopWithDots);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileNoopMultiple);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToCookie);
+  FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
+                           StartReconcileAddToCookieTwice);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileAddToChrome);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileBadPrimary);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest, StartReconcileOnlyOnce);
   FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
                            StartReconcileWithSessionInfoExpiredDefault);
+  FRIEND_TEST_ALL_PREFIXES(AccountReconcilorTest,
+                           MergeSessionCompletedWithBogusAccount);
 
   // Register and unregister with dependent services.
   void RegisterForCookieChanges();
@@ -137,13 +153,18 @@ class AccountReconcilor : public KeyedService,
   // All actions with side effects.  Virtual so that they can be overridden
   // in tests.
   virtual void PerformMergeAction(const std::string& account_id);
-  virtual void PerformAddToChromeAction(const std::string& account_id,
-                                        int session_index);
+  virtual void PerformAddToChromeAction(
+      const std::string& account_id,
+      int session_index,
+      const std::string& signin_scoped_device_id);
   virtual void PerformLogoutAllAccountsAction();
+  virtual void PerformAddAccountToTokenService(
+      const std::string& account_id,
+      const std::string& refresh_token);
 
   // Used to remove an account from chrome and the cookie jar.
-  virtual void StartRemoveAction(const std::string& account_id);
-  virtual void FinishRemoveAction(
+  virtual void PerformStartRemoveAction(const std::string& account_id);
+  virtual void PerformFinishRemoveAction(
       const std::string& account_id,
       const GoogleServiceAuthError& error,
       const std::vector<std::pair<std::string, bool> >& accounts);
@@ -159,11 +180,14 @@ class AccountReconcilor : public KeyedService,
   void HandleRefreshTokenFetched(const std::string& account_id,
                                  const std::string& refresh_token);
 
-  void GetAccountsFromCookie(GetAccountsFromCookieCallback callback);
   void ContinueReconcileActionAfterGetGaiaAccounts(
       const GoogleServiceAuthError& error,
       const std::vector<std::pair<std::string, bool> >& accounts);
   void ValidateAccountsFromTokenService();
+  // Note internally that this |account_id| is added to the cookie jar.
+  bool MarkAccountAsAddedToCookie(const std::string& account_id);
+  // Note internally that this |account_id| is added to the token service.
+  void MarkAccountAsAddedToChrome(const std::string& account_id);
 
   void OnCookieChanged(const net::CanonicalCookie* cookie);
 
@@ -185,9 +209,8 @@ class AccountReconcilor : public KeyedService,
                                  const GoogleServiceAuthError& error) OVERRIDE;
 
   // Overriden from OAuth2TokenService::Observer.
-  virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
   virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
-  virtual void OnRefreshTokensLoaded() OVERRIDE;
+  virtual void OnEndBatchChanges() OVERRIDE;
 
   // Overriden from SigninManagerBase::Observer.
   virtual void GoogleSigninSucceeded(const std::string& username,
@@ -213,6 +236,9 @@ class AccountReconcilor : public KeyedService,
   // this profile.
   bool is_reconcile_started_;
 
+  // True iff this is the first time the reconcilor is executing.
+  bool first_execution_;
+
   // Used during reconcile action.
   // These members are used used to validate the gaia cookie.  |gaia_accounts_|
   // holds the state of google accounts in the gaia cookie.  Each element is
@@ -236,6 +262,9 @@ class AccountReconcilor : public KeyedService,
 
   std::deque<GetAccountsFromCookieCallback> get_gaia_accounts_callbacks_;
 
+  scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription>
+      cookie_changed_subscription_;
+
   DISALLOW_COPY_AND_ASSIGN(AccountReconcilor);
 };