| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/signin/signin_supervised_user_import_handler.h
" | 5 #include "chrome/browser/ui/webui/signin/signin_supervised_user_import_handler.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <set> | 10 #include <set> |
| 11 #include <utility> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/bind.h" | 14 #include "base/bind.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/value_conversions.h" | 17 #include "base/value_conversions.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_attributes_entry.h" | 21 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 base::ListValue supervised_users; | 251 base::ListValue supervised_users; |
| 250 SupervisedUserSharedSettingsService* service = | 252 SupervisedUserSharedSettingsService* service = |
| 251 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); | 253 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
| 252 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 254 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 253 const base::DictionaryValue* value = NULL; | 255 const base::DictionaryValue* value = NULL; |
| 254 bool success = it.value().GetAsDictionary(&value); | 256 bool success = it.value().GetAsDictionary(&value); |
| 255 DCHECK(success); | 257 DCHECK(success); |
| 256 std::string name; | 258 std::string name; |
| 257 value->GetString(SupervisedUserSyncService::kName, &name); | 259 value->GetString(SupervisedUserSyncService::kName, &name); |
| 258 | 260 |
| 259 base::DictionaryValue* supervised_user = new base::DictionaryValue; | 261 std::unique_ptr<base::DictionaryValue> supervised_user( |
| 262 new base::DictionaryValue); |
| 260 supervised_user->SetString("id", it.key()); | 263 supervised_user->SetString("id", it.key()); |
| 261 supervised_user->SetString("name", name); | 264 supervised_user->SetString("name", name); |
| 262 | 265 |
| 263 int avatar_index = SupervisedUserSyncService::kNoAvatar; | 266 int avatar_index = SupervisedUserSyncService::kNoAvatar; |
| 264 const base::Value* avatar_index_value = | 267 const base::Value* avatar_index_value = |
| 265 service->GetValue(it.key(), supervised_users::kChromeAvatarIndex); | 268 service->GetValue(it.key(), supervised_users::kChromeAvatarIndex); |
| 266 if (avatar_index_value) { | 269 if (avatar_index_value) { |
| 267 success = avatar_index_value->GetAsInteger(&avatar_index); | 270 success = avatar_index_value->GetAsInteger(&avatar_index); |
| 268 } else { | 271 } else { |
| 269 // Check if there is a legacy avatar index stored. | 272 // Check if there is a legacy avatar index stored. |
| 270 std::string avatar_str; | 273 std::string avatar_str; |
| 271 value->GetString(SupervisedUserSyncService::kChromeAvatar, &avatar_str); | 274 value->GetString(SupervisedUserSyncService::kChromeAvatar, &avatar_str); |
| 272 success = | 275 success = |
| 273 SupervisedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); | 276 SupervisedUserSyncService::GetAvatarIndex(avatar_str, &avatar_index); |
| 274 } | 277 } |
| 275 DCHECK(success); | 278 DCHECK(success); |
| 276 | 279 |
| 277 std::string avatar_url = | 280 std::string avatar_url = |
| 278 avatar_index == SupervisedUserSyncService::kNoAvatar ? | 281 avatar_index == SupervisedUserSyncService::kNoAvatar ? |
| 279 profiles::GetDefaultAvatarIconUrl( | 282 profiles::GetDefaultAvatarIconUrl( |
| 280 profiles::GetPlaceholderAvatarIndex()) : | 283 profiles::GetPlaceholderAvatarIndex()) : |
| 281 profiles::GetDefaultAvatarIconUrl(avatar_index); | 284 profiles::GetDefaultAvatarIconUrl(avatar_index); |
| 282 supervised_user->SetString("iconURL", avatar_url); | 285 supervised_user->SetString("iconURL", avatar_url); |
| 283 bool on_current_device = | 286 bool on_current_device = |
| 284 supervised_user_ids.find(it.key()) != supervised_user_ids.end(); | 287 supervised_user_ids.find(it.key()) != supervised_user_ids.end(); |
| 285 supervised_user->SetBoolean("onCurrentDevice", on_current_device); | 288 supervised_user->SetBoolean("onCurrentDevice", on_current_device); |
| 286 | 289 |
| 287 supervised_users.Append(supervised_user); | 290 supervised_users.Append(std::move(supervised_user)); |
| 288 } | 291 } |
| 289 | 292 |
| 290 // Resolve callback with response. | 293 // Resolve callback with response. |
| 291 ResolveJavascriptCallback( | 294 ResolveJavascriptCallback( |
| 292 base::StringValue(webui_callback_id_), | 295 base::StringValue(webui_callback_id_), |
| 293 supervised_users); | 296 supervised_users); |
| 294 webui_callback_id_.clear(); | 297 webui_callback_id_.clear(); |
| 295 } | 298 } |
| 296 | 299 |
| 297 bool SigninSupervisedUserImportHandler::IsAccountConnected( | 300 bool SigninSupervisedUserImportHandler::IsAccountConnected( |
| 298 Profile* profile) const { | 301 Profile* profile) const { |
| 299 SigninManagerBase* signin_manager = | 302 SigninManagerBase* signin_manager = |
| 300 SigninManagerFactory::GetForProfile(profile); | 303 SigninManagerFactory::GetForProfile(profile); |
| 301 return signin_manager && signin_manager->IsAuthenticated(); | 304 return signin_manager && signin_manager->IsAuthenticated(); |
| 302 } | 305 } |
| 303 | 306 |
| 304 bool SigninSupervisedUserImportHandler::HasAuthError(Profile* profile) const { | 307 bool SigninSupervisedUserImportHandler::HasAuthError(Profile* profile) const { |
| 305 SigninErrorController* error_controller = | 308 SigninErrorController* error_controller = |
| 306 SigninErrorControllerFactory::GetForProfile(profile); | 309 SigninErrorControllerFactory::GetForProfile(profile); |
| 307 if (!error_controller) | 310 if (!error_controller) |
| 308 return true; | 311 return true; |
| 309 | 312 |
| 310 GoogleServiceAuthError::State state = error_controller->auth_error().state(); | 313 GoogleServiceAuthError::State state = error_controller->auth_error().state(); |
| 311 return state != GoogleServiceAuthError::NONE; | 314 return state != GoogleServiceAuthError::NONE; |
| 312 } | 315 } |
| OLD | NEW |