Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / create_profile_handler.cc
index 8df557c..9c4a88d 100644 (file)
@@ -5,29 +5,32 @@
 #include "chrome/browser/ui/webui/options/create_profile_handler.h"
 
 #include "base/bind.h"
-#include "base/command_line.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/value_conversions.h"
 #include "base/values.h"
 #include "chrome/browser/browser_process.h"
-#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
-#include "chrome/browser/managed_mode/managed_user_service.h"
-#include "chrome/browser/managed_mode/managed_user_service_factory.h"
-#include "chrome/browser/managed_mode/managed_user_sync_service.h"
-#include "chrome/browser/managed_mode/managed_user_sync_service_factory.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/sync/profile_sync_service.h"
 #include "chrome/browser/sync/profile_sync_service_factory.h"
 #include "chrome/browser/ui/webui/options/options_handlers_helper.h"
-#include "chrome/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
-#include "grit/generated_resources.h"
+#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/web_ui.h"
 #include "ui/base/l10n/l10n_util.h"
 
+#if defined(ENABLE_MANAGED_USERS)
+#include "chrome/browser/supervised_user/supervised_user_registration_utility.h"
+#include "chrome/browser/supervised_user/supervised_user_service.h"
+#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
+#include "chrome/browser/supervised_user/supervised_user_sync_service.h"
+#include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h"
+#endif
+
 namespace options {
 
 CreateProfileHandler::CreateProfileHandler()
@@ -36,7 +39,10 @@ CreateProfileHandler::CreateProfileHandler()
 }
 
 CreateProfileHandler::~CreateProfileHandler() {
+#if defined(ENABLE_MANAGED_USERS)
+  // Cancellation is only supported for supervised users.
   CancelProfileRegistration(false);
+#endif
 }
 
 void CreateProfileHandler::GetLocalizedValues(
@@ -44,10 +50,13 @@ void CreateProfileHandler::GetLocalizedValues(
 }
 
 void CreateProfileHandler::RegisterMessages() {
+#if defined(ENABLE_MANAGED_USERS)
+  // Cancellation is only supported for supervised users.
   web_ui()->RegisterMessageCallback(
       "cancelCreateProfile",
       base::Bind(&CreateProfileHandler::HandleCancelProfileCreation,
                  base::Unretained(this)));
+#endif
   web_ui()->RegisterMessageCallback(
       "createProfile",
       base::Bind(&CreateProfileHandler::CreateProfile,
@@ -55,11 +64,12 @@ void CreateProfileHandler::RegisterMessages() {
 }
 
 void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
-  // This handler could have been called in managed mode, for example because
-  // the user fiddled with the web inspector. Silently return in this case.
-  Profile* current_profile = Profile::FromWebUI(web_ui());
-  if (current_profile->IsManaged())
+#if defined(ENABLE_MANAGED_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
 
   if (!profiles::IsMultipleProfilesEnabled())
     return;
@@ -77,42 +87,17 @@ void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
 
   base::string16 name;
   base::string16 icon;
-  std::string managed_user_id;
   bool create_shortcut = false;
-  bool managed_user = false;
   if (args->GetString(0, &name) && args->GetString(1, &icon)) {
-    if (args->GetBoolean(2, &create_shortcut)) {
-      bool success = args->GetBoolean(3, &managed_user);
-      DCHECK(success);
-      success = args->GetString(4, &managed_user_id);
-      DCHECK(success);
-    }
-  }
-
-  if (managed_user) {
-    if (!IsValidExistingManagedUserId(managed_user_id))
-      return;
-
-    profile_creation_type_ = SUPERVISED_PROFILE_IMPORT;
-    if (managed_user_id.empty()) {
-      profile_creation_type_ = SUPERVISED_PROFILE_CREATION;
-      managed_user_id =
-          ManagedUserRegistrationUtility::GenerateNewManagedUserId();
-
-      // If sync is not yet fully initialized, the creation may take extra time,
-      // so show a message. Import doesn't wait for an acknowledgement, so it
-      // won't have the same potential delay.
-      ProfileSyncService* sync_service =
-          ProfileSyncServiceFactory::GetInstance()->GetForProfile(
-              current_profile);
-      ProfileSyncService::SyncStatusSummary status =
-          sync_service->QuerySyncStatusSummary();
-      if (status == ProfileSyncService::DATATYPES_NOT_INITIALIZED) {
-        ShowProfileCreationWarning(l10n_util::GetStringUTF16(
-            IDS_PROFILES_CREATE_MANAGED_JUST_SIGNED_IN));
-      }
-    }
+    base::TrimWhitespace(name, base::TRIM_ALL, &name);
+    CHECK(!name.empty());
+    args->GetBoolean(2, &create_shortcut);
   }
+  std::string supervised_user_id;
+#if defined(ENABLE_MANAGED_USERS)
+  if (!ProcessSupervisedCreateProfileArgs(args, &supervised_user_id))
+    return;
+#endif
 
   ProfileMetrics::LogProfileAddNewUser(ProfileMetrics::ADD_NEW_USER_DIALOG);
 
@@ -122,14 +107,14 @@ void CreateProfileHandler::CreateProfile(const base::ListValue* args) {
                  weak_ptr_factory_.GetWeakPtr(),
                  create_shortcut,
                  helper::GetDesktopType(web_ui()),
-                 managed_user_id),
-      managed_user_id);
+                 supervised_user_id),
+      supervised_user_id);
 }
 
 void CreateProfileHandler::OnProfileCreated(
     bool create_shortcut,
     chrome::HostDesktopType desktop_type,
-    const std::string& managed_user_id,
+    const std::string& supervised_user_id,
     Profile* profile,
     Profile::CreateStatus status) {
   if (status != Profile::CREATE_STATUS_CREATED)
@@ -137,8 +122,7 @@ void CreateProfileHandler::OnProfileCreated(
 
   switch (status) {
     case Profile::CREATE_STATUS_LOCAL_FAIL: {
-      ShowProfileCreationError(profile,
-                               GetProfileCreationErrorMessage(LOCAL_ERROR));
+      ShowProfileCreationError(profile, GetProfileCreationErrorMessageLocal());
       break;
     }
     case Profile::CREATE_STATUS_CREATED: {
@@ -147,14 +131,14 @@ void CreateProfileHandler::OnProfileCreated(
     }
     case Profile::CREATE_STATUS_INITIALIZED: {
       HandleProfileCreationSuccess(create_shortcut, desktop_type,
-                                   managed_user_id, profile);
+                                   supervised_user_id, profile);
       break;
     }
     // User-initiated cancellation is handled in CancelProfileRegistration and
     // does not call this callback.
     case Profile::CREATE_STATUS_CANCELED:
-    // Managed user registration errors are handled in
-    // OnManagedUserRegistered().
+    // Supervised user registration errors are handled in
+    // OnSupervisedUserRegistered().
     case Profile::CREATE_STATUS_REMOTE_FAIL:
     case Profile::MAX_CREATE_STATUS: {
       NOTREACHED();
@@ -166,74 +150,27 @@ void CreateProfileHandler::OnProfileCreated(
 void CreateProfileHandler::HandleProfileCreationSuccess(
     bool create_shortcut,
     chrome::HostDesktopType desktop_type,
-    const std::string& managed_user_id,
+    const std::string& supervised_user_id,
     Profile* profile) {
   switch (profile_creation_type_) {
     case NON_SUPERVISED_PROFILE_CREATION: {
-      DCHECK(managed_user_id.empty());
+      DCHECK(supervised_user_id.empty());
       CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
       break;
     }
+#if defined(ENABLE_MANAGED_USERS)
     case SUPERVISED_PROFILE_CREATION:
     case SUPERVISED_PROFILE_IMPORT:
-      RegisterManagedUser(create_shortcut, desktop_type,
-                          managed_user_id, profile);
+      RegisterSupervisedUser(create_shortcut, desktop_type,
+                             supervised_user_id, profile);
       break;
+#endif
     case NO_CREATION_IN_PROGRESS:
       NOTREACHED();
       break;
   }
 }
 
-void CreateProfileHandler::RegisterManagedUser(
-    bool create_shortcut,
-    chrome::HostDesktopType desktop_type,
-    const std::string& managed_user_id,
-    Profile* new_profile) {
-  DCHECK_EQ(profile_path_being_created_.value(),
-            new_profile->GetPath().value());
-
-  ManagedUserService* managed_user_service =
-      ManagedUserServiceFactory::GetForProfile(new_profile);
-
-  // Register the managed user using the profile of the custodian.
-  managed_user_registration_utility_ =
-      ManagedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui()));
-  managed_user_service->RegisterAndInitSync(
-      managed_user_registration_utility_.get(),
-      Profile::FromWebUI(web_ui()),
-      managed_user_id,
-      base::Bind(&CreateProfileHandler::OnManagedUserRegistered,
-                 weak_ptr_factory_.GetWeakPtr(),
-                 create_shortcut,
-                 desktop_type,
-                 new_profile));
-}
-
-void CreateProfileHandler::OnManagedUserRegistered(
-    bool create_shortcut,
-    chrome::HostDesktopType desktop_type,
-    Profile* profile,
-    const GoogleServiceAuthError& error) {
-  GoogleServiceAuthError::State state = error.state();
-  RecordSupervisedProfileCreationMetrics(state);
-  if (state == GoogleServiceAuthError::NONE) {
-    CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
-    return;
-  }
-
-  base::string16 error_msg;
-  if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
-      state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
-      state == GoogleServiceAuthError::ACCOUNT_DELETED ||
-      state == GoogleServiceAuthError::ACCOUNT_DISABLED) {
-    error_msg = GetProfileCreationErrorMessage(SIGNIN_ERROR);
-  } else {
-    error_msg = GetProfileCreationErrorMessage(REMOTE_ERROR);
-  }
-  ShowProfileCreationError(profile, error_msg);
-}
-
 void CreateProfileHandler::CreateShortcutAndShowSuccess(
     bool create_shortcut,
     chrome::HostDesktopType desktop_type,
@@ -253,10 +190,12 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
   dict.SetString("name",
                  profile->GetPrefs()->GetString(prefs::kProfileName));
   dict.Set("filePath", base::CreateFilePathValue(profile->GetPath()));
-  bool is_managed =
+#if defined(ENABLE_MANAGED_USERS)
+  bool is_supervised =
       profile_creation_type_ == SUPERVISED_PROFILE_CREATION ||
       profile_creation_type_ == SUPERVISED_PROFILE_IMPORT;
-  dict.SetBoolean("isManaged", is_managed);
+  dict.SetBoolean("isSupervised", is_supervised);
+#endif
   web_ui()->CallJavascriptFunction(
       GetJavascriptMethodName(PROFILE_CREATION_SUCCESS), dict);
 
@@ -265,7 +204,13 @@ void CreateProfileHandler::CreateShortcutAndShowSuccess(
   // dialog. If we are importing an existing supervised profile or creating a
   // new non-supervised user profile we don't show any confirmation, so open
   // the new window now.
-  if (profile_creation_type_ != SUPERVISED_PROFILE_CREATION) {
+  bool should_open_new_window = true;
+#if defined(ENABLE_MANAGED_USERS)
+  if (profile_creation_type_ == SUPERVISED_PROFILE_CREATION)
+    should_open_new_window = false;
+#endif
+
+  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,
@@ -284,14 +229,114 @@ void CreateProfileHandler::ShowProfileCreationError(
   web_ui()->CallJavascriptFunction(
       GetJavascriptMethodName(PROFILE_CREATION_ERROR),
       base::StringValue(error));
-  helper::DeleteProfileAtPath(profile->GetPath(), web_ui());
+  // The ProfileManager calls us back with a NULL profile in some cases.
+  if (profile)
+    helper::DeleteProfileAtPath(profile->GetPath(), web_ui());
 }
 
-void CreateProfileHandler::ShowProfileCreationWarning(
-    const base::string16& warning) {
-  DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
-  web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning",
-                                   base::StringValue(warning));
+void CreateProfileHandler::RecordProfileCreationMetrics(
+    Profile::CreateStatus 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()
+    const {
+  int message_id = IDS_PROFILES_CREATE_LOCAL_ERROR;
+#if defined(ENABLE_MANAGED_USERS)
+  // Local errors can occur during supervised profile import.
+  if (profile_creation_type_ == SUPERVISED_PROFILE_IMPORT)
+    message_id = IDS_SUPERVISED_USER_IMPORT_LOCAL_ERROR;
+#endif
+  return l10n_util::GetStringUTF16(message_id);
+}
+
+#if defined(ENABLE_MANAGED_USERS)
+base::string16 CreateProfileHandler::GetProfileCreationErrorMessageRemote()
+    const {
+  return l10n_util::GetStringUTF16(
+      profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
+          IDS_SUPERVISED_USER_IMPORT_REMOTE_ERROR :
+          IDS_PROFILES_CREATE_REMOTE_ERROR);
+}
+
+base::string16 CreateProfileHandler::GetProfileCreationErrorMessageSignin()
+    const {
+  return l10n_util::GetStringUTF16(
+      profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
+          IDS_SUPERVISED_USER_IMPORT_SIGN_IN_ERROR :
+          IDS_PROFILES_CREATE_SIGN_IN_ERROR);
+}
+#endif
+
+std::string CreateProfileHandler::GetJavascriptMethodName(
+    ProfileCreationStatus status) const {
+  switch (profile_creation_type_) {
+#if defined(ENABLE_MANAGED_USERS)
+    case SUPERVISED_PROFILE_IMPORT:
+      switch (status) {
+        case PROFILE_CREATION_SUCCESS:
+          return "BrowserOptions.showSupervisedUserImportSuccess";
+        case PROFILE_CREATION_ERROR:
+          return "BrowserOptions.showSupervisedUserImportError";
+      }
+      break;
+#endif
+    default:
+      switch (status) {
+        case PROFILE_CREATION_SUCCESS:
+          return "BrowserOptions.showCreateProfileSuccess";
+        case PROFILE_CREATION_ERROR:
+          return "BrowserOptions.showCreateProfileError";
+      }
+      break;
+  }
+
+  NOTREACHED();
+  return std::string();
+}
+
+#if defined(ENABLE_MANAGED_USERS)
+bool CreateProfileHandler::ProcessSupervisedCreateProfileArgs(
+    const base::ListValue* args, std::string* supervised_user_id) {
+  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);
+  }
+
+  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));
+      }
+    }
+  }
+  return true;
 }
 
 void CreateProfileHandler::HandleCancelProfileCreation(
@@ -299,20 +344,20 @@ void CreateProfileHandler::HandleCancelProfileCreation(
   CancelProfileRegistration(true);
 }
 
+// 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) {
   if (profile_path_being_created_.empty())
     return;
 
   ProfileManager* manager = g_browser_process->profile_manager();
   Profile* new_profile = manager->GetProfileByPath(profile_path_being_created_);
-  if (!new_profile)
+  if (!new_profile || !new_profile->IsSupervised())
     return;
 
-  // Non-managed user creation cannot be canceled. (Creating a non-managed
-  // profile shouldn't take significant time, and it can easily be deleted
-  // afterward.)
-  if (!new_profile->IsManaged())
-    return;
+  DCHECK(supervised_user_registration_utility_.get());
+  supervised_user_registration_utility_.reset();
 
   if (user_initiated) {
     UMA_HISTOGRAM_MEDIUM_TIMES(
@@ -321,9 +366,6 @@ void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) {
     RecordProfileCreationMetrics(Profile::CREATE_STATUS_CANCELED);
   }
 
-  DCHECK(managed_user_registration_utility_.get());
-  managed_user_registration_utility_.reset();
-
   DCHECK_NE(NO_CREATION_IN_PROGRESS, profile_creation_type_);
   profile_creation_type_ = NO_CREATION_IN_PROGRESS;
 
@@ -333,14 +375,60 @@ void CreateProfileHandler::CancelProfileRegistration(bool user_initiated) {
   helper::DeleteProfileAtPath(new_profile->GetPath(), web_ui());
 }
 
-void CreateProfileHandler::RecordProfileCreationMetrics(
-    Profile::CreateStatus status) {
-  UMA_HISTOGRAM_ENUMERATION("Profile.CreateResult",
-                            status,
-                            Profile::MAX_CREATE_STATUS);
-  UMA_HISTOGRAM_MEDIUM_TIMES(
-      "Profile.CreateTimeNoTimeout",
-      base::TimeTicks::Now() - profile_creation_start_time_);
+void CreateProfileHandler::RegisterSupervisedUser(
+    bool create_shortcut,
+    chrome::HostDesktopType desktop_type,
+    const std::string& supervised_user_id,
+    Profile* new_profile) {
+  DCHECK_EQ(profile_path_being_created_.value(),
+            new_profile->GetPath().value());
+
+  SupervisedUserService* supervised_user_service =
+      SupervisedUserServiceFactory::GetForProfile(new_profile);
+
+  // Register the supervised user using the profile of the custodian.
+  supervised_user_registration_utility_ =
+      SupervisedUserRegistrationUtility::Create(Profile::FromWebUI(web_ui()));
+  supervised_user_service->RegisterAndInitSync(
+      supervised_user_registration_utility_.get(),
+      Profile::FromWebUI(web_ui()),
+      supervised_user_id,
+      base::Bind(&CreateProfileHandler::OnSupervisedUserRegistered,
+                 weak_ptr_factory_.GetWeakPtr(),
+                 create_shortcut,
+                 desktop_type,
+                 new_profile));
+}
+
+void CreateProfileHandler::OnSupervisedUserRegistered(
+    bool create_shortcut,
+    chrome::HostDesktopType desktop_type,
+    Profile* profile,
+    const GoogleServiceAuthError& error) {
+  GoogleServiceAuthError::State state = error.state();
+  RecordSupervisedProfileCreationMetrics(state);
+  if (state == GoogleServiceAuthError::NONE) {
+    CreateShortcutAndShowSuccess(create_shortcut, desktop_type, profile);
+    return;
+  }
+
+  base::string16 error_msg;
+  if (state == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
+      state == GoogleServiceAuthError::USER_NOT_SIGNED_UP ||
+      state == GoogleServiceAuthError::ACCOUNT_DELETED ||
+      state == GoogleServiceAuthError::ACCOUNT_DISABLED) {
+    error_msg = GetProfileCreationErrorMessageSignin();
+  } else {
+    error_msg = GetProfileCreationErrorMessageRemote();
+  }
+  ShowProfileCreationError(profile, error_msg);
+}
+
+void CreateProfileHandler::ShowProfileCreationWarning(
+    const base::string16& warning) {
+  DCHECK_EQ(SUPERVISED_PROFILE_CREATION, profile_creation_type_);
+  web_ui()->CallJavascriptFunction("BrowserOptions.showCreateProfileWarning",
+                                   base::StringValue(warning));
 }
 
 void CreateProfileHandler::RecordSupervisedProfileCreationMetrics(
@@ -363,74 +451,28 @@ void CreateProfileHandler::RecordSupervisedProfileCreationMetrics(
   }
 }
 
-base::string16 CreateProfileHandler::GetProfileCreationErrorMessage(
-    ProfileCreationErrorType error) const {
-  int message_id = -1;
-  switch (error) {
-    case SIGNIN_ERROR:
-      message_id =
-          profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
-              IDS_MANAGED_USER_IMPORT_SIGN_IN_ERROR :
-              IDS_PROFILES_CREATE_SIGN_IN_ERROR;
-      break;
-    case REMOTE_ERROR:
-      message_id =
-          profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
-              IDS_MANAGED_USER_IMPORT_REMOTE_ERROR :
-              IDS_PROFILES_CREATE_REMOTE_ERROR;
-      break;
-    case LOCAL_ERROR:
-      message_id =
-          profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
-              IDS_MANAGED_USER_IMPORT_LOCAL_ERROR :
-              IDS_PROFILES_CREATE_LOCAL_ERROR;
-      break;
-  }
-
-  return l10n_util::GetStringUTF16(message_id);
-}
-
-std::string CreateProfileHandler::GetJavascriptMethodName(
-    ProfileCreationStatus status) const {
-  switch (status) {
-    case PROFILE_CREATION_SUCCESS:
-      return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
-          "BrowserOptions.showManagedUserImportSuccess" :
-          "BrowserOptions.showCreateProfileSuccess";
-    case PROFILE_CREATION_ERROR:
-      return profile_creation_type_ == SUPERVISED_PROFILE_IMPORT ?
-          "BrowserOptions.showManagedUserImportError" :
-          "BrowserOptions.showCreateProfileError";
-  }
-
-  NOTREACHED();
-  return std::string();
-}
-
-bool CreateProfileHandler::IsValidExistingManagedUserId(
-    const std::string& existing_managed_user_id) const {
-  if (existing_managed_user_id.empty())
+bool CreateProfileHandler::IsValidExistingSupervisedUserId(
+    const std::string& existing_supervised_user_id) const {
+  if (existing_supervised_user_id.empty())
     return true;
 
-  if (CommandLine::ForCurrentProcess()->HasSwitch(
-      switches::kDisableCreateExistingManagedUsers)) {
-    return false;
-  }
-
   Profile* profile = Profile::FromWebUI(web_ui());
   const base::DictionaryValue* dict =
-      ManagedUserSyncServiceFactory::GetForProfile(profile)->GetManagedUsers();
-  if (!dict->HasKey(existing_managed_user_id))
+      SupervisedUserSyncServiceFactory::GetForProfile(profile)->
+          GetSupervisedUsers();
+  if (!dict->HasKey(existing_supervised_user_id))
     return false;
 
-  // Check if this managed user already exists on this machine.
+  // 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_managed_user_id == cache.GetManagedUserIdOfProfileAtIndex(i))
+    if (existing_supervised_user_id ==
+            cache.GetSupervisedUserIdOfProfileAtIndex(i))
       return false;
   }
   return true;
 }
+#endif
 
 }  // namespace options