Index: chrome/browser/ui/webui/signin/signin_create_profile_handler.cc |
diff --git a/chrome/browser/ui/webui/options/create_profile_handler.cc b/chrome/browser/ui/webui/signin/signin_create_profile_handler.cc |
similarity index 47% |
copy from chrome/browser/ui/webui/options/create_profile_handler.cc |
copy to chrome/browser/ui/webui/signin/signin_create_profile_handler.cc |
index 6036836a234c394da1362e7a6a68b2525ecbb9ea..1eb0a2985d6d2576af5c6e0c0d8907e5c4db3e7a 100644 |
--- a/chrome/browser/ui/webui/options/create_profile_handler.cc |
+++ b/chrome/browser/ui/webui/signin/signin_create_profile_handler.cc |
@@ -1,32 +1,37 @@ |
-// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/webui/options/create_profile_handler.h" |
+#include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h" |
#include <stddef.h> |
- |
+#include <string> |
#include <vector> |
#include "base/bind.h" |
#include "base/files/file_path.h" |
#include "base/metrics/histogram.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/task_runner_util.h" |
+#include "base/threading/thread_restrictions.h" |
#include "base/value_conversions.h" |
#include "base/values.h" |
#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/profiles/profile_attributes_entry.h" |
-#include "chrome/browser/profiles/profile_attributes_storage.h" |
#include "chrome/browser/profiles/profile_avatar_icon_util.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/profiles/profile_metrics.h" |
#include "chrome/browser/profiles/profiles_state.h" |
+#include "chrome/browser/signin/signin_manager_factory.h" |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
#include "chrome/common/pref_names.h" |
+#include "chrome/common/url_constants.h" |
#include "chrome/grit/generated_resources.h" |
#include "components/browser_sync/browser/profile_sync_service.h" |
#include "components/prefs/pref_service.h" |
+#include "components/strings/grit/components_strings.h" |
+#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/web_ui.h" |
#include "ui/base/l10n/l10n_util.h" |
@@ -38,46 +43,109 @@ |
#include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
#endif |
-namespace options { |
- |
-CreateProfileHandler::CreateProfileHandler() |
+SigninCreateProfileHandler::SigninCreateProfileHandler() |
: profile_creation_type_(NO_CREATION_IN_PROGRESS), |
- weak_ptr_factory_(this) { |
-} |
+ weak_ptr_factory_(this) {} |
-CreateProfileHandler::~CreateProfileHandler() { |
+SigninCreateProfileHandler::~SigninCreateProfileHandler() { |
#if defined(ENABLE_SUPERVISED_USERS) |
// Cancellation is only supported for supervised users. |
CancelProfileRegistration(false); |
#endif |
} |
-void CreateProfileHandler::GetLocalizedValues( |
+void SigninCreateProfileHandler::GetLocalizedValues( |
base::DictionaryValue* localized_strings) { |
+ localized_strings->SetString( |
+ "manageProfilesSupervisedNotSignedIn", |
+ l10n_util::GetStringUTF16( |
+ IDS_PROFILES_CREATE_SUPERVISED_NOT_SIGNED_IN_HTML)); |
+ localized_strings->SetString("createProfileConfirm", |
+ l10n_util::GetStringUTF16(IDS_SAVE)); |
+ localized_strings->SetString("learnMore", |
+ l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
+ localized_strings->SetString( |
+ "createProfileTitle", |
+ l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_TITLE)); |
+ |
+ localized_strings->SetString( |
+ "supervisedUserLearnMoreTitle", |
+ l10n_util::GetStringUTF16(IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TITLE)); |
Dan Beam
2016/02/25 01:04:40
why are you adding another use of a _LEGACY_ strin
Moe
2016/02/25 16:03:02
I'm reusing the strings that haven't changed in th
|
+ localized_strings->SetString( |
+ "supervisedUserLearnMoreDone", |
+ l10n_util::GetStringUTF16( |
+ IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_DONE_BUTTON)); |
+ localized_strings->SetString( |
+ "supervisedUserLearnMoreText", |
+ l10n_util::GetStringFUTF16( |
+ IDS_LEGACY_SUPERVISED_USER_LEARN_MORE_TEXT, |
+ base::ASCIIToUTF16( |
+ chrome::kLegacySupervisedUserManagementDisplayURL))); |
Dan Beam
2016/02/25 01:04:40
what does legacy mean here as well?
Moe
2016/02/25 16:03:03
This is another existing string. I don't know why
|
} |
-void CreateProfileHandler::RegisterMessages() { |
+void SigninCreateProfileHandler::RegisterMessages() { |
#if defined(ENABLE_SUPERVISED_USERS) |
// Cancellation is only supported for supervised users. |
web_ui()->RegisterMessageCallback( |
"cancelCreateProfile", |
- base::Bind(&CreateProfileHandler::HandleCancelProfileCreation, |
+ base::Bind(&SigninCreateProfileHandler::HandleCancelProfileCreation, |
base::Unretained(this))); |
#endif |
web_ui()->RegisterMessageCallback( |
- "createProfile", |
- base::Bind(&CreateProfileHandler::CreateProfile, |
+ "createProfile", base::Bind(&SigninCreateProfileHandler::CreateProfile, |
+ base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ "requestDefaultProfileIcons", |
+ base::Bind(&SigninCreateProfileHandler::RequestDefaultProfileIcons, |
+ base::Unretained(this))); |
+ |
+ web_ui()->RegisterMessageCallback( |
+ "requestSignedInProfiles", |
+ base::Bind(&SigninCreateProfileHandler::RequestSignedInProfiles, |
base::Unretained(this))); |
} |
-void CreateProfileHandler::CreateProfile(const base::ListValue* args) { |
-#if defined(ENABLE_SUPERVISED_USERS) |
- // This handler could have been called for a supervised user, for example |
- // because the user fiddled with the web inspector. Silently return. |
- if (Profile::FromWebUI(web_ui())->IsSupervised()) |
- return; |
-#endif |
+void SigninCreateProfileHandler::RequestDefaultProfileIcons( |
+ const base::ListValue* args) { |
+ base::ListValue image_url_list; |
+ |
+ // Add the default avatar icons. |
+ size_t placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex(); |
+ for (size_t i = 0; i < profiles::GetDefaultAvatarIconCount() && |
+ i != placeholder_avatar_index; |
+ i++) { |
+ std::string url = profiles::GetDefaultAvatarIconUrl(i); |
+ image_url_list.AppendString(url); |
+ } |
+ web_ui()->CallJavascriptFunction("signin.ProfileApi.updateAvailableIcons", |
+ image_url_list); |
+} |
+ |
+void SigninCreateProfileHandler::RequestSignedInProfiles( |
+ const base::ListValue* args) { |
+ base::ListValue user_info_list; |
+ ProfileInfoCache& cache = |
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ std::vector<ProfileAttributesEntry*> entries = |
+ cache.GetAllProfilesAttributes(); |
+ for (auto& entry : entries) { |
+ base::string16 username = entry->GetUserName(); |
+ if (username.empty()) |
+ continue; |
+ base::string16 profile_path = entry->GetPath().AsUTF16Unsafe(); |
+ base::DictionaryValue* user_info = new base::DictionaryValue(); |
Dan Beam
2016/02/25 01:04:40
nit: can you use scoped_ptr<base::DictionaryValue>
Moe
2016/02/25 16:03:02
Done.
|
+ user_info->SetString("username", username); |
+ user_info->SetString("profilePath", profile_path); |
+ |
+ user_info_list.Append(user_info); |
+ } |
+ web_ui()->CallJavascriptFunction("signin.ProfileApi.updateSignedInUsers", |
+ user_info_list); |
+} |
+ |
+void SigninCreateProfileHandler::CreateProfile(const base::ListValue* args) { |
if (!profiles::IsMultipleProfilesEnabled()) |
return; |
@@ -105,24 +173,46 @@ void CreateProfileHandler::CreateProfile(const base::ListValue* args) { |
#endif |
args->GetBoolean(2, &create_shortcut); |
} |
- std::string supervised_user_id; |
#if defined(ENABLE_SUPERVISED_USERS) |
- if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id)) |
- return; |
+ std::string supervised_user_id; |
+ base::FilePath supervisor_profile_path; |
+ if (GetSupervisedCreateProfileArgs(args, &supervised_user_id, |
+ &supervisor_profile_path)) { |
+ // Load supervisor profile. |
+ g_browser_process->profile_manager()->CreateProfileAsync( |
+ supervisor_profile_path, |
+ base::Bind(&SigninCreateProfileHandler::LoadSupervisorProfileCallback, |
+ weak_ptr_factory_.GetWeakPtr(), name, icon_url, |
+ create_shortcut, supervised_user_id), |
+ base::string16(), std::string(), std::string()); |
+ } else { |
+ DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
+ } |
+#else |
+ DoCreateProfile(name, icon_url, create_shortcut, std::string(), nullptr); |
#endif |
+} |
+void SigninCreateProfileHandler::DoCreateProfile( |
+ const base::string16& name, |
+ const std::string& icon_url, |
+ bool create_shortcut, |
+ const std::string& supervised_user_id, |
+ Profile* supervisor_profile) { |
ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG); |
profile_path_being_created_ = ProfileManager::CreateMultiProfileAsync( |
- name, icon_url, base::Bind(&CreateProfileHandler::OnProfileCreated, |
- weak_ptr_factory_.GetWeakPtr(), |
- create_shortcut, supervised_user_id), |
+ name, icon_url, |
+ base::Bind(&SigninCreateProfileHandler::OnProfileCreated, |
+ weak_ptr_factory_.GetWeakPtr(), create_shortcut, |
+ supervised_user_id, supervisor_profile), |
supervised_user_id); |
} |
-void CreateProfileHandler::OnProfileCreated( |
+void SigninCreateProfileHandler::OnProfileCreated( |
bool create_shortcut, |
const std::string& supervised_user_id, |
+ Profile* supervisor_profile, |
Profile* profile, |
Profile::CreateStatus status) { |
if (status != Profile::CREATE_STATUS_CREATED) |
@@ -139,7 +229,7 @@ void CreateProfileHandler::OnProfileCreated( |
} |
case Profile::CREATE_STATUS_INITIALIZED: { |
HandleProfileCreationSuccess(create_shortcut, supervised_user_id, |
- profile); |
+ supervisor_profile, profile); |
break; |
} |
// User-initiated cancellation is handled in CancelProfileRegistration and |
@@ -155,9 +245,10 @@ void CreateProfileHandler::OnProfileCreated( |
} |
} |
-void CreateProfileHandler::HandleProfileCreationSuccess( |
+void SigninCreateProfileHandler::HandleProfileCreationSuccess( |
bool create_shortcut, |
const std::string& supervised_user_id, |
+ Profile* supervisor_profile, |
Profile* profile) { |
switch (profile_creation_type_) { |
case NON_SUPERVISED_PROFILE_CREATION: { |
@@ -168,7 +259,8 @@ void CreateProfileHandler::HandleProfileCreationSuccess( |
#if defined(ENABLE_SUPERVISED_USERS) |
case SUPERVISED_PROFILE_CREATION: |
case SUPERVISED_PROFILE_IMPORT: |
- RegisterSupervisedUser(create_shortcut, supervised_user_id, profile); |
+ RegisterSupervisedUser(create_shortcut, supervised_user_id, |
+ supervisor_profile, profile); |
break; |
#endif |
case NO_CREATION_IN_PROGRESS: |
@@ -177,8 +269,9 @@ void CreateProfileHandler::HandleProfileCreationSuccess( |
} |
} |
-void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, |
- Profile* profile) { |
+void SigninCreateProfileHandler::CreateShortcutAndShowSuccess( |
+ bool create_shortcut, |
+ Profile* profile) { |
if (create_shortcut) { |
ProfileShortcutManager* shortcut_manager = |
g_browser_process->profile_manager()->profile_shortcut_manager(); |
@@ -191,13 +284,11 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, |
profile_path_being_created_.clear(); |
DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
base::DictionaryValue dict; |
- dict.SetString("name", |
- profile->GetPrefs()->GetString(prefs::kProfileName)); |
+ dict.SetString("name", profile->GetPrefs()->GetString(prefs::kProfileName)); |
dict.Set("filePath", base::CreateFilePathValue(profile->GetPath())); |
#if defined(ENABLE_SUPERVISED_USERS) |
- bool is_supervised = |
- profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
+ bool is_supervised = profile_creation_type_ == SUPERVISED_PROFILE_CREATION || |
+ profile_creation_type_ == SUPERVISED_PROFILE_IMPORT; |
dict.SetBoolean("isSupervised", is_supervised); |
#endif |
web_ui()->CallJavascriptFunction( |
@@ -217,13 +308,13 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(bool create_shortcut, |
if (should_open_new_window) { |
// Opening the new window must be the last action, after all callbacks |
// have been run, to give them a chance to initialize the profile. |
- helper::OpenNewWindowForProfile(profile, |
- Profile::CREATE_STATUS_INITIALIZED); |
+ options::helper::OpenNewWindowForProfile( |
Dan Beam
2016/02/25 01:04:40
can you move this code out of options? seems odd
Moe
2016/02/25 16:03:03
Done.
|
+ profile, Profile::CREATE_STATUS_INITIALIZED); |
} |
profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
} |
-void CreateProfileHandler::ShowProfileCreationError( |
+void SigninCreateProfileHandler::ShowProfileCreationError( |
Profile* profile, |
const base::string16& error) { |
DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
@@ -234,20 +325,19 @@ void CreateProfileHandler::ShowProfileCreationError( |
base::StringValue(error)); |
// The ProfileManager calls us back with a NULL profile in some cases. |
if (profile) |
- helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); |
+ options::helper::DeleteProfileAtPath(profile->GetPath(), web_ui()); |
} |
-void CreateProfileHandler::RecordProfileCreationMetrics( |
+void SigninCreateProfileHandler::RecordProfileCreationMetrics( |
Profile::CreateStatus status) { |
- UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", |
- status, |
+ UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult", status, |
Profile::MAX_CREATE_STATUS); |
UMA_HISTOGRAM_MEDIUM_TIMES( |
"Profile.CreateTimeNoTimeout", |
base::TimeTicks::Now() - profile_creation_start_time_); |
} |
-base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal() |
+base::string16 SigninCreateProfileHandler::GetProfileCreationErrorMessageLocal() |
const { |
int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR; |
#if defined(ENABLE_SUPERVISED_USERS) |
@@ -259,24 +349,24 @@ base::string16 CreateProfileHandler::GetProfileCreationErrorMessageLocal() |
} |
#if defined(ENABLE_SUPERVISED_USERS) |
-base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote() |
+base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageRemote() |
const { |
return l10n_util::GetStringUTF16( |
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? |
- IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR : |
- IDS_PROFILES_CREATE_REMOTE_ERROR); |
+ profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
+ ? IDS_LEGACY_SUPERVISED_USER_IMPORT_REMOTE_ERROR |
+ : IDS_PROFILES_CREATE_REMOTE_ERROR); |
} |
-base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin() |
+base::string16 SigninCreateProfileHandler::GetProfileCreateErrorMessageSignin() |
const { |
return l10n_util::GetStringUTF16( |
- profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ? |
- IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR : |
- IDS_PROFILES_CREATE_SIGN_IN_ERROR); |
+ profile_creation_type_ == SUPERVISED_PROFILE_IMPORT |
+ ? IDS_LEGACY_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR |
+ : IDS_PROFILES_CREATE_SIGN_IN_ERROR); |
} |
#endif |
-std::string CreateProfileHandler::GetJavascriptMethodName( |
+std::string SigninCreateProfileHandler::GetJavascriptMethodName( |
ProfileCreationStatus status) const { |
switch (profile_creation_type_) { |
#if defined(ENABLE_SUPERVISED_USERS) |
@@ -292,9 +382,9 @@ std::string CreateProfileHandler::GetJavascriptMethodName( |
default: |
switch (status) { |
case PROFILE_CREATION_SUCCESS: |
- return "BrowserOptions.showCreateProfileSuccess"; |
+ return "signin.ProfileApi.onCreateProfileSuccess"; |
case PROFILE_CREATION_ERROR: |
- return "BrowserOptions.showCreateProfileError"; |
+ return "signin.ProfileApi.onCreateProfileError"; |
} |
break; |
} |
@@ -304,45 +394,123 @@ std::string CreateProfileHandler::GetJavascriptMethodName( |
} |
#if defined(ENABLE_SUPERVISED_USERS) |
-bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs( |
- const base::ListValue* args, std::string* supervised_user_id) { |
+bool SigninCreateProfileHandler::GetSupervisedCreateProfileArgs( |
+ const base::ListValue* args, |
+ std::string* supervised_user_id, |
+ base::FilePath* supervisor_profile_path) { |
bool supervised_user = false; |
- if (args->GetSize() >= 5) { |
- bool success = args->GetBoolean(3, &supervised_user); |
- DCHECK(success); |
- |
- success = args->GetString(4, supervised_user_id); |
- DCHECK(success); |
+ bool success = args->GetBoolean(3, &supervised_user); |
+ DCHECK(success); |
+ success = args->GetString(4, supervised_user_id); |
Dan Beam
2016/02/25 01:04:40
should this GetString() for supervised_user_id be
Moe
2016/02/25 16:03:02
Acknowledged.
|
+ DCHECK(success); |
+ if (supervised_user) { |
+ const base::Value* path_value; |
+ success = args->Get(5, &path_value); |
+ DCHECK(success); |
+ success = base::GetValueAsFilePath(*path_value, supervisor_profile_path); |
+ DCHECK(success); |
} |
+ return supervised_user && !supervisor_profile_path->empty(); |
Dan Beam
2016/02/25 01:04:40
bool supervised_user = false;
bool success = args-
Moe
2016/02/25 16:03:02
Done.
|
+} |
- if (supervised_user) { |
- if (!IsValidExistingSupervisedUserId(*supervised_user_id)) |
- return false; |
- |
- profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
- if (supervised_user_id->empty()) { |
- profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
- *supervised_user_id = |
- SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
- |
- // If sync is not yet fully initialized, the creation may take extra time, |
- // so show a message. Import doesn't wait for an acknowledgment, so it |
- // won't have the same potential delay. |
- ProfileSyncService* sync_service = |
- ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
- Profile::FromWebUI(web_ui())); |
- ProfileSyncService::SyncStatusSummary status = |
- sync_service->QuerySyncStatusSummary(); |
- if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
- ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
- IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); |
+void SigninCreateProfileHandler::LoadSupervisorProfileCallback( |
+ const base::string16& name, |
+ const std::string& icon_url, |
+ bool create_shortcut, |
+ const std::string& supervised_user_id, |
+ Profile* supervisor_profile, |
+ Profile::CreateStatus status) { |
+ // This method gets called once before with Profile::CREATE_STATUS_CREATED. |
+ switch (status) { |
+ case Profile::CREATE_STATUS_LOCAL_FAIL: { |
+ // TODO(mahmadi): see if a better error message is required here. |
+ ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
+ break; |
+ } |
+ case Profile::CREATE_STATUS_CREATED: { |
+ // Ignore the intermediate status. |
+ break; |
+ } |
+ case Profile::CREATE_STATUS_INITIALIZED: { |
+ // We are only interested in Profile::CREATE_STATUS_INITIALIZED when |
+ // everything is ready. |
+ // TODO(mahmadi): display proper error message to the user. |
+ PrefService* prefs = supervisor_profile->GetPrefs(); |
+ if (!prefs->GetBoolean(prefs::kSupervisedUserCreationAllowed)) |
+ return; |
+ |
+ if (!supervised_user_id.empty()) { |
+ profile_creation_type_ = SUPERVISED_PROFILE_IMPORT; |
+ |
+ SupervisedUserSyncService* supervised_user_sync_service = |
+ SupervisedUserSyncServiceFactory::GetForProfile(supervisor_profile); |
+ if (supervised_user_sync_service) { |
+ supervised_user_sync_service->GetSupervisedUsersAsync(base::Bind( |
+ &SigninCreateProfileHandler::DoCreateProfileIfPossible, |
+ weak_ptr_factory_.GetWeakPtr(), name, icon_url, create_shortcut, |
+ supervised_user_id, supervisor_profile)); |
+ } |
+ } else { |
+ profile_creation_type_ = SUPERVISED_PROFILE_CREATION; |
+ std::string new_supervised_user_id = |
+ SupervisedUserRegistrationUtility::GenerateNewSupervisedUserId(); |
+ |
+ // If sync is not yet fully initialized, the creation may take extra |
+ // time, so show a message. Import doesn't wait for an acknowledgment, |
+ // so it won't have the same potential delay. |
+ ProfileSyncService* sync_service = |
+ ProfileSyncServiceFactory::GetInstance()->GetForProfile( |
+ supervisor_profile); |
+ ProfileSyncService::SyncStatusSummary status = |
+ sync_service->QuerySyncStatusSummary(); |
+ if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) { |
+ ShowProfileCreationWarning(l10n_util::GetStringUTF16( |
+ IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); |
+ } |
+ |
+ DoCreateProfile(name, icon_url, create_shortcut, new_supervised_user_id, |
+ supervisor_profile); |
} |
+ break; |
+ } |
+ case Profile::CREATE_STATUS_CANCELED: |
+ case Profile::CREATE_STATUS_REMOTE_FAIL: |
+ case Profile::MAX_CREATE_STATUS: { |
+ NOTREACHED(); |
+ break; |
} |
} |
- return true; |
} |
-void CreateProfileHandler::HandleCancelProfileCreation( |
+void SigninCreateProfileHandler::DoCreateProfileIfPossible( |
+ const base::string16& name, |
+ const std::string& icon_url, |
+ bool create_shortcut, |
+ const std::string& supervised_user_id, |
+ Profile* supervisor_profile, |
+ const base::DictionaryValue* dict) { |
+ DCHECK(dict); |
+ if (!dict->HasKey(supervised_user_id)) |
+ return; |
+ |
+ // Check if this supervised user already exists on this machine. |
+ ProfileInfoCache& cache = |
+ g_browser_process->profile_manager()->GetProfileInfoCache(); |
+ std::vector<ProfileAttributesEntry*> entries = |
+ cache.GetAllProfilesAttributes(); |
+ for (auto& entry : entries) { |
+ if (supervised_user_id == entry->GetSupervisedUserId()) { |
+ // TODO(mahmadi): see whether we need a more specific error message here. |
+ ShowProfileCreationError(nullptr, GetProfileCreationErrorMessageLocal()); |
+ return; |
+ } |
+ } |
+ |
+ DoCreateProfile(name, icon_url, create_shortcut, supervised_user_id, |
+ supervisor_profile); |
+} |
+ |
+void SigninCreateProfileHandler::HandleCancelProfileCreation( |
const base::ListValue* args) { |
CancelProfileRegistration(true); |
} |
@@ -350,7 +518,8 @@ void CreateProfileHandler::HandleCancelProfileCreation( |
// Non-supervised user creation cannot be canceled. (Creating a non-supervised |
// profile shouldn't take significant time, and it can easily be deleted |
// afterward.) |
-void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { |
+void SigninCreateProfileHandler::CancelProfileRegistration( |
+ bool user_initiated) { |
if (profile_path_being_created_.empty()) |
return; |
@@ -372,15 +541,16 @@ void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) { |
DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_); |
profile_creation_type_ = NO_CREATION_IN_PROGRESS; |
- // Cancelling registration means the callback passed into |
+ // Canceling registration means the callback passed into |
// RegisterAndInitSync() won't be called, so the cleanup must be done here. |
profile_path_being_created_.clear(); |
- helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
+ options::helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui()); |
} |
-void CreateProfileHandler::RegisterSupervisedUser( |
+void SigninCreateProfileHandler::RegisterSupervisedUser( |
bool create_shortcut, |
const std::string& supervised_user_id, |
+ Profile* supervisor_profile, |
Profile* new_profile) { |
DCHECK_EQ(profile_path_being_created_.value(), |
new_profile->GetPath().value()); |
@@ -390,18 +560,15 @@ void CreateProfileHandler::RegisterSupervisedUser( |
// Register the supervised user using the profile of the custodian. |
supervised_user_registration_utility_ = |
- SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui())); |
+ SupervisedUserRegistrationUtility::Create(supervisor_profile); |
supervised_user_service->RegisterAndInitSync( |
- supervised_user_registration_utility_.get(), |
- Profile::FromWebUI(web_ui()), |
+ supervised_user_registration_utility_.get(), supervisor_profile, |
supervised_user_id, |
- base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered, |
- weak_ptr_factory_.GetWeakPtr(), |
- create_shortcut, |
- new_profile)); |
+ base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered, |
+ weak_ptr_factory_.GetWeakPtr(), create_shortcut, new_profile)); |
} |
-void CreateProfileHandler::OnSupervisedUserRegistered( |
+void SigninCreateProfileHandler::OnSupervisedUserRegistered( |
bool create_shortcut, |
Profile* profile, |
const GoogleServiceAuthError& error) { |
@@ -417,62 +584,36 @@ void CreateProfileHandler::OnSupervisedUserRegistered( |
state == GoogleServiceAuthError::USER_NOT_SIGNED_UP || |
state == GoogleServiceAuthError::ACCOUNT_DELETED || |
state == GoogleServiceAuthError::ACCOUNT_DISABLED) { |
- error_msg = GetProfileCreationErrorMessageSignin(); |
+ error_msg = GetProfileCreateErrorMessageSignin(); |
} else { |
- error_msg = GetProfileCreationErrorMessageRemote(); |
+ error_msg = GetProfileCreateErrorMessageRemote(); |
} |
ShowProfileCreationError(profile, error_msg); |
} |
-void CreateProfileHandler::ShowProfileCreationWarning( |
+void SigninCreateProfileHandler::ShowProfileCreationWarning( |
const base::string16& warning) { |
DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_); |
- web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning", |
+ web_ui()->CallJavascriptFunction("signin.ProfileApi.onCreateProfileWarning", |
base::StringValue(warning)); |
} |
-void CreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
+void SigninCreateProfileHandler::RecordSupervisedProfileCreationMetrics( |
GoogleServiceAuthError::State error_state) { |
if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION) { |
UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileCreateError", |
- error_state, |
- GoogleServiceAuthError::NUM_STATES); |
+ error_state, GoogleServiceAuthError::NUM_STATES); |
UMA_HISTOGRAM_MEDIUM_TIMES( |
"Profile.SupervisedProfileTotalCreateTime", |
base::TimeTicks::Now() - profile_creation_start_time_); |
} else { |
DCHECK_EQ(SUPERVISED_PROFILE_IMPORT, profile_creation_type_); |
UMA_HISTOGRAM_ENUMERATION("Profile.SupervisedProfileImportError", |
- error_state, |
- GoogleServiceAuthError::NUM_STATES); |
+ error_state, GoogleServiceAuthError::NUM_STATES); |
UMA_HISTOGRAM_MEDIUM_TIMES( |
"Profile.SupervisedProfileTotalImportTime", |
base::TimeTicks::Now() - profile_creation_start_time_); |
} |
} |
-bool CreateProfileHandler::IsValidExistingSupervisedUserId( |
- const std::string& existing_supervised_user_id) const { |
- if (existing_supervised_user_id.empty()) |
- return true; |
- |
- Profile* profile = Profile::FromWebUI(web_ui()); |
- const base::DictionaryValue* dict = |
- SupervisedUserSyncServiceFactory::GetForProfile(profile)-> |
- GetSupervisedUsers(); |
- if (!dict->HasKey(existing_supervised_user_id)) |
- return false; |
- |
- // Check if this supervised user already exists on this machine. |
- std::vector<ProfileAttributesEntry*> entries = |
- g_browser_process->profile_manager()-> |
- GetProfileAttributesStorage().GetAllProfilesAttributes(); |
- for (const ProfileAttributesEntry* entry : entries) { |
- if (existing_supervised_user_id == entry->GetSupervisedUserId()) |
- return false; |
- } |
- return true; |
-} |
#endif |
- |
-} // namespace options |