OLD | NEW |
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 * SupervisedUserListData class. | 7 * SupervisedUserListData class. |
8 * Handles requests for retrieving a list of existing supervised users which | 8 * Handles requests for retrieving a list of existing supervised users which |
9 * are supervised by the current profile. For each request a promise is | 9 * are supervised by the current profile. For each request a promise is |
10 * returned, which is cached in order to reuse the retrieved supervised users | 10 * returned, which is cached in order to reuse the retrieved supervised users |
11 * for future 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 SupervisedUserListData() { | 15 function SupervisedUserListData() { |
16 this.observers_ = []; | 16 this.observers_ = []; |
17 }; | 17 }; |
18 | 18 |
19 cr.addSingletonGetter(SupervisedUserListData); | 19 cr.addSingletonGetter(SupervisedUserListData); |
20 | 20 |
21 /** | 21 /** |
22 * Receives a list of supervised users and resolves the promise. | 22 * Receives a list of supervised users and resolves the promise. |
23 * @param {Array.<Object>} supervisedUsers Array of supervised 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 * supervisedUser = { | 25 * supervisedUser = { |
26 * id: "Supervised User ID", | 26 * id: "Supervised User ID", |
27 * name: "Supervised 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 */ |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 * request, a new promise will be created. | 90 * request, a new promise will be created. |
91 * @private | 91 * @private |
92 */ | 92 */ |
93 SupervisedUserListData.prototype.resetPromise_ = function() { | 93 SupervisedUserListData.prototype.resetPromise_ = function() { |
94 this.promise_ = null; | 94 this.promise_ = null; |
95 }; | 95 }; |
96 | 96 |
97 /** | 97 /** |
98 * Initializes |promise| with the new data and also passes the new data to | 98 * Initializes |promise| with the new data and also passes the new data to |
99 * observers. | 99 * observers. |
100 * @param {Array.<Object>} supervisedUsers Array of supervised user objects. | 100 * @param {Array<Object>} supervisedUsers Array of supervised user objects. |
101 * For the format of the objects, see receiveExistingSupervisedUsers_(). | 101 * For the format of the objects, see receiveExistingSupervisedUsers_(). |
102 * @private | 102 * @private |
103 */ | 103 */ |
104 SupervisedUserListData.prototype.onDataChanged_ = function(supervisedUsers) { | 104 SupervisedUserListData.prototype.onDataChanged_ = function(supervisedUsers) { |
105 this.promise_ = this.createPromise_(); | 105 this.promise_ = this.createPromise_(); |
106 this.resolve_(supervisedUsers); | 106 this.resolve_(supervisedUsers); |
107 for (var i = 0; i < this.observers_.length; ++i) | 107 for (var i = 0; i < this.observers_.length; ++i) |
108 this.observers_[i].receiveExistingSupervisedUsers_(supervisedUsers); | 108 this.observers_[i].receiveExistingSupervisedUsers_(supervisedUsers); |
109 }; | 109 }; |
110 | 110 |
(...skipping 30 matching lines...) Expand all Loading... |
141 'removeObserver', | 141 'removeObserver', |
142 'requestExistingSupervisedUsers', | 142 'requestExistingSupervisedUsers', |
143 'resetPromise', | 143 'resetPromise', |
144 ]); | 144 ]); |
145 | 145 |
146 // Export | 146 // Export |
147 return { | 147 return { |
148 SupervisedUserListData: SupervisedUserListData, | 148 SupervisedUserListData: SupervisedUserListData, |
149 }; | 149 }; |
150 }); | 150 }); |
OLD | NEW |