| 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 #include "chrome/browser/signin/account_reconcilor.h" | 5 #include "chrome/browser/signin/account_reconcilor.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/net/chrome_cookie_notification_details.h" | 11 #include "chrome/browser/net/chrome_cookie_notification_details.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/signin/google_auto_login_helper.h" | |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 16 #include "chrome/browser/signin/signin_manager.h" | 15 #include "chrome/browser/signin/signin_manager.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 21 #include "google_apis/gaia/gaia_auth_fetcher.h" | 20 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 22 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 23 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 DVLOG(1) << "AccountReconcilor::OnNetworkError: " << account_id_ | 70 DVLOG(1) << "AccountReconcilor::OnNetworkError: " << account_id_ |
| 72 << " response_code=" << response_code; | 71 << " response_code=" << response_code; |
| 73 | 72 |
| 74 // TODO(rogerta): some response error should not be treated like | 73 // TODO(rogerta): some response error should not be treated like |
| 75 // permanent errors. Figure out appropriate ones. | 74 // permanent errors. Figure out appropriate ones. |
| 76 reconcilor_->HandleFailedAccountIdCheck(account_id_); | 75 reconcilor_->HandleFailedAccountIdCheck(account_id_); |
| 77 } | 76 } |
| 78 | 77 |
| 79 AccountReconcilor::AccountReconcilor(Profile* profile) | 78 AccountReconcilor::AccountReconcilor(Profile* profile) |
| 80 : profile_(profile), | 79 : profile_(profile), |
| 80 merge_session_helper_(profile, NULL), |
| 81 registered_with_token_service_(false), | 81 registered_with_token_service_(false), |
| 82 are_gaia_accounts_set_(false), | 82 are_gaia_accounts_set_(false),requests_(NULL) { |
| 83 requests_(NULL) { | |
| 84 DVLOG(1) << "AccountReconcilor::AccountReconcilor"; | 83 DVLOG(1) << "AccountReconcilor::AccountReconcilor"; |
| 85 RegisterWithSigninManager(); | 84 RegisterWithSigninManager(); |
| 86 RegisterWithCookieMonster(); | 85 RegisterWithCookieMonster(); |
| 87 | 86 |
| 88 // If this profile is not connected, the reconcilor should do nothing but | 87 // If this profile is not connected, the reconcilor should do nothing but |
| 89 // wait for the connection. | 88 // wait for the connection. |
| 90 if (IsProfileConnected()) { | 89 if (IsProfileConnected()) { |
| 91 RegisterWithTokenService(); | 90 RegisterWithTokenService(); |
| 92 StartPeriodicReconciliation(); | 91 StartPeriodicReconciliation(); |
| 93 } | 92 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 | 103 |
| 105 void AccountReconcilor::Shutdown() { | 104 void AccountReconcilor::Shutdown() { |
| 106 DVLOG(1) << "AccountReconcilor::Shutdown"; | 105 DVLOG(1) << "AccountReconcilor::Shutdown"; |
| 107 DeleteAccessTokenRequestsAndUserIdFetchers(); | 106 DeleteAccessTokenRequestsAndUserIdFetchers(); |
| 108 UnregisterWithSigninManager(); | 107 UnregisterWithSigninManager(); |
| 109 UnregisterWithTokenService(); | 108 UnregisterWithTokenService(); |
| 110 UnregisterWithCookieMonster(); | 109 UnregisterWithCookieMonster(); |
| 111 StopPeriodicReconciliation(); | 110 StopPeriodicReconciliation(); |
| 112 } | 111 } |
| 113 | 112 |
| 113 void AccountReconcilor::AddMergeSessionObserver( |
| 114 GoogleAutoLoginHelper::Observer* observer) { |
| 115 merge_session_helper_.AddObserver(observer); |
| 116 } |
| 117 |
| 118 void AccountReconcilor::RemoveMergeSessionObserver( |
| 119 GoogleAutoLoginHelper::Observer* observer) { |
| 120 merge_session_helper_.RemoveObserver(observer); |
| 121 } |
| 122 |
| 114 void AccountReconcilor::DeleteAccessTokenRequestsAndUserIdFetchers() { | 123 void AccountReconcilor::DeleteAccessTokenRequestsAndUserIdFetchers() { |
| 115 delete[] requests_; | 124 delete[] requests_; |
| 116 requests_ = NULL; | 125 requests_ = NULL; |
| 117 | 126 |
| 118 user_id_fetchers_.clear(); | 127 user_id_fetchers_.clear(); |
| 119 } | 128 } |
| 120 | 129 |
| 121 bool AccountReconcilor::AreAllRefreshTokensChecked() const { | 130 bool AccountReconcilor::AreAllRefreshTokensChecked() const { |
| 122 return chrome_accounts_.size() == | 131 return chrome_accounts_.size() == |
| 123 (valid_chrome_accounts_.size() + invalid_chrome_accounts_.size()); | 132 (valid_chrome_accounts_.size() + invalid_chrome_accounts_.size()); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 238 } |
| 230 | 239 |
| 231 void AccountReconcilor::OnRefreshTokenRevoked(const std::string& account_id) { | 240 void AccountReconcilor::OnRefreshTokenRevoked(const std::string& account_id) { |
| 232 DVLOG(1) << "AccountReconcilor::OnRefreshTokenRevoked: " << account_id; | 241 DVLOG(1) << "AccountReconcilor::OnRefreshTokenRevoked: " << account_id; |
| 233 PerformRemoveAction(account_id); | 242 PerformRemoveAction(account_id); |
| 234 } | 243 } |
| 235 | 244 |
| 236 void AccountReconcilor::OnRefreshTokensLoaded() {} | 245 void AccountReconcilor::OnRefreshTokensLoaded() {} |
| 237 | 246 |
| 238 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { | 247 void AccountReconcilor::PerformMergeAction(const std::string& account_id) { |
| 239 // GoogleAutoLoginHelper deletes itself upon success / failure. | 248 merge_session_helper_.LogIn(account_id); |
| 240 GoogleAutoLoginHelper* helper = new GoogleAutoLoginHelper(profile_); | |
| 241 helper->LogIn(account_id); | |
| 242 } | 249 } |
| 243 | 250 |
| 244 void AccountReconcilor::PerformRemoveAction(const std::string& account_id) { | 251 void AccountReconcilor::PerformRemoveAction(const std::string& account_id) { |
| 245 // TODO(acleung): Implement this: | 252 // TODO(acleung): Implement this: |
| 246 } | 253 } |
| 247 | 254 |
| 248 void AccountReconcilor::StartReconcileAction() { | 255 void AccountReconcilor::StartReconcileAction() { |
| 249 if (!IsProfileConnected()) | 256 if (!IsProfileConnected()) |
| 250 return; | 257 return; |
| 251 | 258 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const std::string& account_id) { | 398 const std::string& account_id) { |
| 392 valid_chrome_accounts_.insert(account_id); | 399 valid_chrome_accounts_.insert(account_id); |
| 393 FinishReconcileAction(); | 400 FinishReconcileAction(); |
| 394 } | 401 } |
| 395 | 402 |
| 396 void AccountReconcilor::HandleFailedAccountIdCheck( | 403 void AccountReconcilor::HandleFailedAccountIdCheck( |
| 397 const std::string& account_id) { | 404 const std::string& account_id) { |
| 398 invalid_chrome_accounts_.insert(account_id); | 405 invalid_chrome_accounts_.insert(account_id); |
| 399 FinishReconcileAction(); | 406 FinishReconcileAction(); |
| 400 } | 407 } |
| OLD | NEW |