Chromium Code Reviews| Index: chrome/browser/resources/options/managed_user_list_data.js |
| diff --git a/chrome/browser/resources/options/managed_user_list_data.js b/chrome/browser/resources/options/managed_user_list_data.js |
| index cae63d59a5d72864b28da5724563f944782b6510..d7cdc0c53f502968e0c3f9fdb94b67c4744048d6 100644 |
| --- a/chrome/browser/resources/options/managed_user_list_data.js |
| +++ b/chrome/browser/resources/options/managed_user_list_data.js |
| @@ -12,6 +12,7 @@ cr.define('options', function() { |
| * @constructor |
| * @class |
| */ |
| + // TODO(akuegel): Refactor this class by using dom promises. |
| function ManagedUserListData() { |
| this.callbacks_ = []; |
| this.errbacks_ = []; |
| @@ -41,33 +42,31 @@ cr.define('options', function() { |
| * name: "Managed User Name", |
| * iconURL: "chrome://path/to/icon/image", |
| * onCurrentDevice: true or false, |
| + * nameConflict: true or false, |
| * needAvatar: true or false |
| * } |
| + * @private |
| */ |
| - ManagedUserListData.receiveExistingManagedUsers = function(managedUsers) { |
| - var instance = ManagedUserListData.getInstance(); |
| - var i; |
| - for (i = 0; i < instance.callbacks_.length; i++) { |
| - instance.callbacks_[i](managedUsers); |
| - } |
| - instance.managedUsers_ = managedUsers; |
| - instance.reset_(); |
| + ManagedUserListData.prototype.receiveExistingManagedUsers_ = function( |
| + managedUsers) { |
| + for (var i = 0; i < this.callbacks_.length; i++) |
| + this.callbacks_[i](managedUsers); |
| + this.managedUsers_ = managedUsers; |
| + this.reset_(); |
| }; |
| /** |
| * Called when there is a signin error when retrieving the list of managed |
| * users. Calls the error callbacks which will display an appropriate error |
| * message to the user. |
| + * @private |
| */ |
| - ManagedUserListData.onSigninError = function() { |
| - var instance = ManagedUserListData.getInstance(); |
| - var i; |
| - for (i = 0; i < instance.errbacks_.length; i++) { |
| - instance.errbacks_[i](); |
| - } |
| + ManagedUserListData.prototype.onSigninError_ = function() { |
| + for (var i = 0; i < this.errbacks_.length; i++) |
| + this.errbacks_[i](); |
| // Reset the list of managed users in order to avoid showing stale data. |
| - instance.managedUsers_ = null; |
| - instance.reset_(); |
| + this.managedUsers_ = null; |
| + this.reset_(); |
| }; |
| /** |
| @@ -77,18 +76,18 @@ cr.define('options', function() { |
| * receiveExistingManagedUsers(). |
| * @param {Object} callback The callback function which is called on success. |
| * @param {Object} errback the callback function which is called on error. |
| + * @private |
| */ |
| - ManagedUserListData.requestExistingManagedUsers = function(callback, |
| - errback) { |
| - var instance = ManagedUserListData.getInstance(); |
| - instance.callbacks_.push(callback); |
| - instance.errbacks_.push(errback); |
| - if (!instance.requestInProgress_) { |
| - if (instance.managedUsers_ != null) { |
| - ManagedUserListData.receiveExistingManagedUsers(instance.managedUsers_); |
| + ManagedUserListData.prototype.requestExistingManagedUsers_ = function( |
| + callback, errback) { |
| + if (!this.requestInProgress_) { |
|
Bernhard Bauer
2014/01/09 16:33:18
Early-return if a request is in progress?
Adrian Kuegel
2014/01/10 09:53:43
This is obsolete now. I already replaced my code w
|
| + if (this.managedUsers_ != null) { |
| + callback(this.managedUsers_); |
| return; |
| } |
| - instance.requestInProgress_ = true; |
| + this.callbacks_.push(callback); |
| + this.errbacks_.push(errback); |
| + this.requestInProgress_ = true; |
| chrome.send('requestManagedUserImportUpdate'); |
| } |
| }; |
| @@ -97,17 +96,30 @@ cr.define('options', function() { |
| * Reload the list of existing managed users. Should be called when a new |
| * supervised user profile was created or a supervised user profile was |
| * deleted. |
| + * @private |
| */ |
| - ManagedUserListData.reloadExistingManagedUsers = function() { |
| - var instance = ManagedUserListData.getInstance(); |
| - if (instance.requestInProgress_) |
| + ManagedUserListData.prototype.reloadExistingManagedUsers_ = function() { |
| + if (this.requestInProgress_) |
| return; |
| - instance.managedUsers_ = null; |
| - instance.requestInProgress_ = true; |
| + this.managedUsers_ = null; |
| + this.requestInProgress_ = true; |
| chrome.send('requestManagedUserImportUpdate'); |
| }; |
| + // Forward public APIs to private implementations. |
| + [ |
| + 'onSigninError', |
| + 'receiveExistingManagedUsers', |
| + 'reloadExistingManagedUsers', |
| + 'requestExistingManagedUsers', |
| + ].forEach(function(name) { |
| + ManagedUserListData[name] = function() { |
| + var instance = ManagedUserListData.getInstance(); |
| + return instance[name + '_'].apply(instance, arguments); |
| + }; |
| + }); |
| + |
| // Export |
| return { |
| ManagedUserListData: ManagedUserListData, |