Commit 31fc3d06 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

Settings[DICE]: Add account selectors and sync buttons.

Bug: 800970
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ifdfa802f6eb36414bc51d0442f572eafbf089a54
Reviewed-on: https://chromium-review.googlesource.com/887728
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534576}
parent 560d7677
...@@ -3051,6 +3051,18 @@ ...@@ -3051,6 +3051,18 @@
<message name="IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT_SECONDARY" desc="The secondary text displayed to prompt users to sign in to chrome."> <message name="IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT_SECONDARY" desc="The secondary text displayed to prompt users to sign in to chrome.">
Sync for a personalized browsing experience, across your devices Sync for a personalized browsing experience, across your devices
</message> </message>
<message name="IDS_SETTINGS_PEOPLE_SYNC_ANOTHER_ACCOUNT" desc="The label for the button that lets the user choose another account to sync with.">
Use another account
</message>
<message name="IDS_SETTINGS_PEOPLE_SYNC_AS_NAME" desc="The label for the button that lets the user lock-in the account to sync with.">
Sync as <ph name="FULL_NAME">$1<ex>Bob Smith</ex></ph>
</message>
<message name="IDS_SETTINGS_PEOPLE_SYNCED_TO_NAME" desc="The text displayed to the user that the profile is currently synced to a specific account.">
Synced to <ph name="FULL_NAME">$1<ex>Bob Smith</ex></ph>
</message>
<message name="IDS_SETTINGS_PEOPLE_SYNC_TURN_OFF" desc="The label for the button that lets the user turn off profile syncing with their gaia account.">
Turn off
</message>
<message name="IDS_SETTINGS_SYNC_DISCONNECT_MANAGED_PROFILE_EXPLANATION" desc="The text to display in the 'Sign out of Chrome' dialog to stop syncing for managed profiles."> <message name="IDS_SETTINGS_SYNC_DISCONNECT_MANAGED_PROFILE_EXPLANATION" desc="The text to display in the 'Sign out of Chrome' dialog to stop syncing for managed profiles.">
Because this account is managed by <ph name="DOMAIN">$1<ex>example.com</ex></ph>, your bookmarks, history, passwords, and other settings will be cleared from this device. However, your data will remain stored in your Google Account and can be managed on <ph name="BEGIN_LINK">&lt;a href="$2" target=&quot;_blank&quot;&gt;<ex>&lt;a href="$2" target=&quot;_blank&quot;&gt;</ex></ph>Google Dashboard<ph name="END_LINK">&lt;/a&gt;<ex>&lt;/a&gt;</ex></ph>. Because this account is managed by <ph name="DOMAIN">$1<ex>example.com</ex></ph>, your bookmarks, history, passwords, and other settings will be cleared from this device. However, your data will remain stored in your Google Account and can be managed on <ph name="BEGIN_LINK">&lt;a href="$2" target=&quot;_blank&quot;&gt;<ex>&lt;a href="$2" target=&quot;_blank&quot;&gt;</ex></ph>Google Dashboard<ph name="END_LINK">&lt;/a&gt;<ex>&lt;/a&gt;</ex></ph>.
</message> </message>
......
...@@ -260,6 +260,8 @@ ...@@ -260,6 +260,8 @@
'dependencies': [ 'dependencies': [
'../compiled_resources2.gyp:route', '../compiled_resources2.gyp:route',
'../prefs/compiled_resources2.gyp:prefs_behavior', '../prefs/compiled_resources2.gyp:prefs_behavior',
'<(DEPTH)/ui/webui/resources/cr_elements/cr_action_menu/compiled_resources2.gyp:cr_action_menu',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:icon', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:icon',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:web_ui_listener_behavior', '<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:web_ui_listener_behavior',
'profile_info_browser_proxy', 'profile_info_browser_proxy',
......
...@@ -103,14 +103,10 @@ ...@@ -103,14 +103,10 @@
<neon-animatable route-path="default"> <neon-animatable route-path="default">
<if expr="not chromeos"> <if expr="not chromeos">
<template is="dom-if" if="[[diceEnabled_]]"> <template is="dom-if" if="[[diceEnabled_]]">
<div class="settings-box first two-line" <settings-sync-account-control
hidden="[[syncStatus.signedIn]]"> promo-label="$i18n{peopleSignInPrompt}"
<div class="start"> promo-secondary-label="$i18n{peopleSignInPromptSecondary}">
<div>$i18n{peopleSignInPrompt}</div> </settings-sync-account-control>
<div class="secondary">$i18n{peopleSignInPromptSecondary}</div>
</div>
</div>
<settings-sync-account-control></settings-sync-account-control>
</template> </template>
<template is="dom-if" if="[[!diceEnabled_]]"> <template is="dom-if" if="[[!diceEnabled_]]">
</if> </if>
......
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html"> <link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="chrome://resources/html/icon.html"> <link rel="import" href="chrome://resources/cr_elements/cr_action_menu/cr_action_menu.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html"> <link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="profile_info_browser_proxy.html"> <link rel="import" href="profile_info_browser_proxy.html">
<link rel="import" href="sync_browser_proxy.html"> <link rel="import" href="sync_browser_proxy.html">
<link rel="import" href="../i18n_setup.html">
<link rel="import" href="../route.html"> <link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
...@@ -17,48 +18,93 @@ ...@@ -17,48 +18,93 @@
-webkit-margin-start: 20px; -webkit-margin-start: 20px;
} }
#profile-icon { .account-icon {
background: center / cover no-repeat; background: url(chrome://theme/IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE)
center / cover no-repeat;
border-radius: 20px; border-radius: 20px;
flex-shrink: 0; flex-shrink: 0;
height: 40px; height: 40px;
width: 40px; width: 40px;
} }
.account-icon.small {
height: 20px;
width: 20px;
}
#menu .dropdown-item {
padding: 12px;
}
#menu .dropdown-item .email {
-webkit-margin-start: 8px;
}
.flex { .flex {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
</style> </style>
<div class="settings-box first two-line"> <!-- TODO(scottchen): figure out what to show if sign-in (not just sync)
<template is="dom-if" if="[[syncStatus]]"> is not even allowed by policy (crbug/807061). -->
<div id="profile-icon" <div class="settings-box first two-line" hidden="[[syncStatus.signedIn]]">
style="background-image: [[getIcon_(profileInfo_.iconUrl)]]"> <div class="start">
</div> <div>[[promoLabel]]</div>
<div class="secondary">[[promoSecondaryLabel]]</div>
</div>
<div class="separator" hidden="[[shouldShowAvatarRow_]]"></div>
<paper-button class="primary-button" on-tap="onSigninTap_"
disabled="[[syncStatus.setupInProgress]]"
hidden="[[shouldShowAvatarRow_]]">
$i18n{syncSignin}
</paper-button>
</div>
<template is="dom-if" if="[[shouldShowAvatarRow_]]">
<div class="settings-box first two-line">
<img class="account-icon" src="[[shownAccount_.image]]">
<div class="middle two-line no-min-width"> <div class="middle two-line no-min-width">
<div class="flex text-elide"> <div class="flex text-elide">
<span>[[profileInfo_.name]]</span> <span>
<div class="secondary" hidden="[[!syncStatus.signedIn]]"> [[getNameDisplay_('$i18nPolymer{syncedToName}',
[[syncStatus.signedInUsername]] shownAccount_.fullName, syncStatus.signedIn)]]
</div> </span>
<div class="secondary">[[shownAccount_.email]]</div>
</div> </div>
<div class="separator" hidden="[[syncStatus.signedIn]]"></div>
<button is="paper-icon-button-light" id="dots"
on-tap="onMenuButtonTap_" title="$i18n{moreActions}"
class="icon-arrow-dropdown" hidden="[[syncStatus.signedIn]]">
</button>
</div> </div>
<template is="dom-if" if="[[showSignin_(syncStatus)]]"> <!-- TODO(scottchen): Disable if sync not allowed by policy
<paper-button class="primary-button" on-tap="onSigninTap_" (crbug/807061). -->
disabled="[[syncStatus.setupInProgress]]"> <paper-button class="action-button" on-tap="onSyncButtonTap_"
$i18n{syncSignin} hidden="[[syncStatus.signedIn]]">
</paper-button> [[getSubstituteLabel_(
</template> '$i18nPolymer{syncAsName}', shownAccount_.fullName)]]
<template is="dom-if" if="[[syncStatus.signedIn]]"> </paper-button>
<div class="separator"></div> <!-- TODO(scottchen): Find out if there's a policy that forbids
<paper-button id="disconnectButton" class="secondary-button" turning off sync. If so, disable button (crbug/807061). -->
on-tap="onDisconnectTap_" <paper-button class="secondary-button" on-tap="onTurnOffButtonTap_"
disabled="[[syncStatus.setupInProgress]]"> hidden="[[!syncStatus.signedIn]]">
$i18n{syncDisconnect} $i18n{turnOffSync}
</paper-button> </paper-button>
</template> </div>
<template is="dom-if" if="[[!syncStatus.signedIn]]" restamp>
<dialog is="cr-action-menu" id="menu">
<template is="dom-repeat" items="[[storedAccounts_]]">
<button class="dropdown-item" on-tap="onAccountTap_" slot="item">
<img class="account-icon small" src="[[item.image]]">
<span class="email">[[item.email]]</span>
</button>
</template>
<button class="dropdown-item" on-tap="onSigninTap_" slot="item">
<div class="account-icon small"></div>
<span class="email">$i18n{useAnotherAccount}</span>
</button>
</dialog>
</template> </template>
</div> </template>
</template> </template>
<script src="sync_account_control.js"></script> <script src="sync_account_control.js"></script>
</dom-module> </dom-module>
...@@ -12,74 +12,148 @@ Polymer({ ...@@ -12,74 +12,148 @@ Polymer({
properties: { properties: {
/** /**
* The current sync status, supplied by SyncBrowserProxy. * The current sync status, supplied by SyncBrowserProxy.
* @type {?settings.SyncStatus} * @type {!settings.SyncStatus}
*/ */
syncStatus: Object, syncStatus: Object,
/** @private {!settings.ProfileInfo} */ /** @private {!Array<!settings.StoredAccount>} */
profileInfo_: Object, storedAccounts_: Object,
/** @private {?settings.StoredAccount} */
shownAccount_: Object,
promoLabel: String,
promoSecondaryLabel: String,
/** @private {boolean} */
shouldShowAvatarRow_: {
type: Boolean,
value: false,
computed: 'computeShouldShowAvatarRow_(storedAccounts_, syncStatus,' +
'storedAccounts_.length, syncStatus.signedIn)',
}
}, },
observers: [
'onShownAccountShouldChange_(storedAccounts_.*, syncStatus.*)',
],
/** @private {?settings.SyncBrowserProxy} */ /** @private {?settings.SyncBrowserProxy} */
syncBrowserProxy_: null, syncBrowserProxy_: null,
/** @override */ /** @override */
attached: function() { attached: function() {
const profileInfoProxy = settings.ProfileInfoBrowserProxyImpl.getInstance();
profileInfoProxy.getProfileInfo().then(this.handleProfileInfo_.bind(this));
this.addWebUIListener(
'profile-info-changed', this.handleProfileInfo_.bind(this));
this.syncBrowserProxy_ = settings.SyncBrowserProxyImpl.getInstance(); this.syncBrowserProxy_ = settings.SyncBrowserProxyImpl.getInstance();
this.syncBrowserProxy_.getSyncStatus().then( this.syncBrowserProxy_.getSyncStatus().then(
this.handleSyncStatus_.bind(this)); this.handleSyncStatus_.bind(this));
this.syncBrowserProxy_.getStoredAccounts().then(
this.handleStoredAccounts_.bind(this));
this.addWebUIListener( this.addWebUIListener(
'sync-status-changed', this.handleSyncStatus_.bind(this)); 'sync-status-changed', this.handleSyncStatus_.bind(this));
this.addWebUIListener(
'stored-accounts-updated', this.handleStoredAccounts_.bind(this));
},
/**
* @param {string} label
* @param {string} name
* @return {string}
* @private
*/
getSubstituteLabel_: function(label, name) {
return loadTimeData.substituteString(label, name);
},
/**
* @param {string} label
* @param {string} name
* @return {string}
* @private
*/
getNameDisplay_: function(label, name) {
return this.syncStatus.signedIn ?
loadTimeData.substituteString(label, name) :
name;
}, },
/** /**
* Handler for when the profile's icon and name is updated. * @param {!Array<!settings.StoredAccount>} accounts
* @private * @private
* @param {!settings.ProfileInfo} info
*/ */
handleProfileInfo_: function(info) { handleStoredAccounts_: function(accounts) {
this.profileInfo_ = info; this.storedAccounts_ = accounts;
}, },
/** /**
* Handler for when the sync state is pushed from the browser. * Handler for when the sync state is pushed from the browser.
* @param {?settings.SyncStatus} syncStatus * @param {!settings.SyncStatus} syncStatus
* @private * @private
*/ */
handleSyncStatus_: function(syncStatus) { handleSyncStatus_: function(syncStatus) {
this.syncStatus = syncStatus; this.syncStatus = syncStatus;
}, },
/**
* @return {boolean}
* @private
*/
computeShouldShowAvatarRow_: function() {
return this.syncStatus.signedIn || this.storedAccounts_.length > 0;
},
/** @private */ /** @private */
onSigninTap_: function() { onSigninTap_: function() {
this.syncBrowserProxy_.startSignIn(); this.syncBrowserProxy_.startSignIn();
// Need to close here since one menu item also triggers this function.
if (this.$$('#menu')) {
/** @type {!CrActionMenuElement} */ (this.$$('#menu')).close();
}
}, },
/** @private */ /** @private */
onDisconnectTap_: function() { onSyncButtonTap_: function() {
assert(this.shownAccount_);
this.syncBrowserProxy_.startSyncingWithEmail(this.shownAccount_.email);
},
/** @private */
onTurnOffButtonTap_: function() {
/* This will route to people_page's disconnect dialog. */ /* This will route to people_page's disconnect dialog. */
settings.navigateTo(settings.routes.SIGN_OUT); settings.navigateTo(settings.routes.SIGN_OUT);
}, },
/** /** @private */
* @param {string} iconUrl onMenuButtonTap_: function() {
* @return {string} A CSS image-set for multiple scale factors. const actionMenu =
* @private /** @type {!CrActionMenuElement} */ (this.$$('#menu'));
*/ actionMenu.showAt(assert(this.$$('#dots')));
getIcon_: function(iconUrl) {
return cr.icon.getImage(iconUrl);
}, },
/** /**
* @param {!settings.SyncStatus} syncStatus * @param {!{model:
* @return {boolean} Whether to show the "Sign in to Chrome" button. * !{item: !settings.StoredAccount},
* }} e
* @private * @private
*/ */
showSignin_: function(syncStatus) { onAccountTap_: function(e) {
return !!syncStatus.signinAllowed && !syncStatus.signedIn; this.shownAccount_ = e.model.item;
/** @type {!CrActionMenuElement} */ (this.$$('#menu')).close();
}, },
/** @private */
onShownAccountShouldChange_: function() {
if (this.syncStatus.signedIn) {
for (let i = 0; i < this.storedAccounts_.length; i++) {
if (this.storedAccounts_[i].email == this.syncStatus.signedInUsername) {
this.shownAccount_ = this.storedAccounts_[i];
return;
}
}
} else {
this.shownAccount_ =
this.storedAccounts_ ? this.storedAccounts_[0] : null;
}
}
}); });
\ No newline at end of file
...@@ -9,6 +9,14 @@ ...@@ -9,6 +9,14 @@
*/ */
cr.exportPath('settings'); cr.exportPath('settings');
/**
* @typedef {{fullName: (string|undefined),
* email: !string,
* image: (string|undefined)}}
* @see chrome/browser/ui/webui/settings/people_handler.cc
*/
settings.StoredAccount;
/** /**
* @typedef {{childUser: (boolean|undefined), * @typedef {{childUser: (boolean|undefined),
* domain: (string|undefined), * domain: (string|undefined),
...@@ -140,6 +148,12 @@ cr.define('settings', function() { ...@@ -140,6 +148,12 @@ cr.define('settings', function() {
*/ */
getSyncStatus() {} getSyncStatus() {}
/**
* Gets a list of stored accounts.
* @return {!Promise<!Array<!settings.StoredAccount>>}
*/
getStoredAccounts() {}
/** /**
* Function to invoke when the sync page has been navigated to. This * Function to invoke when the sync page has been navigated to. This
* registers the UI as the "active" sync UI so that if the user tries to * registers the UI as the "active" sync UI so that if the user tries to
...@@ -167,6 +181,12 @@ cr.define('settings', function() { ...@@ -167,6 +181,12 @@ cr.define('settings', function() {
*/ */
setSyncEncryption(syncPrefs) {} setSyncEncryption(syncPrefs) {}
/**
* Start syncing with an account, specified by its email.
* @param {!string} email
*/
startSyncingWithEmail(email) {}
/** /**
* Opens the Google Activity Controls url in a new tab. * Opens the Google Activity Controls url in a new tab.
*/ */
...@@ -199,7 +219,6 @@ cr.define('settings', function() { ...@@ -199,7 +219,6 @@ cr.define('settings', function() {
attemptUserExit() { attemptUserExit() {
return chrome.send('AttemptUserExit'); return chrome.send('AttemptUserExit');
} }
// </if> // </if>
/** @override */ /** @override */
...@@ -207,6 +226,11 @@ cr.define('settings', function() { ...@@ -207,6 +226,11 @@ cr.define('settings', function() {
return cr.sendWithPromise('SyncSetupGetSyncStatus'); return cr.sendWithPromise('SyncSetupGetSyncStatus');
} }
/** @override */
getStoredAccounts() {
return cr.sendWithPromise('SyncSetupGetStoredAccounts');
}
/** @override */ /** @override */
didNavigateToSyncPage() { didNavigateToSyncPage() {
chrome.send('SyncSetupShowSetupUI'); chrome.send('SyncSetupShowSetupUI');
...@@ -229,6 +253,11 @@ cr.define('settings', function() { ...@@ -229,6 +253,11 @@ cr.define('settings', function() {
'SyncSetupSetEncryption', JSON.stringify(syncPrefs)); 'SyncSetupSetEncryption', JSON.stringify(syncPrefs));
} }
/** @override */
startSyncingWithEmail(email) {
chrome.send('SyncSetupStartSyncingWithEmail', [email]);
}
/** @override */ /** @override */
openActivityControlsUrl() { openActivityControlsUrl() {
chrome.metricsPrivate.recordUserAction( chrome.metricsPrivate.recordUserAction(
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/plugins/plugin_utils.h" #include "chrome/browser/plugins/plugin_utils.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "components/google/core/browser/google_util.h" #include "components/google/core/browser/google_util.h"
#include "components/password_manager/core/browser/password_manager_constants.h" #include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/signin/core/browser/signin_features.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h" #include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
...@@ -1439,13 +1441,19 @@ void AddPeopleStrings(content::WebUIDataSource* html_source) { ...@@ -1439,13 +1441,19 @@ void AddPeopleStrings(content::WebUIDataSource* html_source) {
{"videoModeAccessibleText", IDS_SETTINGS_VIDEO_MODE_ACCESSIBLE_TEXT}, {"videoModeAccessibleText", IDS_SETTINGS_VIDEO_MODE_ACCESSIBLE_TEXT},
#else // !defined(OS_CHROMEOS) #else // !defined(OS_CHROMEOS)
{"domainManagedProfile", IDS_SETTINGS_PEOPLE_DOMAIN_MANAGED_PROFILE}, {"domainManagedProfile", IDS_SETTINGS_PEOPLE_DOMAIN_MANAGED_PROFILE},
{"peopleSignInPrompt", IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT},
{"peopleSignInPromptSecondary",
IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT_SECONDARY},
{"editPerson", IDS_SETTINGS_EDIT_PERSON}, {"editPerson", IDS_SETTINGS_EDIT_PERSON},
{"profileNameAndPicture", IDS_SETTINGS_PROFILE_NAME_AND_PICTURE}, {"profileNameAndPicture", IDS_SETTINGS_PROFILE_NAME_AND_PICTURE},
{"showShortcutLabel", IDS_SETTINGS_PROFILE_SHORTCUT_TOGGLE_LABEL}, {"showShortcutLabel", IDS_SETTINGS_PROFILE_SHORTCUT_TOGGLE_LABEL},
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
{"peopleSignInPrompt", IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT},
{"peopleSignInPromptSecondary",
IDS_SETTINGS_PEOPLE_SIGN_IN_PROMPT_SECONDARY},
{"useAnotherAccount", IDS_SETTINGS_PEOPLE_SYNC_ANOTHER_ACCOUNT},
{"syncAsName", IDS_SETTINGS_PEOPLE_SYNC_AS_NAME},
{"syncedToName", IDS_SETTINGS_PEOPLE_SYNCED_TO_NAME},
{"turnOffSync", IDS_SETTINGS_PEOPLE_SYNC_TURN_OFF},
#endif
{"syncOverview", IDS_SETTINGS_SYNC_OVERVIEW}, {"syncOverview", IDS_SETTINGS_SYNC_OVERVIEW},
{"syncDisabledByAdministrator", {"syncDisabledByAdministrator",
IDS_SETTINGS_SYNC_DISABLED_BY_ADMINISTRATOR}, IDS_SETTINGS_SYNC_DISABLED_BY_ADMINISTRATOR},
......
...@@ -64,6 +64,13 @@ ...@@ -64,6 +64,13 @@
#else #else
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#endif #endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
// TODO(scottchen): no longer need icon_util once we start loading real
// account pictures.
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "components/signin/core/browser/account_tracker_service.h"
#endif
using browser_sync::ProfileSyncService; using browser_sync::ProfileSyncService;
using content::WebContents; using content::WebContents;
...@@ -186,7 +193,14 @@ PeopleHandler::PeopleHandler(Profile* profile) ...@@ -186,7 +193,14 @@ PeopleHandler::PeopleHandler(Profile* profile)
: profile_(profile), : profile_(profile),
configuring_sync_(false), configuring_sync_(false),
signin_observer_(this), signin_observer_(this),
sync_service_observer_(this) {} #if BUILDFLAG(ENABLE_DICE_SUPPORT)
sync_service_observer_(this),
account_tracker_observer_(this) {
}
#else
sync_service_observer_(this) {
}
#endif
PeopleHandler::~PeopleHandler() { PeopleHandler::~PeopleHandler() {
// Early exit if running unit tests (no actual WebUI is attached). // Early exit if running unit tests (no actual WebUI is attached).
...@@ -231,6 +245,16 @@ void PeopleHandler::RegisterMessages() { ...@@ -231,6 +245,16 @@ void PeopleHandler::RegisterMessages() {
"SyncSetupStartSignIn", "SyncSetupStartSignIn",
base::Bind(&PeopleHandler::HandleStartSignin, base::Unretained(this))); base::Bind(&PeopleHandler::HandleStartSignin, base::Unretained(this)));
#endif #endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
web_ui()->RegisterMessageCallback(
"SyncSetupGetStoredAccounts",
base::BindRepeating(&PeopleHandler::HandleGetStoredAccounts,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"SyncSetupStartSyncingWithEmail",
base::BindRepeating(&PeopleHandler::HandleStartSyncingWithEmail,
base::Unretained(this)));
#endif
} }
void PeopleHandler::OnJavascriptAllowed() { void PeopleHandler::OnJavascriptAllowed() {
...@@ -249,12 +273,22 @@ void PeopleHandler::OnJavascriptAllowed() { ...@@ -249,12 +273,22 @@ void PeopleHandler::OnJavascriptAllowed() {
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_)); ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_));
if (sync_service) if (sync_service)
sync_service_observer_.Add(sync_service); sync_service_observer_.Add(sync_service);
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
AccountTrackerService* account_tracker(
AccountTrackerServiceFactory::GetForProfile(profile_));
if (account_tracker)
account_tracker_observer_.Add(account_tracker);
#endif
} }
void PeopleHandler::OnJavascriptDisallowed() { void PeopleHandler::OnJavascriptDisallowed() {
profile_pref_registrar_.RemoveAll(); profile_pref_registrar_.RemoveAll();
signin_observer_.RemoveAll(); signin_observer_.RemoveAll();
sync_service_observer_.RemoveAll(); sync_service_observer_.RemoveAll();
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
account_tracker_observer_.RemoveAll();
#endif
} }
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
...@@ -407,6 +441,60 @@ void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) { ...@@ -407,6 +441,60 @@ void PeopleHandler::HandleSetDatatypes(const base::ListValue* args) {
ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE); ProfileMetrics::LogProfileSyncInfo(ProfileMetrics::SYNC_CHOOSE);
} }
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
void PeopleHandler::HandleGetStoredAccounts(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
const base::Value* callback_id;
CHECK(args->Get(0, &callback_id));
ResolveJavascriptCallback(*callback_id, *GetStoredAccountsList());
}
void PeopleHandler::OnAccountUpdated(const AccountInfo& info) {
FireWebUIListener("stored-accounts-updated", *GetStoredAccountsList());
}
void PeopleHandler::OnAccountRemoved(const AccountInfo& info) {
FireWebUIListener("stored-accounts-updated", *GetStoredAccountsList());
}
std::unique_ptr<base::ListValue> PeopleHandler::GetStoredAccountsList() {
std::vector<AccountInfo> accounts =
signin_ui_util::GetAccountsForDicePromos(profile_);
std::unique_ptr<base::ListValue> accounts_list(new base::ListValue);
accounts_list->Reserve(accounts.size());
for (auto const& account : accounts) {
accounts_list->GetList().push_back(
base::Value(base::Value::Type::DICTIONARY));
base::Value& acc = accounts_list->GetList().back();
acc.SetKey("email", base::Value(account.email));
acc.SetKey("fullName", base::Value(account.full_name));
// TODO(scottchen): should return account.picture_url as encoded image.
acc.SetKey("image", base::Value(profiles::GetPlaceholderAvatarIconUrl()));
}
return accounts_list;
}
void PeopleHandler::HandleStartSyncingWithEmail(const base::ListValue* args) {
const base::Value* email;
CHECK(args->Get(0, &email));
Browser* browser =
chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
AccountTrackerService* account_tracker =
AccountTrackerServiceFactory::GetForProfile(profile_);
AccountInfo account =
account_tracker->FindAccountInfoByEmail(email->GetString());
signin_ui_util::EnableSync(
browser, account, signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS);
}
#endif
void PeopleHandler::HandleSetEncryption(const base::ListValue* args) { void PeopleHandler::HandleSetEncryption(const base::ListValue* args) {
DCHECK(!sync_startup_tracker_); DCHECK(!sync_startup_tracker_);
...@@ -786,7 +874,6 @@ PeopleHandler::GetSyncStatusDictionary() { ...@@ -786,7 +874,6 @@ PeopleHandler::GetSyncStatusDictionary() {
signin_ui_util::GetAuthenticatedUsername(signin)); signin_ui_util::GetAuthenticatedUsername(signin));
sync_status->SetBoolean("hasUnrecoverableError", sync_status->SetBoolean("hasUnrecoverableError",
service && service->HasUnrecoverableError()); service && service->HasUnrecoverableError());
return sync_status; return sync_status;
} }
......
...@@ -14,13 +14,19 @@ ...@@ -14,13 +14,19 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/sync/sync_startup_tracker.h" #include "chrome/browser/sync/sync_startup_tracker.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h" #include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/signin/core/browser/signin_features.h"
#include "components/signin/core/browser/signin_manager_base.h" #include "components/signin/core/browser/signin_manager_base.h"
#include "components/sync/driver/sync_service_observer.h" #include "components/sync/driver/sync_service_observer.h"
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
#include "components/signin/core/browser/account_tracker_service.h"
#endif
class LoginUIService; class LoginUIService;
class SigninManagerBase; class SigninManagerBase;
...@@ -45,6 +51,9 @@ namespace settings { ...@@ -45,6 +51,9 @@ namespace settings {
class PeopleHandler : public SettingsPageUIHandler, class PeopleHandler : public SettingsPageUIHandler,
public SigninManagerBase::Observer, public SigninManagerBase::Observer,
public SyncStartupTracker::Observer, public SyncStartupTracker::Observer,
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
public AccountTrackerService::Observer,
#endif
public LoginUIService::LoginUI, public LoginUIService::LoginUI,
public syncer::SyncServiceObserver { public syncer::SyncServiceObserver {
public: public:
...@@ -122,6 +131,12 @@ class PeopleHandler : public SettingsPageUIHandler, ...@@ -122,6 +131,12 @@ class PeopleHandler : public SettingsPageUIHandler,
// syncer::SyncServiceObserver implementation. // syncer::SyncServiceObserver implementation.
void OnStateChanged(syncer::SyncService* sync) override; void OnStateChanged(syncer::SyncService* sync) override;
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
// AccountTrackerService::Observer implementation.
void OnAccountUpdated(const AccountInfo& info) override;
void OnAccountRemoved(const AccountInfo& info) override;
#endif
// Returns a newly created dictionary with a number of properties that // Returns a newly created dictionary with a number of properties that
// correspond to the status of sync. // correspond to the status of sync.
std::unique_ptr<base::DictionaryValue> GetSyncStatusDictionary(); std::unique_ptr<base::DictionaryValue> GetSyncStatusDictionary();
...@@ -155,6 +170,12 @@ class PeopleHandler : public SettingsPageUIHandler, ...@@ -155,6 +170,12 @@ class PeopleHandler : public SettingsPageUIHandler,
signin_metrics::AccessPoint access_point); signin_metrics::AccessPoint access_point);
#endif #endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
void HandleGetStoredAccounts(const base::ListValue* args);
void HandleStartSyncingWithEmail(const base::ListValue* args);
std::unique_ptr<base::ListValue> GetStoredAccountsList();
#endif
// Displays spinner-only UI indicating that something is going on in the // Displays spinner-only UI indicating that something is going on in the
// background. // background.
// TODO(kochi): better to show some message that the user can understand what // TODO(kochi): better to show some message that the user can understand what
...@@ -211,6 +232,11 @@ class PeopleHandler : public SettingsPageUIHandler, ...@@ -211,6 +232,11 @@ class PeopleHandler : public SettingsPageUIHandler,
ScopedObserver<browser_sync::ProfileSyncService, PeopleHandler> ScopedObserver<browser_sync::ProfileSyncService, PeopleHandler>
sync_service_observer_; sync_service_observer_;
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
ScopedObserver<AccountTrackerService, PeopleHandler>
account_tracker_observer_;
#endif
DISALLOW_COPY_AND_ASSIGN(PeopleHandler); DISALLOW_COPY_AND_ASSIGN(PeopleHandler);
}; };
......
...@@ -7,6 +7,7 @@ class TestSyncBrowserProxy extends TestBrowserProxy { ...@@ -7,6 +7,7 @@ class TestSyncBrowserProxy extends TestBrowserProxy {
constructor() { constructor() {
super([ super([
'getSyncStatus', 'getSyncStatus',
'getStoredAccounts',
'signOut', 'signOut',
]); ]);
} }
...@@ -20,6 +21,12 @@ class TestSyncBrowserProxy extends TestBrowserProxy { ...@@ -20,6 +21,12 @@ class TestSyncBrowserProxy extends TestBrowserProxy {
}); });
} }
/** @override */
getStoredAccounts() {
this.methodCalled('getStoredAccounts');
return Promise.resolve([]);
}
/** @override */ /** @override */
signOut(deleteProfile) { signOut(deleteProfile) {
this.methodCalled('signOut', deleteProfile); this.methodCalled('signOut', deleteProfile);
......
...@@ -204,12 +204,12 @@ void AccountTrackerService::StartTrackingAccount( ...@@ -204,12 +204,12 @@ void AccountTrackerService::StartTrackingAccount(
void AccountTrackerService::StopTrackingAccount(const std::string& account_id) { void AccountTrackerService::StopTrackingAccount(const std::string& account_id) {
DVLOG(1) << "StopTracking " << account_id; DVLOG(1) << "StopTracking " << account_id;
if (base::ContainsKey(accounts_, account_id)) { if (base::ContainsKey(accounts_, account_id)) {
AccountState& state = accounts_[account_id]; AccountState state = std::move(accounts_[account_id]);
RemoveFromPrefs(state); RemoveFromPrefs(state);
accounts_.erase(account_id);
if (!state.info.gaia.empty()) if (!state.info.gaia.empty())
NotifyAccountRemoved(state); NotifyAccountRemoved(state);
accounts_.erase(account_id);
} }
} }
......
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