#include "base/files/file_path.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/about_flags.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/pref_service_flags_storage.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/browser_thread.h"
namespace {
+const char kNewProfileManagementExperimentInternalName[] =
+ "enable-new-profile-management";
+
// Handles running a callback when a new Browser for the given profile
// has been completely created.
class BrowserAddedForProfileObserver : public chrome::BrowserListObserver {
void CreateAndSwitchToNewProfile(chrome::HostDesktopType desktop_type,
ProfileSwitchingDoneCallback callback,
ProfileMetrics::ProfileAdd metric) {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+
+ int placeholder_avatar_index = profiles::GetPlaceholderAvatarIndex();
ProfileManager::CreateMultiProfileAsync(
- base::string16(),
- base::string16(),
+ cache.ChooseNameForNewProfile(placeholder_avatar_index),
+ base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(
+ placeholder_avatar_index)),
base::Bind(&OpenBrowserWindowForProfile,
callback,
true,
}
void ShowUserManagerMaybeWithTutorial(Profile* profile) {
- if (!profile) {
+ // Guest users cannot appear in the User Manager, nor display a tutorial.
+ if (!profile || profile->IsGuestSession()) {
chrome::ShowUserManager(base::FilePath());
return;
}
}
}
+void EnableNewProfileManagementPreview() {
+ about_flags::PrefServiceFlagsStorage flags_storage(
+ g_browser_process->local_state());
+ about_flags::SetExperimentEnabled(
+ &flags_storage,
+ kNewProfileManagementExperimentInternalName,
+ true);
+
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kNewProfileManagement);
+ chrome::ShowUserManagerWithTutorial(profiles::USER_MANAGER_TUTORIAL_OVERVIEW);
+}
+
+void DisableNewProfileManagementPreview() {
+ about_flags::PrefServiceFlagsStorage flags_storage(
+ g_browser_process->local_state());
+ about_flags::SetExperimentEnabled(
+ &flags_storage,
+ kNewProfileManagementExperimentInternalName,
+ false);
+ chrome::AttemptRestart();
+}
+
} // namespace profiles