| 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 "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 10 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 void AuthSyncObserver::Shutdown() { | 39 void AuthSyncObserver::Shutdown() { |
| 40 ProfileSyncService* sync_service = | 40 ProfileSyncService* sync_service = |
| 41 ProfileSyncServiceFactory::GetForProfile(profile_); | 41 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 42 if (sync_service) | 42 if (sync_service) |
| 43 sync_service->RemoveObserver(this); | 43 sync_service->RemoveObserver(this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void AuthSyncObserver::OnStateChanged() { | 46 void AuthSyncObserver::OnStateChanged() { |
| 47 DCHECK(UserManager::Get()->IsLoggedInAsRegularUser() || | 47 DCHECK(GetUserManager()->IsLoggedInAsRegularUser() || |
| 48 UserManager::Get()->IsLoggedInAsLocallyManagedUser()); | 48 GetUserManager()->IsLoggedInAsLocallyManagedUser()); |
| 49 ProfileSyncService* sync_service = | 49 ProfileSyncService* sync_service = |
| 50 ProfileSyncServiceFactory::GetForProfile(profile_); | 50 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 51 User* user = ProfileHelper::Get()->GetUserByProfile(profile_); | 51 User* user = ProfileHelper::Get()->GetUserByProfile(profile_); |
| 52 GoogleServiceAuthError::State state = | 52 GoogleServiceAuthError::State state = |
| 53 sync_service->GetAuthError().state(); | 53 sync_service->GetAuthError().state(); |
| 54 if (state != GoogleServiceAuthError::NONE && | 54 if (state != GoogleServiceAuthError::NONE && |
| 55 state != GoogleServiceAuthError::CONNECTION_FAILED && | 55 state != GoogleServiceAuthError::CONNECTION_FAILED && |
| 56 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && | 56 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
| 57 state != GoogleServiceAuthError::REQUEST_CANCELED) { | 57 state != GoogleServiceAuthError::REQUEST_CANCELED) { |
| 58 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is | 58 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is |
| 59 // needed because sign-out/sign-in solution is suggested to the user. | 59 // needed because sign-out/sign-in solution is suggested to the user. |
| 60 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. | 60 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. |
| 61 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " | 61 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " |
| 62 << sync_service->GetAuthError().ToString(); | 62 << sync_service->GetAuthError().ToString(); |
| 63 std::string email = user->email(); | 63 std::string email = user->email(); |
| 64 DCHECK(!email.empty()); | 64 DCHECK(!email.empty()); |
| 65 // TODO(nkostyelv): Change observer after active user has changed. | 65 // TODO(nkostyelv): Change observer after active user has changed. |
| 66 User::OAuthTokenStatus old_status = user->oauth_token_status(); | 66 User::OAuthTokenStatus old_status = user->oauth_token_status(); |
| 67 UserManager::Get()->SaveUserOAuthStatus(email, | 67 GetUserManager()->SaveUserOAuthStatus(email, |
| 68 User::OAUTH2_TOKEN_STATUS_INVALID); | 68 User::OAUTH2_TOKEN_STATUS_INVALID); |
| 69 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED && | 69 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED && |
| 70 old_status != User::OAUTH2_TOKEN_STATUS_INVALID) { | 70 old_status != User::OAUTH2_TOKEN_STATUS_INVALID) { |
| 71 // Attempt to restore token from file. | 71 // Attempt to restore token from file. |
| 72 UserManager::Get()->GetSupervisedUserManager()->LoadSupervisedUserToken( | 72 GetUserManager()->GetSupervisedUserManager()->LoadSupervisedUserToken( |
| 73 profile_, | 73 profile_, |
| 74 base::Bind(&AuthSyncObserver::OnSupervisedTokenLoaded, | 74 base::Bind(&AuthSyncObserver::OnSupervisedTokenLoaded, |
| 75 base::Unretained(this))); | 75 base::Unretained(this))); |
| 76 content::RecordAction( | 76 content::RecordAction( |
| 77 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Invalidated")); | 77 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Invalidated")); |
| 78 } | 78 } |
| 79 } else if (state == GoogleServiceAuthError::NONE) { | 79 } else if (state == GoogleServiceAuthError::NONE) { |
| 80 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED && | 80 if (user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED && |
| 81 user->oauth_token_status() == User::OAUTH2_TOKEN_STATUS_INVALID) { | 81 user->oauth_token_status() == User::OAUTH2_TOKEN_STATUS_INVALID) { |
| 82 LOG(ERROR) << | 82 LOG(ERROR) << |
| 83 "Got an incorrectly invalidated token case, restoring token status."; | 83 "Got an incorrectly invalidated token case, restoring token status."; |
| 84 UserManager::Get()->SaveUserOAuthStatus( | 84 GetUserManager()->SaveUserOAuthStatus(user->email(), |
| 85 user->email(), | 85 User::OAUTH2_TOKEN_STATUS_VALID); |
| 86 User::OAUTH2_TOKEN_STATUS_VALID); | |
| 87 content::RecordAction( | 86 content::RecordAction( |
| 88 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Recovered")); | 87 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Recovered")); |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 | 91 |
| 93 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { | 92 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { |
| 94 UserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( | 93 GetUserManager()->GetSupervisedUserManager()->ConfigureSyncWithToken(profile_, |
| 95 profile_, token); | 94 token); |
| 96 } | 95 } |
| 97 | 96 |
| 98 } // namespace chromeos | 97 } // namespace chromeos |
| OLD | NEW |