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/chromeos/login/auth_sync_observer.h" | 5 #include "chrome/browser/chromeos/login/auth_sync_observer.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chromeos/login/supervised_user_manager.h" | 8 #include "chrome/browser/chromeos/login/supervised_user_manager.h" |
9 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "chrome/browser/chromeos/login/user_manager.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 ProfileSyncServiceFactory::GetForProfile(profile_); | 36 ProfileSyncServiceFactory::GetForProfile(profile_); |
37 if (sync_service) | 37 if (sync_service) |
38 sync_service->RemoveObserver(this); | 38 sync_service->RemoveObserver(this); |
39 } | 39 } |
40 | 40 |
41 void AuthSyncObserver::OnStateChanged() { | 41 void AuthSyncObserver::OnStateChanged() { |
42 DCHECK(UserManager::Get()->IsLoggedInAsRegularUser() || | 42 DCHECK(UserManager::Get()->IsLoggedInAsRegularUser() || |
43 UserManager::Get()->IsLoggedInAsLocallyManagedUser()); | 43 UserManager::Get()->IsLoggedInAsLocallyManagedUser()); |
44 ProfileSyncService* sync_service = | 44 ProfileSyncService* sync_service = |
45 ProfileSyncServiceFactory::GetForProfile(profile_); | 45 ProfileSyncServiceFactory::GetForProfile(profile_); |
46 User* user = UserManager::Get()->GetUserByProfile(profile_); | |
46 GoogleServiceAuthError::State state = | 47 GoogleServiceAuthError::State state = |
47 sync_service->GetAuthError().state(); | 48 sync_service->GetAuthError().state(); |
48 if (state != GoogleServiceAuthError::NONE && | 49 if (state != GoogleServiceAuthError::NONE && |
49 state != GoogleServiceAuthError::CONNECTION_FAILED && | 50 state != GoogleServiceAuthError::CONNECTION_FAILED && |
50 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && | 51 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
51 state != GoogleServiceAuthError::REQUEST_CANCELED) { | 52 state != GoogleServiceAuthError::REQUEST_CANCELED) { |
52 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is | 53 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is |
53 // needed because sign-out/sign-in solution is suggested to the user. | 54 // needed because sign-out/sign-in solution is suggested to the user. |
54 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. | 55 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. |
55 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " | 56 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " |
56 << sync_service->GetAuthError().ToString(); | 57 << sync_service->GetAuthError().ToString(); |
57 std::string email = profile_->GetProfileName(); | 58 std::string email = user->email(); |
58 if (email.empty() && UserManager::Get()->IsLoggedInAsLocallyManagedUser()) { | |
59 std::string sync_id = | |
60 profile_->GetPrefs()->GetString(prefs::kManagedUserId); | |
61 const User* user = | |
62 UserManager::Get()->GetSupervisedUserManager()->FindBySyncId(sync_id); | |
63 if (user) | |
64 email = user->email(); | |
65 } | |
66 DCHECK(!email.empty()); | 59 DCHECK(!email.empty()); |
67 // TODO(nkostyelv): Change observer after active user has changed. | 60 // TODO(nkostyelv): Change observer after active user has changed. |
68 UserManager::Get()->SaveUserOAuthStatus( | 61 User::OAuthTokenStatus old_status = user->oauth_token_status(); |
69 gaia::CanonicalizeEmail(email), | 62 UserManager::Get()->SaveUserOAuthStatus(email, |
70 User::OAUTH2_TOKEN_STATUS_INVALID); | 63 User::OAUTH2_TOKEN_STATUS_INVALID); |
64 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED && | |
65 old_status == User::OAUTH2_TOKEN_STATUS_VALID) { | |
Nikita (slow)
2014/02/07 09:51:48
This needs to be checked as
old_status != User::O
| |
66 // Attempt to restore token from file. | |
67 UserManager::Get()->GetSupervisedUserManager()->LoadSupervisedUserToken( | |
Nikita (slow)
2014/02/07 09:51:48
nit: Please add UMA metric to track this.
| |
68 profile_, | |
69 base::Bind(&AuthSyncObserver::OnSupervisedTokenLoaded, | |
70 base::Unretained(this))); | |
71 | |
72 } | |
73 } else if (state == GoogleServiceAuthError::NONE) { | |
74 if (user->GetType() == User::USER_TYPE_LOCALLY_MANAGED && | |
75 user->oauth_token_status() == User::OAUTH2_TOKEN_STATUS_INVALID) { | |
76 LOG(ERROR) << | |
Nikita (slow)
2014/02/07 09:51:48
nit: Please add UMA metric to track this.
| |
77 "Got an incorrectly invalidated token case, restoring token status."; | |
78 UserManager::Get()->SaveUserOAuthStatus( | |
79 user->email(), | |
80 User::OAUTH2_TOKEN_STATUS_VALID); | |
81 } | |
71 } | 82 } |
72 } | 83 } |
73 | 84 |
85 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { | |
86 UserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( | |
87 profile_, token); | |
88 } | |
89 | |
74 } // namespace chromeos | 90 } // namespace chromeos |
OLD | NEW |