Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: chrome/browser/chromeos/login/signin/auth_sync_observer.cc

Issue 444903002: [cros] user_manager component - move UserManagerBase and UserManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chrome_user_manager.h"
10 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" 11 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/user_manager.h"
12 #include "chrome/browser/chromeos/profiles/profile_helper.h" 12 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h" 14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "components/user_manager/user_manager.h"
16 #include "components/user_manager/user_type.h" 17 #include "components/user_manager/user_type.h"
17 #include "content/public/browser/user_metrics.h" 18 #include "content/public/browser/user_metrics.h"
18 #include "google_apis/gaia/gaia_auth_util.h" 19 #include "google_apis/gaia/gaia_auth_util.h"
19 20
20 class Profile; 21 class Profile;
21 class ProfileSyncService; 22 class ProfileSyncService;
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 AuthSyncObserver::AuthSyncObserver(Profile* profile) 26 AuthSyncObserver::AuthSyncObserver(Profile* profile)
(...skipping 11 matching lines...) Expand all
37 } 38 }
38 39
39 void AuthSyncObserver::Shutdown() { 40 void AuthSyncObserver::Shutdown() {
40 ProfileSyncService* sync_service = 41 ProfileSyncService* sync_service =
41 ProfileSyncServiceFactory::GetForProfile(profile_); 42 ProfileSyncServiceFactory::GetForProfile(profile_);
42 if (sync_service) 43 if (sync_service)
43 sync_service->RemoveObserver(this); 44 sync_service->RemoveObserver(this);
44 } 45 }
45 46
46 void AuthSyncObserver::OnStateChanged() { 47 void AuthSyncObserver::OnStateChanged() {
47 DCHECK(UserManager::Get()->IsLoggedInAsRegularUser() || 48 DCHECK(user_manager::UserManager::Get()->IsLoggedInAsRegularUser() ||
48 UserManager::Get()->IsLoggedInAsSupervisedUser()); 49 user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser());
49 ProfileSyncService* sync_service = 50 ProfileSyncService* sync_service =
50 ProfileSyncServiceFactory::GetForProfile(profile_); 51 ProfileSyncServiceFactory::GetForProfile(profile_);
51 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile_); 52 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile_);
52 GoogleServiceAuthError::State state = 53 GoogleServiceAuthError::State state =
53 sync_service->GetAuthError().state(); 54 sync_service->GetAuthError().state();
54 if (state != GoogleServiceAuthError::NONE && 55 if (state != GoogleServiceAuthError::NONE &&
55 state != GoogleServiceAuthError::CONNECTION_FAILED && 56 state != GoogleServiceAuthError::CONNECTION_FAILED &&
56 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && 57 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE &&
57 state != GoogleServiceAuthError::REQUEST_CANCELED) { 58 state != GoogleServiceAuthError::REQUEST_CANCELED) {
58 // Invalidate OAuth2 refresh token to force Gaia sign-in flow. This is 59 // 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. 60 // needed because sign-out/sign-in solution is suggested to the user.
60 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented. 61 // TODO(nkostylev): Remove after crosbug.com/25978 is implemented.
61 LOG(WARNING) << "Invalidate OAuth token because of a sync error: " 62 LOG(WARNING) << "Invalidate OAuth token because of a sync error: "
62 << sync_service->GetAuthError().ToString(); 63 << sync_service->GetAuthError().ToString();
63 std::string email = user->email(); 64 std::string email = user->email();
64 DCHECK(!email.empty()); 65 DCHECK(!email.empty());
65 // TODO(nkostyelv): Change observer after active user has changed. 66 // TODO(nkostyelv): Change observer after active user has changed.
66 user_manager::User::OAuthTokenStatus old_status = 67 user_manager::User::OAuthTokenStatus old_status =
67 user->oauth_token_status(); 68 user->oauth_token_status();
68 UserManager::Get()->SaveUserOAuthStatus( 69 user_manager::UserManager::Get()->SaveUserOAuthStatus(
69 email, user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); 70 email, user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
70 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED && 71 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED &&
71 old_status != user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) { 72 old_status != user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) {
72 // Attempt to restore token from file. 73 // Attempt to restore token from file.
73 UserManager::Get()->GetSupervisedUserManager()->LoadSupervisedUserToken( 74 ChromeUserManager::Get()
74 profile_, 75 ->GetSupervisedUserManager()
75 base::Bind(&AuthSyncObserver::OnSupervisedTokenLoaded, 76 ->LoadSupervisedUserToken(
76 base::Unretained(this))); 77 profile_,
78 base::Bind(&AuthSyncObserver::OnSupervisedTokenLoaded,
79 base::Unretained(this)));
77 content::RecordAction( 80 content::RecordAction(
78 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Invalidated")); 81 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Invalidated"));
79 } 82 }
80 } else if (state == GoogleServiceAuthError::NONE) { 83 } else if (state == GoogleServiceAuthError::NONE) {
81 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED && 84 if (user->GetType() == user_manager::USER_TYPE_SUPERVISED &&
82 user->oauth_token_status() == 85 user->oauth_token_status() ==
83 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) { 86 user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) {
84 LOG(ERROR) << 87 LOG(ERROR) <<
85 "Got an incorrectly invalidated token case, restoring token status."; 88 "Got an incorrectly invalidated token case, restoring token status.";
86 UserManager::Get()->SaveUserOAuthStatus( 89 user_manager::UserManager::Get()->SaveUserOAuthStatus(
87 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_VALID); 90 user->email(), user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
88 content::RecordAction( 91 content::RecordAction(
89 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Recovered")); 92 base::UserMetricsAction("ManagedUsers_Chromeos_Sync_Recovered"));
90 } 93 }
91 } 94 }
92 } 95 }
93 96
94 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) { 97 void AuthSyncObserver::OnSupervisedTokenLoaded(const std::string& token) {
95 UserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken( 98 ChromeUserManager::Get()->GetSupervisedUserManager()->ConfigureSyncWithToken(
96 profile_, token); 99 profile_, token);
97 } 100 }
98 101
99 } // namespace chromeos 102 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698