| 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 a85a4f4830dfad2561fb3bbd2ec48a0773a5a419..11af51b991bf796e468f52d2902caee7a2efa1af 100644
|
| --- a/chrome/browser/ui/webui/options/create_profile_handler.cc
|
| +++ b/chrome/browser/ui/webui/signin/signin_create_profile_handler.cc
|
| @@ -1,16 +1,21 @@
|
| -// 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/prefs/pref_service.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"
|
| @@ -18,11 +23,15 @@
|
| #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/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"
|
|
|
| @@ -34,46 +43,113 @@
|
| #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(
|
| + "manageProfilesSupervisedSignedInLabel",
|
| + l10n_util::GetStringUTF16(
|
| + IDS_PROFILES_CREATE_SUPERVISED_MULTI_SIGNED_IN_LABEL));
|
| + 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));
|
| + 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)));
|
| }
|
|
|
| -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();
|
| + 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;
|
|
|
| @@ -101,28 +177,48 @@ 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,
|
| - helper::GetDesktopType(web_ui()),
|
| - supervised_user_id),
|
| + base::Bind(&SigninCreateProfileHandler::OnProfileCreated,
|
| + weak_ptr_factory_.GetWeakPtr(), create_shortcut,
|
| + options::helper::GetDesktopType(web_ui()), supervised_user_id,
|
| + supervisor_profile),
|
| supervised_user_id);
|
| }
|
|
|
| -void CreateProfileHandler::OnProfileCreated(
|
| +void SigninCreateProfileHandler::OnProfileCreated(
|
| bool create_shortcut,
|
| chrome::HostDesktopType desktop_type,
|
| const std::string& supervised_user_id,
|
| + Profile* supervisor_profile,
|
| Profile* profile,
|
| Profile::CreateStatus status) {
|
| if (status != Profile::CREATE_STATUS_CREATED)
|
| @@ -139,7 +235,8 @@ void CreateProfileHandler::OnProfileCreated(
|
| }
|
| case Profile::CREATE_STATUS_INITIALIZED: {
|
| HandleProfileCreationSuccess(create_shortcut, desktop_type,
|
| - supervised_user_id, profile);
|
| + supervised_user_id, supervisor_profile,
|
| + profile);
|
| break;
|
| }
|
| // User-initiated cancellation is handled in CancelProfileRegistration and
|
| @@ -155,10 +252,11 @@ void CreateProfileHandler::OnProfileCreated(
|
| }
|
| }
|
|
|
| -void CreateProfileHandler::HandleProfileCreationSuccess(
|
| +void SigninCreateProfileHandler::HandleProfileCreationSuccess(
|
| bool create_shortcut,
|
| chrome::HostDesktopType desktop_type,
|
| const std::string& supervised_user_id,
|
| + Profile* supervisor_profile,
|
| Profile* profile) {
|
| switch (profile_creation_type_) {
|
| case NON_SUPERVISED_PROFILE_CREATION: {
|
| @@ -169,8 +267,8 @@ void CreateProfileHandler::HandleProfileCreationSuccess(
|
| #if defined(ENABLE_SUPERVISED_USERS)
|
| case SUPERVISED_PROFILE_CREATION:
|
| case SUPERVISED_PROFILE_IMPORT:
|
| - RegisterSupervisedUser(create_shortcut, desktop_type,
|
| - supervised_user_id, profile);
|
| + RegisterSupervisedUser(create_shortcut, desktop_type, supervised_user_id,
|
| + supervisor_profile, profile);
|
| break;
|
| #endif
|
| case NO_CREATION_IN_PROGRESS:
|
| @@ -179,7 +277,7 @@ void CreateProfileHandler::HandleProfileCreationSuccess(
|
| }
|
| }
|
|
|
| -void CreateProfileHandler::CreateShortcutAndShowSuccess(
|
| +void SigninCreateProfileHandler::CreateShortcutAndShowSuccess(
|
| bool create_shortcut,
|
| chrome::HostDesktopType desktop_type,
|
| Profile* profile) {
|
| @@ -195,13 +293,11 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
|
| 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(
|
| @@ -221,14 +317,13 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
|
| 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(desktop_type,
|
| - profile,
|
| - Profile::CREATE_STATUS_INITIALIZED);
|
| + options::helper::OpenNewWindowForProfile(
|
| + desktop_type, 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_);
|
| @@ -239,20 +334,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)
|
| @@ -264,24 +358,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)
|
| @@ -297,9 +391,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;
|
| }
|
| @@ -309,45 +403,119 @@ 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);
|
| + DCHECK(args->GetBoolean(3, &supervised_user));
|
| + DCHECK(args->GetString(4, supervised_user_id));
|
| + if (supervised_user) {
|
| + const base::Value* path_value;
|
| + DCHECK(args->Get(5, &path_value));
|
| + DCHECK(base::GetValueAsFilePath(*path_value, supervisor_profile_path));
|
| }
|
| + return supervised_user && !supervisor_profile_path->empty();
|
| +}
|
|
|
| - 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);
|
| }
|
| @@ -355,7 +523,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;
|
|
|
| @@ -377,16 +546,17 @@ 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,
|
| chrome::HostDesktopType desktop_type,
|
| const std::string& supervised_user_id,
|
| + Profile* supervisor_profile,
|
| Profile* new_profile) {
|
| DCHECK_EQ(profile_path_being_created_.value(),
|
| new_profile->GetPath().value());
|
| @@ -396,19 +566,16 @@ 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,
|
| - desktop_type,
|
| + base::Bind(&SigninCreateProfileHandler::OnSupervisedUserRegistered,
|
| + weak_ptr_factory_.GetWeakPtr(), create_shortcut, desktop_type,
|
| new_profile));
|
| }
|
|
|
| -void CreateProfileHandler::OnSupervisedUserRegistered(
|
| +void SigninCreateProfileHandler::OnSupervisedUserRegistered(
|
| bool create_shortcut,
|
| chrome::HostDesktopType desktop_type,
|
| Profile* profile,
|
| @@ -425,62 +592,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.
|
| - const ProfileInfoCache& cache =
|
| - g_browser_process->profile_manager()->GetProfileInfoCache();
|
| - for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
|
| - if (existing_supervised_user_id ==
|
| - cache.GetSupervisedUserIdOfProfileAtIndex(i))
|
| - return false;
|
| - }
|
| - return true;
|
| -}
|
| #endif
|
| -
|
| -} // namespace options
|
|
|