Chromium Code Reviews| Index: chrome/browser/resources/md_user_manager/profile_api.js |
| diff --git a/chrome/browser/resources/md_user_manager/profile_api.js b/chrome/browser/resources/md_user_manager/profile_api.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..544fef55d9c3770c84141e5f7b76abc4863b1576 |
| --- /dev/null |
| +++ b/chrome/browser/resources/md_user_manager/profile_api.js |
| @@ -0,0 +1,131 @@ |
| +/* Copyright 2016 The Chromium Authors. All rights reserved. |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +/** @typedef {{username:(string), profilePath:(string)}} */ |
| +var signedInUser; |
|
Dan Beam
2016/02/12 23:42:24
SignedInUser
Moe
2016/02/20 00:20:59
Done.
|
| + |
| +/** @typedef {{name:(string), filePath:(string), isSupervised:(boolean)}} */ |
| +var profileInfo; |
|
Dan Beam
2016/02/12 23:42:24
ProfileInfo
Moe
2016/02/20 00:20:59
Done.
|
| + |
| +cr.define('signin', function() { |
| + /** |
| + * API that encapsulates messaging between JS and C++ for creating/importing |
| + * profiles in the user-manager page. |
| + * @constructor |
| + */ |
| + function ProfileApi() {} |
| + |
| + /** @private {?function(!Array<string>)} */ |
| + ProfileApi.getAvailableIconsCallback_ = null; |
| + |
| + /** @private {?function(!Array<signedInUser>)} */ |
| + ProfileApi.getSignedInUsersCallback_ = null; |
| + |
| + /** @private {?function(!string)} */ |
| + ProfileApi.profileCreateErrorCallback_ = null; |
| + |
| + /** @private {?function(!string)} */ |
| + ProfileApi.profileCreateWarningCallback_ = null; |
| + |
| + /** @private {?function(!profileInfo)} */ |
| + ProfileApi.profileCreateSuccessCallback_ = null; |
|
Dan Beam
2016/02/12 23:42:24
why are you using globals? this means that async
Moe
2016/02/20 00:20:59
I followed the pattern used in sync_private_api.js
|
| + |
| + /** |
| + * Sets the profile create success callback. |
| + * @param {?function(!profileInfo)} callback |
| + */ |
| + ProfileApi.setProfileCreateSuccessCallback = function(callback) { |
| + ProfileApi.profileCreateSuccessCallback_ = callback; |
| + }; |
| + |
| + /** |
| + * Sets the profile create warning callback. |
| + * @param {?function(!string)} callback |
| + */ |
| + ProfileApi.setProfileCreateWarningCallback = function(callback) { |
| + ProfileApi.profileCreateWarningCallback_ = callback; |
| + }; |
| + |
| + /** |
| + * Sets the profile create error callback. |
| + * @param {?function(!string)} callback |
| + */ |
| + ProfileApi.setProfileCreateErrorCallback = function(callback) { |
| + ProfileApi.profileCreateErrorCallback_ = callback; |
| + }; |
| + |
| + /** |
| + * Called from JavaScript. Gets the available profile icons to choose from. |
| + * {!function(!Array<string>)} callback |
| + */ |
| + ProfileApi.getAvailableIcons = function(callback) { |
| + ProfileApi.getAvailableIconsCallback_ = callback; |
| + chrome.send('requestDefaultProfileIcons'); |
| + }; |
| + |
| + /** |
| + * Called from JavaScript. Gets the current signed-in users. |
| + * {!function(!Array<string>)} callback |
| + */ |
| + ProfileApi.getSignedInUsers = function(callback) { |
| + ProfileApi.getSignedInUsersCallback_ = callback; |
| + chrome.send('requestSignedInProfiles'); |
| + }; |
| + |
| + /** |
| + * Called from C++ as a response to getAvailableIcons. |
| + * @param {!Array<string>} iconUrls An array of icon URLs. |
| + * @private |
| + */ |
| + ProfileApi.updateAvailableIcons = function(iconUrls) { |
| + if (ProfileApi.getAvailableIconsCallback_) |
| + ProfileApi.getAvailableIconsCallback_(iconUrls); |
| + }; |
| + |
| + /** |
| + * Called from C++ in response to 'requestSignedInProfiles'. |
| + * @param {!Array<signedInUser>} signedInUsers An array of email addresses of |
| + * signed in users and the corresponding profile path. |
| + * @private |
| + */ |
| + ProfileApi.updateSignedInUsers = function(signedInUsers) { |
| + if (ProfileApi.getSignedInUsersCallback_) |
| + ProfileApi.getSignedInUsersCallback_(signedInUsers); |
| + }; |
| + |
| + /** |
| + * Called from C++ to report supervised profile create errors. |
| + * @param {string} error The error raised while creating a profile. |
| + * @private |
| + */ |
| + ProfileApi.onCreateProfileError = function(error) { |
| + if (ProfileApi.profileCreateErrorCallback_) |
| + ProfileApi.profileCreateErrorCallback_(error); |
| + }; |
| + |
| + /** |
| + * Called from C++ to report supervised profile create warnings. |
| + * @param {string} warning The warning issued while creating a profile. |
| + * @private |
| + */ |
| + ProfileApi.onCreateProfileWarning = function(warning) { |
| + if (ProfileApi.profileCreateWarningCallback_) |
| + ProfileApi.profileCreateWarningCallback_(warning); |
| + }; |
| + |
| + /** |
| + * Called from C++ to report successful creation of a profile. |
| + * @param {!profileInfo} profileInfo |
| + * @private |
| + */ |
| + ProfileApi.onCreateProfileSuccess = function(profileInfo) { |
| + if (ProfileApi.profileCreateSuccessCallback_) |
| + ProfileApi.profileCreateSuccessCallback_(profileInfo); |
| + }; |
| + |
| + return { |
| + ProfileApi: ProfileApi, |
| + }; |
| +}); |