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

Side by Side Diff: chrome/browser/resources/options/supervised_user_list_data.js

Issue 403343002: Rename "managed (mode|user)" to "supervised user" (part 8) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.define('options', function() { 5 cr.define('options', function() {
6 /** 6 /**
7 * ManagedUserListData class. 7 * SupervisedUserListData class.
8 * Handles requests for retrieving a list of existing managed users which are 8 * Handles requests for retrieving a list of existing supervised users which
9 * supervised by the current profile. For each request a promise is returned, 9 * are supervised by the current profile. For each request a promise is
10 * which is cached in order to reuse the retrieved managed users for future 10 * returned, which is cached in order to reuse the retrieved supervised users
11 * requests. The first request will be handled asynchronously. 11 * for future requests. The first request will be handled asynchronously.
12 * @constructor 12 * @constructor
13 * @class 13 * @class
14 */ 14 */
15 function ManagedUserListData() { 15 function SupervisedUserListData() {
16 this.observers_ = []; 16 this.observers_ = [];
17 }; 17 };
18 18
19 cr.addSingletonGetter(ManagedUserListData); 19 cr.addSingletonGetter(SupervisedUserListData);
20 20
21 /** 21 /**
22 * Receives a list of managed users and resolves the promise. 22 * Receives a list of supervised users and resolves the promise.
23 * @param {Array.<Object>} managedUsers An array of managed user objects. 23 * @param {Array.<Object>} supervisedUsers Array of supervised user objects.
24 * Each object is of the form: 24 * Each object is of the form:
25 * managedUser = { 25 * supervisedUser = {
26 * id: "Managed User ID", 26 * id: "Supervised User ID",
27 * name: "Managed User Name", 27 * name: "Supervised User Name",
28 * iconURL: "chrome://path/to/icon/image", 28 * iconURL: "chrome://path/to/icon/image",
29 * onCurrentDevice: true or false, 29 * onCurrentDevice: true or false,
30 * needAvatar: true or false 30 * needAvatar: true or false
31 * } 31 * }
32 * @private 32 * @private
33 */ 33 */
34 ManagedUserListData.prototype.receiveExistingManagedUsers_ = function( 34 SupervisedUserListData.prototype.receiveExistingSupervisedUsers_ = function(
35 managedUsers) { 35 supervisedUsers) {
36 if (!this.promise_) { 36 if (!this.promise_) {
37 this.onDataChanged_(managedUsers); 37 this.onDataChanged_(supervisedUsers);
38 return; 38 return;
39 } 39 }
40 this.resolve_(managedUsers); 40 this.resolve_(supervisedUsers);
41 }; 41 };
42 42
43 /** 43 /**
44 * Called when there is a signin error when retrieving the list of managed 44 * Called when there is a signin error when retrieving the list of supervised
45 * users. Rejects the promise and resets the cached promise to null. 45 * users. Rejects the promise and resets the cached promise to null.
46 * @private 46 * @private
47 */ 47 */
48 ManagedUserListData.prototype.onSigninError_ = function() { 48 SupervisedUserListData.prototype.onSigninError_ = function() {
49 assert(this.promise_); 49 assert(this.promise_);
50 this.reject_(); 50 this.reject_();
51 this.resetPromise_(); 51 this.resetPromise_();
52 }; 52 };
53 53
54 /** 54 /**
55 * Handles the request for the list of existing managed users by returning a 55 * Handles the request for the list of existing supervised users by returning
56 * promise for the requested data. If there is no cached promise yet, a new 56 * a promise for the requested data. If there is no cached promise yet, a new
57 * one will be created. 57 * one will be created.
58 * @return {Promise} The promise containing the list of managed users. 58 * @return {Promise} The promise containing the list of supervised users.
59 * @private 59 * @private
60 */ 60 */
61 ManagedUserListData.prototype.requestExistingManagedUsers_ = function() { 61 SupervisedUserListData.prototype.requestExistingSupervisedUsers_ =
62 function() {
62 if (this.promise_) 63 if (this.promise_)
63 return this.promise_; 64 return this.promise_;
64 this.promise_ = this.createPromise_(); 65 this.promise_ = this.createPromise_();
65 chrome.send('requestManagedUserImportUpdate'); 66 chrome.send('requestSupervisedUserImportUpdate');
66 return this.promise_; 67 return this.promise_;
67 }; 68 };
68 69
69 /** 70 /**
70 * Creates the promise containing the list of managed users. The promise is 71 * Creates the promise containing the list of supervised users. The promise is
71 * resolved in receiveExistingManagedUsers_() or rejected in 72 * resolved in receiveExistingSupervisedUsers_() or rejected in
72 * onSigninError_(). The promise is cached, so that for future requests it can 73 * onSigninError_(). The promise is cached, so that for future requests it can
73 * be resolved immediately. 74 * be resolved immediately.
74 * @return {Promise} The promise containing the list of managed users. 75 * @return {Promise} The promise containing the list of supervised users.
75 * @private 76 * @private
76 */ 77 */
77 ManagedUserListData.prototype.createPromise_ = function() { 78 SupervisedUserListData.prototype.createPromise_ = function() {
78 var self = this; 79 var self = this;
79 return new Promise(function(resolve, reject) { 80 return new Promise(function(resolve, reject) {
80 self.resolve_ = resolve; 81 self.resolve_ = resolve;
81 self.reject_ = reject; 82 self.reject_ = reject;
82 }); 83 });
83 }; 84 };
84 85
85 /** 86 /**
86 * Resets the promise to null in order to avoid stale data. For the next 87 * Resets the promise to null in order to avoid stale data. For the next
87 * request, a new promise will be created. 88 * request, a new promise will be created.
88 * @private 89 * @private
89 */ 90 */
90 ManagedUserListData.prototype.resetPromise_ = function() { 91 SupervisedUserListData.prototype.resetPromise_ = function() {
91 this.promise_ = null; 92 this.promise_ = null;
92 }; 93 };
93 94
94 /** 95 /**
95 * Initializes |promise| with the new data and also passes the new data to 96 * Initializes |promise| with the new data and also passes the new data to
96 * observers. 97 * observers.
97 * @param {Array.<Object>} managedUsers An array of managed user objects. 98 * @param {Array.<Object>} supervisedUsers Array of supervised user objects.
98 * For the format of the objects, see receiveExistingManagedUsers_(). 99 * For the format of the objects, see receiveExistingSupervisedUsers_().
99 * @private 100 * @private
100 */ 101 */
101 ManagedUserListData.prototype.onDataChanged_ = function(managedUsers) { 102 SupervisedUserListData.prototype.onDataChanged_ = function(supervisedUsers) {
102 this.promise_ = this.createPromise_(); 103 this.promise_ = this.createPromise_();
103 this.resolve_(managedUsers); 104 this.resolve_(supervisedUsers);
104 for (var i = 0; i < this.observers_.length; ++i) 105 for (var i = 0; i < this.observers_.length; ++i)
105 this.observers_[i].receiveExistingManagedUsers_(managedUsers); 106 this.observers_[i].receiveExistingSupervisedUsers_(supervisedUsers);
106 }; 107 };
107 108
108 /** 109 /**
109 * Adds an observer to the list of observers. 110 * Adds an observer to the list of observers.
110 * @param {Object} observer The observer to be added. 111 * @param {Object} observer The observer to be added.
111 * @private 112 * @private
112 */ 113 */
113 ManagedUserListData.prototype.addObserver_ = function(observer) { 114 SupervisedUserListData.prototype.addObserver_ = function(observer) {
114 for (var i = 0; i < this.observers_.length; ++i) 115 for (var i = 0; i < this.observers_.length; ++i)
115 assert(this.observers_[i] != observer); 116 assert(this.observers_[i] != observer);
116 this.observers_.push(observer); 117 this.observers_.push(observer);
117 }; 118 };
118 119
119 /** 120 /**
120 * Removes an observer from the list of observers. 121 * Removes an observer from the list of observers.
121 * @param {Object} observer The observer to be removed. 122 * @param {Object} observer The observer to be removed.
122 * @private 123 * @private
123 */ 124 */
124 ManagedUserListData.prototype.removeObserver_ = function(observer) { 125 SupervisedUserListData.prototype.removeObserver_ = function(observer) {
125 for (var i = 0; i < this.observers_.length; ++i) { 126 for (var i = 0; i < this.observers_.length; ++i) {
126 if (this.observers_[i] == observer) { 127 if (this.observers_[i] == observer) {
127 this.observers_.splice(i, 1); 128 this.observers_.splice(i, 1);
128 return; 129 return;
129 } 130 }
130 } 131 }
131 }; 132 };
132 133
133 // Forward public APIs to private implementations. 134 // Forward public APIs to private implementations.
134 [ 135 [
135 'addObserver', 136 'addObserver',
136 'onSigninError', 137 'onSigninError',
137 'receiveExistingManagedUsers', 138 'receiveExistingSupervisedUsers',
138 'removeObserver', 139 'removeObserver',
139 'requestExistingManagedUsers', 140 'requestExistingSupervisedUsers',
140 'resetPromise', 141 'resetPromise',
141 ].forEach(function(name) { 142 ].forEach(function(name) {
142 ManagedUserListData[name] = function() { 143 SupervisedUserListData[name] = function() {
143 var instance = ManagedUserListData.getInstance(); 144 var instance = SupervisedUserListData.getInstance();
144 return instance[name + '_'].apply(instance, arguments); 145 return instance[name + '_'].apply(instance, arguments);
145 }; 146 };
146 }); 147 });
147 148
148 // Export 149 // Export
149 return { 150 return {
150 ManagedUserListData: ManagedUserListData, 151 SupervisedUserListData: SupervisedUserListData,
151 }; 152 };
152 }); 153 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698