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

Side by Side Diff: chrome/browser/ui/webui/signin/signin_create_profile_handler.cc

Issue 2468723003: Move session service and supervised users to buildflags. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
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_create_profile_handler.h" 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/profiles/profile_metrics.h" 26 #include "chrome/browser/profiles/profile_metrics.h"
27 #include "chrome/browser/profiles/profiles_state.h" 27 #include "chrome/browser/profiles/profiles_state.h"
28 #include "chrome/browser/signin/signin_error_controller_factory.h" 28 #include "chrome/browser/signin/signin_error_controller_factory.h"
29 #include "chrome/browser/signin/signin_manager_factory.h" 29 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/browser/sync/profile_sync_service_factory.h" 30 #include "chrome/browser/sync/profile_sync_service_factory.h"
31 #include "chrome/browser/ui/browser_finder.h" 31 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/user_manager.h" 32 #include "chrome/browser/ui/user_manager.h"
33 #include "chrome/browser/ui/webui/profile_helper.h" 33 #include "chrome/browser/ui/webui/profile_helper.h"
34 #include "chrome/browser/ui/webui/signin/signin_utils.h" 34 #include "chrome/browser/ui/webui/signin/signin_utils.h"
35 #include "chrome/common/features.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
36 #include "chrome/common/url_constants.h" 37 #include "chrome/common/url_constants.h"
37 #include "chrome/grit/chromium_strings.h" 38 #include "chrome/grit/chromium_strings.h"
38 #include "chrome/grit/generated_resources.h" 39 #include "chrome/grit/generated_resources.h"
39 #include "components/browser_sync/profile_sync_service.h" 40 #include "components/browser_sync/profile_sync_service.h"
40 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
41 #include "components/signin/core/browser/signin_error_controller.h" 42 #include "components/signin/core/browser/signin_error_controller.h"
42 #include "components/strings/grit/components_strings.h" 43 #include "components/strings/grit/components_strings.h"
43 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/notification_service.h" 45 #include "content/public/browser/notification_service.h"
45 #include "content/public/browser/web_ui.h" 46 #include "content/public/browser/web_ui.h"
46 #include "ui/base/l10n/l10n_util.h" 47 #include "ui/base/l10n/l10n_util.h"
47 48
48 #if defined(ENABLE_SUPERVISED_USERS) 49 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
49 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h" 50 #include "chrome/browser/supervised_user/legacy/supervised_user_registration_uti lity.h"
50 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" 51 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h"
51 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h" 52 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h"
52 #include "chrome/browser/supervised_user/supervised_user_service.h" 53 #include "chrome/browser/supervised_user/supervised_user_service.h"
53 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 54 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
54 #endif 55 #endif
55 56
56 SigninCreateProfileHandler::SigninCreateProfileHandler() 57 SigninCreateProfileHandler::SigninCreateProfileHandler()
57 : profile_creation_type_(NO_CREATION_IN_PROGRESS), 58 : profile_creation_type_(NO_CREATION_IN_PROGRESS),
58 weak_ptr_factory_(this) { 59 weak_ptr_factory_(this) {
59 g_browser_process->profile_manager()-> 60 g_browser_process->profile_manager()->
60 GetProfileAttributesStorage().AddObserver(this); 61 GetProfileAttributesStorage().AddObserver(this);
61 } 62 }
62 63
63 SigninCreateProfileHandler::~SigninCreateProfileHandler() { 64 SigninCreateProfileHandler::~SigninCreateProfileHandler() {
64 #if defined(ENABLE_SUPERVISED_USERS) 65 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
65 // Cancellation is only supported for supervised users. 66 // Cancellation is only supported for supervised users.
66 CancelProfileRegistration(false); 67 CancelProfileRegistration(false);
67 #endif 68 #endif
68 g_browser_process->profile_manager()-> 69 g_browser_process->profile_manager()->
69 GetProfileAttributesStorage().RemoveObserver(this); 70 GetProfileAttributesStorage().RemoveObserver(this);
70 } 71 }
71 72
72 void SigninCreateProfileHandler::GetLocalizedValues( 73 void SigninCreateProfileHandler::GetLocalizedValues(
73 base::DictionaryValue* localized_strings) { 74 base::DictionaryValue* localized_strings) {
74 localized_strings->SetString( 75 localized_strings->SetString(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 "supervisedUserCreatedDone", 143 "supervisedUserCreatedDone",
143 l10n_util::GetStringUTF16( 144 l10n_util::GetStringUTF16(
144 IDS_LEGACY_SUPERVISED_USER_CREATED_DONE_BUTTON)); 145 IDS_LEGACY_SUPERVISED_USER_CREATED_DONE_BUTTON));
145 localized_strings->SetString( 146 localized_strings->SetString(
146 "supervisedUserCreatedSwitch", 147 "supervisedUserCreatedSwitch",
147 l10n_util::GetStringUTF16( 148 l10n_util::GetStringUTF16(
148 IDS_LEGACY_SUPERVISED_USER_CREATED_SWITCH_BUTTON)); 149 IDS_LEGACY_SUPERVISED_USER_CREATED_SWITCH_BUTTON));
149 } 150 }
150 151
151 void SigninCreateProfileHandler::RegisterMessages() { 152 void SigninCreateProfileHandler::RegisterMessages() {
152 #if defined(ENABLE_SUPERVISED_USERS) 153 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
153 // Cancellation is only supported for supervised users. 154 // Cancellation is only supported for supervised users.
154 web_ui()->RegisterMessageCallback( 155 web_ui()->RegisterMessageCallback(
155 "cancelCreateProfile", 156 "cancelCreateProfile",
156 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, 157 base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation,
157 base::Unretained(this))); 158 base::Unretained(this)));
158 159
159 web_ui()->RegisterMessageCallback( 160 web_ui()->RegisterMessageCallback(
160 "switchToProfile", 161 "switchToProfile",
161 base::Bind(&SigninCreateProfileHandler::SwitchToProfile, 162 base::Bind(&SigninCreateProfileHandler::SwitchToProfile,
162 base::Unretained(this))); 163 base::Unretained(this)));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) { 246 if (args->GetString(0, &name) && args->GetString(1, &icon_url)) {
246 DCHECK(base::IsStringASCII(icon_url)); 247 DCHECK(base::IsStringASCII(icon_url));
247 base::TrimWhitespace(name, base::TRIM_ALL, &name); 248 base::TrimWhitespace(name, base::TRIM_ALL, &name);
248 CHECK(!name.empty()); 249 CHECK(!name.empty());
249 #ifndef NDEBUG 250 #ifndef NDEBUG
250 size_t icon_index; 251 size_t icon_index;
251 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)); 252 DCHECK(profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index));
252 #endif 253 #endif
253 args->GetBoolean(2, &create_shortcut); 254 args->GetBoolean(2, &create_shortcut);
254 } 255 }
255 #if defined(ENABLE_SUPERVISED_USERS) 256 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
256 std::string supervised_user_id; 257 std::string supervised_user_id;
257 base::FilePath custodian_profile_path; 258 base::FilePath custodian_profile_path;
258 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, 259 if (GetSupervisedCreateProfileArgs(args, &supervised_user_id,
259 &custodian_profile_path)) { 260 &custodian_profile_path)) {
260 // Load custodian profile. 261 // Load custodian profile.
261 g_browser_process->profile_manager()->CreateProfileAsync( 262 g_browser_process->profile_manager()->CreateProfileAsync(
262 custodian_profile_path, 263 custodian_profile_path,
263 base::Bind(&SigninCreateProfileHandler::LoadCustodianProfileCallback, 264 base::Bind(&SigninCreateProfileHandler::LoadCustodianProfileCallback,
264 weak_ptr_factory_.GetWeakPtr(), name, icon_url, 265 weak_ptr_factory_.GetWeakPtr(), name, icon_url,
265 create_shortcut, supervised_user_id), 266 create_shortcut, supervised_user_id),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 bool create_shortcut, 329 bool create_shortcut,
329 const std::string& supervised_user_id, 330 const std::string& supervised_user_id,
330 Profile* custodian_profile, 331 Profile* custodian_profile,
331 Profile* profile) { 332 Profile* profile) {
332 switch (profile_creation_type_) { 333 switch (profile_creation_type_) {
333 case NON_SUPERVISED_PROFILE_CREATION: { 334 case NON_SUPERVISED_PROFILE_CREATION: {
334 DCHECK(supervised_user_id.empty()); 335 DCHECK(supervised_user_id.empty());
335 CreateShortcutAndShowSuccess(create_shortcut, nullptr, profile); 336 CreateShortcutAndShowSuccess(create_shortcut, nullptr, profile);
336 break; 337 break;
337 } 338 }
338 #if defined(ENABLE_SUPERVISED_USERS) 339 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
339 case SUPERVISED_PROFILE_CREATION: 340 case SUPERVISED_PROFILE_CREATION:
340 case SUPERVISED_PROFILE_IMPORT: 341 case SUPERVISED_PROFILE_IMPORT:
341 RegisterSupervisedUser(create_shortcut, supervised_user_id, 342 RegisterSupervisedUser(create_shortcut, supervised_user_id,
342 custodian_profile, profile); 343 custodian_profile, profile);
343 break; 344 break;
344 #endif 345 #endif
345 case NO_CREATION_IN_PROGRESS: 346 case NO_CREATION_IN_PROGRESS:
346 NOTREACHED(); 347 NOTREACHED();
347 break; 348 break;
348 } 349 }
(...skipping 14 matching lines...) Expand all
363 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value()); 364 DCHECK_EQ(profile_path_being_created_.value(), profile->GetPath().value());
364 profile_path_being_created_.clear(); 365 profile_path_being_created_.clear();
365 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); 366 DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
366 base::DictionaryValue dict; 367 base::DictionaryValue dict;
367 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); 368 dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName));
368 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); 369 dict.Set("filePath", base::CreateFilePathValue(profile->GetPath()));
369 370
370 bool is_force_signin_enabled = signin::IsForceSigninEnabled(); 371 bool is_force_signin_enabled = signin::IsForceSigninEnabled();
371 bool open_new_window = !is_force_signin_enabled; 372 bool open_new_window = !is_force_signin_enabled;
372 373
373 #if defined(ENABLE_SUPERVISED_USERS) 374 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
374 // If the new profile is a supervised user, instead of opening a new window 375 // If the new profile is a supervised user, instead of opening a new window
375 // right away, a confirmation page will be shown by JS from the creation 376 // right away, a confirmation page will be shown by JS from the creation
376 // dialog. If we are importing an existing supervised profile or creating a 377 // dialog. If we are importing an existing supervised profile or creating a
377 // new non-supervised user profile we don't show any confirmation, so open 378 // new non-supervised user profile we don't show any confirmation, so open
378 // the new window now. 379 // the new window now.
379 380
380 open_new_window = 381 open_new_window =
381 open_new_window && profile_creation_type_ != SUPERVISED_PROFILE_CREATION; 382 open_new_window && profile_creation_type_ != SUPERVISED_PROFILE_CREATION;
382 383
383 dict.SetBoolean("showConfirmation", 384 dict.SetBoolean("showConfirmation",
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, 450 UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status,
450 Profile::MAX_CREATE_STATUS); 451 Profile::MAX_CREATE_STATUS);
451 UMA_HISTOGRAM_MEDIUM_TIMES( 452 UMA_HISTOGRAM_MEDIUM_TIMES(
452 "Profile.CreateTimeNoTimeout", 453 "Profile.CreateTimeNoTimeout",
453 base::TimeTicks::Now() - profile_creation_start_time_); 454 base::TimeTicks::Now() - profile_creation_start_time_);
454 } 455 }
455 456
456 base::string16 SigninCreateProfileHandler::GetProfileCreationErrorMessageLocal() 457 base::string16 SigninCreateProfileHandler::GetProfileCreationErrorMessageLocal()
457 const { 458 const {
458 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; 459 int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR;
459 #if defined(ENABLE_SUPERVISED_USERS) 460 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
460 // Local errors can occur during supervised profile import. 461 // Local errors can occur during supervised profile import.
461 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT) 462 if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT)
462 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR; 463 message_id = IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR;
463 #endif 464 #endif
464 return l10n_util::GetStringUTF16(message_id); 465 return l10n_util::GetStringUTF16(message_id);
465 } 466 }
466 467
467 void SigninCreateProfileHandler::Observe( 468 void SigninCreateProfileHandler::Observe(
468 int type, 469 int type,
469 const content::NotificationSource& source, 470 const content::NotificationSource& source,
(...skipping 26 matching lines...) Expand all
496 switch (status) { 497 switch (status) {
497 case PROFILE_CREATION_SUCCESS: 498 case PROFILE_CREATION_SUCCESS:
498 return base::StringValue("create-profile-success"); 499 return base::StringValue("create-profile-success");
499 case PROFILE_CREATION_ERROR: 500 case PROFILE_CREATION_ERROR:
500 return base::StringValue("create-profile-error"); 501 return base::StringValue("create-profile-error");
501 } 502 }
502 NOTREACHED(); 503 NOTREACHED();
503 return base::StringValue(std::string()); 504 return base::StringValue(std::string());
504 } 505 }
505 506
506 #if defined(ENABLE_SUPERVISED_USERS) 507 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
507 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() 508 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote()
508 const { 509 const {
509 return l10n_util::GetStringUTF16( 510 return l10n_util::GetStringUTF16(
510 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT 511 profile_creation_type_ == SUPERVISED_PROFILE_IMPORT
511 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR 512 ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR
512 : IDS_PROFILES_CREATE_REMOTE_ERROR); 513 : IDS_PROFILES_CREATE_REMOTE_ERROR);
513 } 514 }
514 515
515 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin() 516 base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin()
516 const { 517 const {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 803
803 profiles::OpenBrowserWindowForProfile( 804 profiles::OpenBrowserWindowForProfile(
804 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback, 805 base::Bind(&SigninCreateProfileHandler::OnBrowserReadyCallback,
805 weak_ptr_factory_.GetWeakPtr()), 806 weak_ptr_factory_.GetWeakPtr()),
806 false, // Don't create a window if one already exists. 807 false, // Don't create a window if one already exists.
807 true, // Create a first run window. 808 true, // Create a first run window.
808 profile, 809 profile,
809 Profile::CREATE_STATUS_INITIALIZED); 810 Profile::CREATE_STATUS_INITIALIZED);
810 } 811 }
811 #endif 812 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698