Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/resources/settings/people_page/sync_private_api.js

Issue 1536593004: Settings People Revamp: Implement Chrome Profile name/icon selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.exportPath('settings'); 5 cr.exportPath('settings');
6 6
7 /** 7 /**
8 * The state of sync. This is the data structure sent back and forth between 8 * The state of sync. This is the data structure sent back and forth between
9 * C++ and JS. Its naming and structure is not optimal, but changing it would 9 * C++ and JS. Its naming and structure is not optimal, but changing it would
10 * require changes to the C++ handler, which is already functional. 10 * require changes to the C++ handler, which is already functional.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 * wifiCredentialsSynced: (boolean|undefined) 52 * wifiCredentialsSynced: (boolean|undefined)
53 * }} 53 * }}
54 */ 54 */
55 settings.SyncPrefs; 55 settings.SyncPrefs;
56 56
57 /** 57 /**
58 * @typedef {{actionLinkText: (string|undefined), 58 * @typedef {{actionLinkText: (string|undefined),
59 * childUser: (boolean|undefined), 59 * childUser: (boolean|undefined),
60 * hasError: (boolean|undefined), 60 * hasError: (boolean|undefined),
61 * hasUnrecoverableError: (boolean|undefined), 61 * hasUnrecoverableError: (boolean|undefined),
62 * iconURL: (string|undefined),
63 * managed: (boolean|undefined), 62 * managed: (boolean|undefined),
64 * name: (string|undefined),
65 * setupCompleted: (boolean|undefined), 63 * setupCompleted: (boolean|undefined),
66 * setupInProgress: (boolean|undefined), 64 * setupInProgress: (boolean|undefined),
67 * signedIn: (boolean|undefined), 65 * signedIn: (boolean|undefined),
68 * signinAllowed: (boolean|undefined), 66 * signinAllowed: (boolean|undefined),
69 * signoutAllowed: (boolean|undefined), 67 * signoutAllowed: (boolean|undefined),
70 * statusText: (string|undefined), 68 * statusText: (string|undefined),
71 * supervisedUser: (boolean|undefined), 69 * supervisedUser: (boolean|undefined),
72 * syncSystemEnabled: (boolean|undefined)}} 70 * syncSystemEnabled: (boolean|undefined)}}
73 * @see chrome/browser/ui/webui/settings/sync_handler.cc 71 * @see chrome/browser/ui/webui/settings/sync_handler.cc
74 */ 72 */
(...skipping 10 matching lines...) Expand all
85 PASSPHRASE_ERROR: 'passphraseError', // Error in the passphrase. 83 PASSPHRASE_ERROR: 'passphraseError', // Error in the passphrase.
86 }; 84 };
87 85
88 cr.define('settings', function() { 86 cr.define('settings', function() {
89 /** 87 /**
90 * API which encapsulates messaging between JS and C++ for the sync page. 88 * API which encapsulates messaging between JS and C++ for the sync page.
91 * @constructor 89 * @constructor
92 */ 90 */
93 function SyncPrivateApi() {} 91 function SyncPrivateApi() {}
94 92
93 /** @private {?function(!string, !string)} */
94 SyncPrivateApi.getProfileInfoCallback_ = null;
95
96 /** @private {?function(!Array<string>)} */
97 SyncPrivateApi.getAvailableIconsCallback_ = null;
98
95 /** @private {?function(settings.SyncPrefs)} */ 99 /** @private {?function(settings.SyncPrefs)} */
96 SyncPrivateApi.syncPrefsCallback_ = null; 100 SyncPrivateApi.syncPrefsCallback_ = null;
97 101
98 /** @private {?function(settings.PageStatus)} */ 102 /** @private {?function(settings.PageStatus)} */
99 SyncPrivateApi.setPageStatusCallback_ = null; 103 SyncPrivateApi.setPageStatusCallback_ = null;
100 104
101 /** 105 /**
106 * Called from JavaScript. Gets the current profile name and icon.
107 * @param {?function(!string, !string)} callback
108 */
109 SyncPrivateApi.getProfileInfo = function(callback) {
110 SyncPrivateApi.getProfileInfoCallback_ = callback;
111 chrome.send('getProfileInfo');
112 };
113
114 /**
115 * Called from C++ as a response to getIconsAndNames.
116 * @param {!string} name The current profile name.
117 * @param {!string} iconUrl The current profile icon's URL. Can be a data URL.
118 */
119 SyncPrivateApi.receiveProfileInfo = function(name, iconUrl) {
120 if (SyncPrivateApi.getProfileInfoCallback_)
121 SyncPrivateApi.getProfileInfoCallback_(name, iconUrl);
122 };
123
124 /**
125 * Called from JavaScript. Gets the available profile icons to choose from.
126 * @param {!function(!Array<string>)} callback
127 */
128 SyncPrivateApi.getAvailableIcons = function(callback) {
129 SyncPrivateApi.getAvailableIconsCallback_ = callback;
130 chrome.send('requestDefaultProfileIcons');
131 };
132
133 /**
134 * Called from C++ as a response to getAvailableIcons.
135 * @param {!Array<string>} iconUrls An array of icon URLs.
136 */
137 SyncPrivateApi.receiveAvailableIcons = function(iconUrls) {
138 if (SyncPrivateApi.getAvailableIconsCallback_)
139 SyncPrivateApi.getAvailableIconsCallback_(iconUrls);
140 };
141
142 /**
143 * Called from JavaScript. Sets the profile icon and name.
144 * @param {!string} iconUrl The new profile URL.
145 * @param {!string} name The new profile name.
146 */
147 SyncPrivateApi.setProfileIconAndName = function(iconUrl, name) {
148 chrome.send('setProfileIconAndName', [iconUrl, name]);
149 };
150
151 /**
102 * Starts the signin process for the user. Does nothing if the user is 152 * Starts the signin process for the user. Does nothing if the user is
103 * already signed in. 153 * already signed in.
104 * @private 154 * @private
105 */ 155 */
106 SyncPrivateApi.startSignIn = function() { 156 SyncPrivateApi.startSignIn = function() {
107 chrome.send('SyncSetupStartSignIn'); 157 chrome.send('syncSetupStartSignIn');
108 }; 158 };
109 159
110 /** 160 /**
111 * Disconnects the signed in user. 161 * Disconnects the signed in user.
112 * @param {!boolean} deleteProfile 162 * @param {!boolean} deleteProfile
113 * @private 163 * @private
114 */ 164 */
115 SyncPrivateApi.disconnect = function(deleteProfile) { 165 SyncPrivateApi.disconnect = function(deleteProfile) {
116 chrome.send('SyncSetupStopSyncing', [deleteProfile]); 166 chrome.send('syncSetupStopSyncing', [deleteProfile]);
117 }; 167 };
118 168
119 /** 169 /**
120 * Determines the appropriate page to show in the Sync Setup UI based on 170 * Determines the appropriate page to show in the Sync Setup UI based on
121 * the state of the Sync backend. Does nothing if the user is not signed in. 171 * the state of the Sync backend. Does nothing if the user is not signed in.
122 * @private 172 * @private
123 */ 173 */
124 SyncPrivateApi.showSetupUI = function() { 174 SyncPrivateApi.showSetupUI = function() {
125 chrome.send('SyncSetupShowSetupUI'); 175 chrome.send('syncSetupShowSetupUI');
126 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowSyncAdvanced']); 176 chrome.send('coreOptionsUserMetricsAction', ['Options_ShowSyncAdvanced']);
127 }; 177 };
128 178
129 /** 179 /**
130 * Function to invoke when the sync page has been navigated to. This registers 180 * Function to invoke when the sync page has been navigated to. This registers
131 * the UI as the "active" sync UI so that if the user tries to open another 181 * the UI as the "active" sync UI so that if the user tries to open another
132 * sync UI, this one will be shown instead. 182 * sync UI, this one will be shown instead.
133 */ 183 */
134 SyncPrivateApi.didNavigateToSyncPage = function() { 184 SyncPrivateApi.didNavigateToSyncPage = function() {
135 chrome.send('SyncSetupShowSetupUI'); 185 chrome.send('syncSetupShowSetupUI');
136 }; 186 };
137 187
138 /** 188 /**
139 * Function to invoke when leaving the sync page so that the C++ layer can be 189 * Function to invoke when leaving the sync page so that the C++ layer can be
140 * notified that the sync UI is no longer open. 190 * notified that the sync UI is no longer open.
141 */ 191 */
142 SyncPrivateApi.didNavigateAwayFromSyncPage = function() { 192 SyncPrivateApi.didNavigateAwayFromSyncPage = function() {
143 SyncPrivateApi.setPageStatusCallback_ = null; 193 SyncPrivateApi.setPageStatusCallback_ = null;
144 chrome.send('SyncSetupDidClosePage'); 194 chrome.send('syncSetupDidClosePage');
145 }; 195 };
146 196
147 /** 197 /**
148 * Sets the callback to be invoked when sync data has been fetched. 198 * Sets the callback to be invoked when sync data has been fetched.
149 * @param {!function(settings.SyncPrefs)} callback 199 * @param {!function(settings.SyncPrefs)} callback
150 */ 200 */
151 SyncPrivateApi.setSyncPrefsCallback = function(callback) { 201 SyncPrivateApi.setSyncPrefsCallback = function(callback) {
152 SyncPrivateApi.syncPrefsCallback_ = callback; 202 SyncPrivateApi.syncPrefsCallback_ = callback;
153 }; 203 };
154 204
155 /** 205 /**
156 * Handler for when state has been fetched from C++. 206 * Handler for when state has been fetched from C++.
157 * @param {!settings.SyncPrefs} syncPrefsFromCpp 207 * @param {!settings.SyncPrefs} syncPrefsFromCpp
158 * @private 208 * @private
159 */ 209 */
160 SyncPrivateApi.sendSyncPrefs_ = function(syncPrefsFromCpp) { 210 SyncPrivateApi.sendSyncPrefs_ = function(syncPrefsFromCpp) {
161 if (SyncPrivateApi.syncPrefsCallback_) 211 if (SyncPrivateApi.syncPrefsCallback_)
162 SyncPrivateApi.syncPrefsCallback_(syncPrefsFromCpp); 212 SyncPrivateApi.syncPrefsCallback_(syncPrefsFromCpp);
163 }; 213 };
164 214
165 /** 215 /**
166 * Sets the sync state by sending it to the C++ layer. 216 * Sets the sync state by sending it to the C++ layer.
167 * @param {!settings.SyncPrefs} syncPrefs 217 * @param {!settings.SyncPrefs} syncPrefs
168 * @param {!function(settings.PageStatus)} callback 218 * @param {!function(settings.PageStatus)} callback
169 */ 219 */
170 SyncPrivateApi.setSyncPrefs = function(syncPrefs, callback) { 220 SyncPrivateApi.setSyncPrefs = function(syncPrefs, callback) {
171 SyncPrivateApi.setPageStatusCallback_ = callback; 221 SyncPrivateApi.setPageStatusCallback_ = callback;
172 chrome.send('SyncSetupConfigure', [JSON.stringify(syncPrefs)]); 222 chrome.send('syncSetupConfigure', [JSON.stringify(syncPrefs)]);
173 }; 223 };
174 224
175 /** 225 /**
176 * Handler for when setSyncPrefs() has either succeeded or failed. 226 * Handler for when setSyncPrefs() has either succeeded or failed.
177 * @param {!settings.PageStatus} status 227 * @param {!settings.PageStatus} status
178 * @private 228 * @private
179 */ 229 */
180 SyncPrivateApi.setPageStatus_ = function(status) { 230 SyncPrivateApi.setPageStatus_ = function(status) {
181 if (SyncPrivateApi.setPageStatusCallback_) 231 if (SyncPrivateApi.setPageStatusCallback_)
182 SyncPrivateApi.setPageStatusCallback_(status); 232 SyncPrivateApi.setPageStatusCallback_(status);
183 233
184 SyncPrivateApi.setPageStatusCallback_ = null; 234 SyncPrivateApi.setPageStatusCallback_ = null;
185 }; 235 };
186 236
187 /** 237 /**
188 * Sends a request from JS to C++ for the current sync status. 238 * Sends a request from JS to C++ for the current sync status.
189 * @param {!function(settings.SyncStatus)} callback 239 * @param {!function(settings.SyncStatus)} callback
190 */ 240 */
191 SyncPrivateApi.getSyncStatus = function(callback) { 241 SyncPrivateApi.getSyncStatus = function(callback) {
192 SyncPrivateApi.syncStatusCallback_ = callback; 242 SyncPrivateApi.syncStatusCallback_ = callback;
193 chrome.send('SyncSetupGetSyncStatus'); 243 chrome.send('syncSetupGetSyncStatus');
194 }; 244 };
195 245
196 /** 246 /**
197 * Handler for when sync status has been fetched from C++. 247 * Handler for when sync status has been fetched from C++.
198 * @param {!settings.SyncStatus} syncStatusFromCpp 248 * @param {!settings.SyncStatus} syncStatusFromCpp
199 * @private 249 * @private
200 */ 250 */
201 SyncPrivateApi.sendSyncStatus = function(syncStatusFromCpp) { 251 SyncPrivateApi.sendSyncStatus = function(syncStatusFromCpp) {
202 if (SyncPrivateApi.syncStatusCallback_) 252 if (SyncPrivateApi.syncStatusCallback_)
203 SyncPrivateApi.syncStatusCallback_(syncStatusFromCpp); 253 SyncPrivateApi.syncStatusCallback_(syncStatusFromCpp);
204 }; 254 };
205 255
206 /** 256 /**
207 * Sends a request from JS to C++ to open the multi-profile User Manager. 257 * Sends a request from JS to C++ to open the multi-profile User Manager.
208 */ 258 */
209 SyncPrivateApi.manageOtherPeople = function() { 259 SyncPrivateApi.manageOtherPeople = function() {
210 chrome.send('SyncSetupManageOtherPeople'); 260 chrome.send('syncSetupManageOtherPeople');
Dan Beam 2016/01/07 02:41:20 arguably do in a separate patch
tommycli 2016/01/07 22:08:23 Done.
211 }; 261 };
212 262
213 /** 263 /**
214 * This function encapsulates the logic that maps from the legacy 264 * This function encapsulates the logic that maps from the legacy
215 * SyncSettingsHandler to an API natural to the new Polymer implementation. 265 * SyncSettingsHandler to an API natural to the new Polymer implementation.
216 * @param {!settings.PageStatus} status 266 * @param {!settings.PageStatus} status
217 * @param {!settings.SyncPrefs} prefs 267 * @param {!settings.SyncPrefs} prefs
218 */ 268 */
219 SyncPrivateApi.showSyncSetupPage = function(status, prefs) { 269 SyncPrivateApi.showSyncSetupPage = function(status, prefs) {
220 switch (status) { 270 switch (status) {
(...skipping 12 matching lines...) Expand all
233 break; 283 break;
234 default: 284 default:
235 // Other statuses (i.e. "spinner") are ignored. 285 // Other statuses (i.e. "spinner") are ignored.
236 } 286 }
237 }; 287 };
238 288
239 return { 289 return {
240 SyncPrivateApi: SyncPrivateApi, 290 SyncPrivateApi: SyncPrivateApi,
241 }; 291 };
242 }); 292 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698