| 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/ui/webui/options/supervised_user_import_handler.h" | 5 #include "chrome/browser/ui/webui/options/supervised_user_import_handler.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 14 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 15 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 19 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
.h" | 20 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" | 21 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" | 22 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" |
| 23 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" | 23 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 26 #include "components/signin/core/browser/profile_oauth2_token_service.h" | |
| 27 #include "components/signin/core/browser/signin_error_controller.h" | 26 #include "components/signin/core/browser/signin_error_controller.h" |
| 28 #include "components/signin/core/browser/signin_manager.h" | 27 #include "components/signin/core/browser/signin_manager.h" |
| 29 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
| 30 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 scoped_ptr<base::ListValue> GetAvatarIcons() { | 33 scoped_ptr<base::ListValue> GetAvatarIcons() { |
| 35 scoped_ptr<base::ListValue> avatar_icons(new base::ListValue); | 34 scoped_ptr<base::ListValue> avatar_icons(new base::ListValue); |
| 36 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); ++i) { | 35 for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount(); ++i) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); | 85 localized_strings->Set("avatarIcons", GetAvatarIcons().release()); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void SupervisedUserImportHandler::InitializeHandler() { | 88 void SupervisedUserImportHandler::InitializeHandler() { |
| 90 Profile* profile = Profile::FromWebUI(web_ui()); | 89 Profile* profile = Profile::FromWebUI(web_ui()); |
| 91 if (!profile->IsSupervised()) { | 90 if (!profile->IsSupervised()) { |
| 92 SupervisedUserSyncService* sync_service = | 91 SupervisedUserSyncService* sync_service = |
| 93 SupervisedUserSyncServiceFactory::GetForProfile(profile); | 92 SupervisedUserSyncServiceFactory::GetForProfile(profile); |
| 94 if (sync_service) { | 93 if (sync_service) { |
| 95 sync_service->AddObserver(this); | 94 sync_service->AddObserver(this); |
| 96 observer_.Add(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 95 observer_.Add(SigninErrorControllerFactory::GetForProfile(profile)); |
| 97 signin_error_controller()); | |
| 98 SupervisedUserSharedSettingsService* settings_service = | 96 SupervisedUserSharedSettingsService* settings_service = |
| 99 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | 97 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| 100 profile); | 98 profile); |
| 101 subscription_ = settings_service->Subscribe( | 99 subscription_ = settings_service->Subscribe( |
| 102 base::Bind(&SupervisedUserImportHandler::OnSharedSettingChanged, | 100 base::Bind(&SupervisedUserImportHandler::OnSharedSettingChanged, |
| 103 weak_ptr_factory_.GetWeakPtr())); | 101 weak_ptr_factory_.GetWeakPtr())); |
| 104 } else { | 102 } else { |
| 105 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | 103 DCHECK(!SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( |
| 106 profile)); | 104 profile)); |
| 107 DCHECK(!ProfileOAuth2TokenServiceFactory::GetForProfile(profile)); | 105 DCHECK(!SigninErrorControllerFactory::GetForProfile(profile)); |
| 108 } | 106 } |
| 109 } | 107 } |
| 110 } | 108 } |
| 111 | 109 |
| 112 void SupervisedUserImportHandler::RegisterMessages() { | 110 void SupervisedUserImportHandler::RegisterMessages() { |
| 113 web_ui()->RegisterMessageCallback("requestSupervisedUserImportUpdate", | 111 web_ui()->RegisterMessageCallback("requestSupervisedUserImportUpdate", |
| 114 base::Bind(&SupervisedUserImportHandler:: | 112 base::Bind(&SupervisedUserImportHandler:: |
| 115 RequestSupervisedUserImportUpdate, | 113 RequestSupervisedUserImportUpdate, |
| 116 base::Unretained(this))); | 114 base::Unretained(this))); |
| 117 } | 115 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 215 |
| 218 bool SupervisedUserImportHandler::IsAccountConnected() const { | 216 bool SupervisedUserImportHandler::IsAccountConnected() const { |
| 219 Profile* profile = Profile::FromWebUI(web_ui()); | 217 Profile* profile = Profile::FromWebUI(web_ui()); |
| 220 SigninManagerBase* signin_manager = | 218 SigninManagerBase* signin_manager = |
| 221 SigninManagerFactory::GetForProfile(profile); | 219 SigninManagerFactory::GetForProfile(profile); |
| 222 return signin_manager && signin_manager->IsAuthenticated(); | 220 return signin_manager && signin_manager->IsAuthenticated(); |
| 223 } | 221 } |
| 224 | 222 |
| 225 bool SupervisedUserImportHandler::HasAuthError() const { | 223 bool SupervisedUserImportHandler::HasAuthError() const { |
| 226 Profile* profile = Profile::FromWebUI(web_ui()); | 224 Profile* profile = Profile::FromWebUI(web_ui()); |
| 227 ProfileOAuth2TokenService* token_service = | 225 SigninErrorController* error_controller = |
| 228 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 226 SigninErrorControllerFactory::GetForProfile(profile); |
| 229 if (!token_service) | 227 if (!error_controller) |
| 230 return true; | 228 return true; |
| 231 | 229 |
| 232 SigninErrorController* error_controller = | |
| 233 token_service->signin_error_controller(); | |
| 234 | |
| 235 GoogleServiceAuthError::State state = error_controller->auth_error().state(); | 230 GoogleServiceAuthError::State state = error_controller->auth_error().state(); |
| 236 | 231 |
| 237 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 232 return state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || |
| 238 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || | 233 state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
| 239 state == GoogleServiceAuthError::ACCOUNT_DELETED || | 234 state == GoogleServiceAuthError::ACCOUNT_DELETED || |
| 240 state == GoogleServiceAuthError::ACCOUNT_DISABLED; | 235 state == GoogleServiceAuthError::ACCOUNT_DISABLED; |
| 241 } | 236 } |
| 242 | 237 |
| 243 void SupervisedUserImportHandler::OnSharedSettingChanged( | 238 void SupervisedUserImportHandler::OnSharedSettingChanged( |
| 244 const std::string& supervised_user_id, | 239 const std::string& supervised_user_id, |
| 245 const std::string& key) { | 240 const std::string& key) { |
| 246 if (key == supervised_users::kChromeAvatarIndex) | 241 if (key == supervised_users::kChromeAvatarIndex) |
| 247 FetchSupervisedUsers(); | 242 FetchSupervisedUsers(); |
| 248 } | 243 } |
| 249 | 244 |
| 250 void SupervisedUserImportHandler::OnErrorChanged() { | 245 void SupervisedUserImportHandler::OnErrorChanged() { |
| 251 FetchSupervisedUsers(); | 246 FetchSupervisedUsers(); |
| 252 } | 247 } |
| 253 | 248 |
| 254 } // namespace options | 249 } // namespace options |
| OLD | NEW |