Commit 70640da4 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfilePicker]: Allow users to control frequency of the profile picker.

This CL adds a checkbox to the main view of the profile picker. By
default the profile picker frequency is set to be shown on every
startup.  The user can decide to change that by checking/unchecking the
'Ask on startup' option. The profile picker is meant to be shown in the
picker window and is a singleton not in a chrome tab, for that reason
the profile picker does not listen on changes to
|kBrowserShowProfilePickerOnStartup|.

Screenshot:
https://drive.google.com/file/d/1UH63Pl773SQ95iSLzxnnaPTjwJ5KwxJD/view?usp=sharing

Bug: 1063856
Change-Id: I2e8f71abb8ad93a3e0f5dfd84426a7deb0ea15b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333834
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794525}
parent 0f9d72bd
......@@ -664,6 +664,9 @@
<!-- Profile Picker -->
<if expr="not chromeos and not is_android">
<message name="IDS_PROFILE_PICKER_ASK_ON_STARTUP" desc="Text for the checkbox on the profile picker main view">
Ask on startup
</message>
<message name="IDS_PROFILE_PICKER_BACK_BUTTON_LABEL" desc="Label for a button that navigates user to the previous page">
Back
</message>
......
9b870df57bd31352a2576b0e15a0d58f541e4858
\ No newline at end of file
......@@ -68,6 +68,8 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kBrowserGuestModeEnforced, false);
registry->RegisterBooleanPref(prefs::kBrowserAddPersonEnabled, true);
registry->RegisterBooleanPref(prefs::kForceBrowserSignin, false);
registry->RegisterBooleanPref(prefs::kBrowserShowProfilePickerOnStartup,
true);
}
void SetLastUsedProfile(const std::string& profile_dir) {
......
......@@ -31,7 +31,9 @@ js_library("profile_picker_main_view") {
":navigation_behavior",
"//third_party/polymer/v3_0/components-chromium/iron-icon",
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
"//ui/webui/resources/cr_elements/cr_checkbox:cr_checkbox.m",
"//ui/webui/resources/cr_elements/cr_icon_button:cr_icon_button.m",
"//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:web_ui_listener_behavior.m",
]
}
......
......@@ -37,6 +37,13 @@ export class ManageProfilesBrowserProxy {
*/
launchSelectedProfile(profilePath) {}
/**
* Inform native the user's choice on whether to show the profile picker
* on startup or not.
* @param {boolean} shouldShow
*/
askOnStartupChanged(shouldShow) {}
/**
* Retrieves suggested theme for the new profile.
* @return {!Promise<!AutogeneratedThemeColorInfo>} A promise firing with the
......@@ -57,6 +64,11 @@ export class ManageProfilesBrowserProxyImpl {
chrome.send('launchSelectedProfile', [profilePath]);
}
/** @override */
askOnStartupChanged(shouldShow) {
chrome.send('askOnStartupChanged', [shouldShow]);
}
/** @override */
getNewProfileSuggestedThemeInfo() {
return sendWithPromise('getNewProfileSuggestedThemeInfo');
......
......@@ -6,9 +6,7 @@
}
.banner {
bottom: 0;
height: var(--banner-img-height);
margin: auto;
overflow: hidden;
position: absolute;
top: 0;
......@@ -93,6 +91,27 @@
@media (prefers-color-scheme: dark) {
/* TODO(msalama): Dark mode mocks not ready yet.*/
cr-checkbox {
--cr-checkbox-label-color: var(--google-grey-refresh-500);
background-color: rgba(var(--md-background-color), .8);
}
}
.footer {
bottom: 0;
display: flex;
margin-bottom: 40px;
position: absolute;
width: 100%;
}
cr-checkbox {
--cr-checkbox-label-color: var(--google-grey-refresh-700);
--cr-checkbox-label-padding-start: 8px;
background-color: rgba(255, 255, 255, .8);
justify-content: flex-end;
margin-inline-end: 40px;
margin-inline-start: auto;
}
</style>
......@@ -118,3 +137,10 @@
</div>
</div>
<div id="rightBanner" class="banner"></div>
<div class="footer">
<cr-checkbox checked="{{askOnStartup_}}"
on-change="onAskOnStartupChangedByUser_">
$i18n{askOnStartupCheckboxText}
</cr-checkbox>
</div>
......@@ -4,12 +4,15 @@
import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.m.js';
import './icons.js';
import './profile_card.js';
import './profile_picker_shared_css.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerBehavior} from 'chrome://resources/js/web_ui_listener_behavior.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import './strings.js';
import {ManageProfilesBrowserProxy, ManageProfilesBrowserProxyImpl, ProfileState} from './manage_profiles_browser_proxy.js';
import {navigateTo, NavigationBehavior, Routes} from './navigation_behavior.js';
......@@ -30,6 +33,14 @@ Polymer({
profilesList_: {
type: Object,
},
/** @private */
askOnStartup_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('askOnStartup');
}
},
},
/** @private {?ManageProfilesBrowserProxy} */
......@@ -69,6 +80,14 @@ Polymer({
this.profilesList_ = profilesList;
},
/**
* Called when the user modifies 'Ask on startup' preference.
* @private
*/
onAskOnStartupChangedByUser_() {
this.manageProfilesBrowserProxy_.askOnStartupChanged(this.askOnStartup_);
},
/** @private */
onAddProfileClick_() {
navigateTo(Routes.NEW_PROFILE);
......
......@@ -273,6 +273,8 @@ bool ShouldShowProfilePicker() {
->GetProfileAttributesStorage()
.GetNumberOfProfiles();
return !signin_util::IsForceSigninEnabled() && number_of_profiles != 1 &&
g_browser_process->local_state()->GetBoolean(
prefs::kBrowserShowProfilePickerOnStartup) &&
base::FeatureList::IsEnabled(features::kNewProfilePicker);
}
#endif // !defined(OS_CHROMEOS)
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/search/generated_colors_info.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/webui/web_ui_util.h"
......@@ -41,6 +42,10 @@ void ProfilePickerHandler::RegisterMessages() {
"launchSelectedProfile",
base::BindRepeating(&ProfilePickerHandler::HandleLaunchSelectedProfile,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"askOnStartupChanged",
base::BindRepeating(&ProfilePickerHandler::HandleAskOnStartupChanged,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getNewProfileSuggestedThemeInfo",
base::BindRepeating(
......@@ -97,6 +102,16 @@ void ProfilePickerHandler::HandleLaunchSelectedProfile(
weak_factory_.GetWeakPtr()));
}
void ProfilePickerHandler::HandleAskOnStartupChanged(
const base::ListValue* args) {
bool show_on_startup;
if (!args->GetBoolean(0, &show_on_startup))
return;
PrefService* prefs = g_browser_process->local_state();
prefs->SetBoolean(prefs::kBrowserShowProfilePickerOnStartup, show_on_startup);
}
void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo(
const base::ListValue* args) {
AllowJavascript();
......
......@@ -26,6 +26,7 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
private:
void HandleMainViewInitialize(const base::ListValue* args);
void HandleLaunchSelectedProfile(const base::ListValue* args);
void HandleAskOnStartupChanged(const base::ListValue* args);
void HandleGetNewProfileSuggestedThemeInfo(const base::ListValue* args);
void OnSwitchToProfileComplete(Profile* profile,
......
......@@ -4,14 +4,17 @@
#include "chrome/browser/ui/webui/signin/profile_picker_ui.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/signin/profile_picker_handler.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/profile_picker_resources.h"
#include "chrome/grit/profile_picker_resources_map.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/webui/web_ui_util.h"
......@@ -21,6 +24,7 @@ void AddStrings(content::WebUIDataSource* html_source) {
static constexpr webui::LocalizedString kLocalizedStrings[] = {
{"mainViewTitle", IDS_PROFILE_PICKER_MAIN_VIEW_TITLE},
{"mainViewSubtitle", IDS_PROFILE_PICKER_MAIN_VIEW_SUBTITLE},
{"askOnStartupCheckboxText", IDS_PROFILE_PICKER_ASK_ON_STARTUP},
{"backButtonLabel", IDS_PROFILE_PICKER_BACK_BUTTON_LABEL},
{"profileTypeChoiceTitle",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_PROFILE_TYPE_CHOICE_TITLE},
......@@ -32,6 +36,9 @@ void AddStrings(content::WebUIDataSource* html_source) {
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_NOT_NOW_BUTTON_LABEL},
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
html_source->AddBoolean("askOnStartup",
g_browser_process->local_state()->GetBoolean(
prefs::kBrowserShowProfilePickerOnStartup));
}
} // namespace
......
......@@ -2628,6 +2628,10 @@ const char kBrowserAddPersonEnabled[] = "profile.add_person_enabled";
// Whether profile can be used before sign in.
const char kForceBrowserSignin[] = "profile.force_browser_signin";
// Whether to show the profile picker on startup or not.
const char kBrowserShowProfilePickerOnStartup[] =
"profile.show_picker_on_startup";
// Boolean which indicates if the user is allowed to sign into Chrome on the
// next startup.
const char kSigninAllowedOnNextStartup[] = "signin.allowed_on_next_startup";
......
......@@ -886,6 +886,7 @@ extern const char kBrowserGuestModeEnabled[];
extern const char kBrowserGuestModeEnforced[];
extern const char kBrowserAddPersonEnabled[];
extern const char kForceBrowserSignin[];
extern const char kBrowserShowProfilePickerOnStartup[];
extern const char kSigninAllowedOnNextStartup[];
extern const char kCryptAuthDeviceId[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment