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

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

Issue 125993002: Add error handling for supervised user import flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move ManagedUserListData to its own file. Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6 /**
7 * ManagedUserListData class.
8 * Handles requests for retrieving a list of existing managed users which are
9 * supervised by the current profile. This list is cached in order to make it
10 * possible to serve future requests immediately. The first request will be
11 * handled asynchronously.
12 * @constructor
13 * @class
14 */
15 function ManagedUserListData() {
16 this.callbacks_ = [];
17 this.errbacks_ = [];
18 this.requestInProgress_ = false;
19 this.managedUsers_ = null;
20 };
21
22 cr.addSingletonGetter(ManagedUserListData);
23
24 /**
25 * Resets to the initial state of no pending requests.
26 * @private
27 */
28 ManagedUserListData.prototype.reset_ = function() {
29 this.callbacks_ = [];
30 this.errbacks_ = [];
31 this.requestInProgress_ = false;
32 }
33
34 /**
35 * Receives a list of managed users and passes the list to each of the
36 * callbacks.
37 * @param {Array.<Object>} managedUsers An array of managed user objects.
38 * Each object is of the form:
39 * managedUser = {
40 * id: "Managed User ID",
41 * name: "Managed User Name",
42 * iconURL: "chrome://path/to/icon/image",
43 * onCurrentDevice: true or false,
44 * needAvatar: true or false
45 * }
46 */
47 ManagedUserListData.receiveExistingManagedUsers = function(managedUsers) {
48 var instance = ManagedUserListData.getInstance();
49 var i;
50 for (i = 0; i < instance.callbacks_.length; i++) {
51 instance.callbacks_[i](managedUsers);
52 }
53 instance.managedUsers_ = managedUsers;
54 instance.reset_();
55 };
56
57 /**
58 * Called when there is a signin error when retrieving the list of managed
59 * users. Calls the error callbacks which will display an appropriate error
60 * message to the user.
61 */
62 ManagedUserListData.onSigninError = function() {
63 var instance = ManagedUserListData.getInstance();
64 var i;
65 for (i = 0; i < instance.errbacks_.length; i++) {
66 instance.errbacks_[i]();
67 }
68 // Reset the list of managed users in order to avoid showing stale data.
69 instance.managedUsers_ = null;
70 instance.reset_();
71 };
72
73 /**
74 * Handles the request for the list of existing managed users. If the data is
75 * already available, it will call |callback| immediately. Otherwise, it
76 * retrieves the list of existing managed users which is then processed in
77 * receiveExistingManagedUsers().
78 * @param {Object} callback The callback function which is called on success.
79 * @param {Object} errback the callback function which is called on error.
80 */
81 ManagedUserListData.requestExistingManagedUsers = function(callback,
82 errback) {
83 var instance = ManagedUserListData.getInstance();
84 instance.callbacks_.push(callback);
85 instance.errbacks_.push(errback);
86 if (!instance.requestInProgress_) {
87 if (instance.managedUsers_ != null) {
88 ManagedUserListData.receiveExistingManagedUsers(instance.managedUsers_);
89 return;
90 }
91 instance.requestInProgress_ = true;
92 chrome.send('requestManagedUserImportUpdate');
93 }
94 };
95
96 /**
97 * Reload the list of existing managed users. Should be called when a new
98 * supervised user profile was created or a supervised user profile was
99 * deleted.
100 */
101 ManagedUserListData.reloadExistingManagedUsers = function() {
102 var instance = ManagedUserListData.getInstance();
103 if (instance.requestInProgress_)
104 return;
105
106 instance.managedUsers_ = null;
107 instance.requestInProgress_ = true;
108 chrome.send('requestManagedUserImportUpdate');
109 };
110
111 // Export
112 return {
113 ManagedUserListData: ManagedUserListData,
114 };
115 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698