| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/login/signin/auth_sync_observer.h" | 5 #include "chrome/browser/chromeos/login/signin/auth_sync_observer.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "base/metrics/user_metrics_action.h" | 8 #include "base/metrics/user_metrics_action.h" |
| 9 #include "chrome/browser/chromeos/login/reauth_stats.h" | 9 #include "chrome/browser/chromeos/login/reauth_stats.h" |
| 10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 sync_service->AddObserver(this); | 40 sync_service->AddObserver(this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void AuthSyncObserver::Shutdown() { | 43 void AuthSyncObserver::Shutdown() { |
| 44 browser_sync::ProfileSyncService* sync_service = | 44 browser_sync::ProfileSyncService* sync_service = |
| 45 ProfileSyncServiceFactory::GetForProfile(profile_); | 45 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 46 if (sync_service) | 46 if (sync_service) |
| 47 sync_service->RemoveObserver(this); | 47 sync_service->RemoveObserver(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void AuthSyncObserver::OnStateChanged() { | 50 void AuthSyncObserver::OnStateChanged(syncer::SyncService* sync) { |
| 51 DCHECK(user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount() || | 51 DCHECK(user_manager::UserManager::Get()->IsLoggedInAsUserWithGaiaAccount() || |
| 52 user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()); | 52 user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()); |
| 53 browser_sync::ProfileSyncService* sync_service = | |
| 54 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 55 const user_manager::User* user = | 53 const user_manager::User* user = |
| 56 ProfileHelper::Get()->GetUserByProfile(profile_); | 54 ProfileHelper::Get()->GetUserByProfile(profile_); |
| 57 GoogleServiceAuthError::State state = | 55 GoogleServiceAuthError::State state = sync->GetAuthError().state(); |
| 58 sync_service->GetAuthError().state(); | |
| 59 if (state != GoogleServiceAuthError::NONE && | 56 if (state != GoogleServiceAuthError::NONE && |
| 60 state != GoogleServiceAuthError::CONNECTION_FAILED && | 57 state != GoogleServiceAuthError::CONNECTION_FAILED && |
| 61 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && | 58 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
| 62 state != GoogleServiceAuthError::REQUEST_CANCELED) { | 59 state != GoogleServiceAuthError::REQUEST_CANCELED) { |
| 63 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is | 60 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is |
| 64 // needed because sign-out/sign-in solution is suggested to the user. | 61 // needed because sign-out/sign-in solution is suggested to the user. |
| 65 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. | 62 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. |
| 66 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " | 63 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " |
| 67 << sync_service->GetAuthError().ToString(); | 64 << sync->GetAuthError().ToString(); |
| 68 const AccountId& account_id = user->GetAccountId(); | 65 const AccountId& account_id = user->GetAccountId(); |
| 69 DCHECK(account_id.is_valid()); | 66 DCHECK(account_id.is_valid()); |
| 70 // TODO(nkostyelv): Change observer after active user has changed. | 67 // TODO(nkostyelv): Change observer after active user has changed. |
| 71 user_manager::User::OAuthTokenStatus old_status = | 68 user_manager::User::OAuthTokenStatus old_status = |
| 72 user->oauth_token_status(); | 69 user->oauth_token_status(); |
| 73 user_manager::UserManager::Get()->SaveUserOAuthStatus( | 70 user_manager::UserManager::Get()->SaveUserOAuthStatus( |
| 74 account_id, user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); | 71 account_id, user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); |
| 75 RecordReauthReason(account_id, ReauthReason::SYNC_FAILED); | 72 RecordReauthReason(account_id, ReauthReason::SYNC_FAILED); |
| 76 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED && | 73 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED && |
| 77 old_status != user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) { | 74 old_status != user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 98 } | 95 } |
| 99 } | 96 } |
| 100 } | 97 } |
| 101 | 98 |
| 102 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { | 99 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { |
| 103 ChromeUserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( | 100 ChromeUserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( |
| 104 profile_, token); | 101 profile_, token); |
| 105 } | 102 } |
| 106 | 103 |
| 107 } // namespace chromeos | 104 } // namespace chromeos |
| OLD | NEW |