1 // Copyright (c) 2012 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.
5 cr
.define('print_preview', function() {
9 * Repository which stores information about the user. Events are dispatched
10 * when the information changes.
12 * @extends {cr.EventTarget}
15 cr
.EventTarget
.call(this);
18 * Email address of the logged in user or {@code null} if no user is logged
19 * in. In case of Google multilogin, can be changed by the user.
22 this.activeUser_
= null;
25 * Email addresses of the logged in users or empty array if no user is
26 * logged in. {@code null} if not known yet.
27 * @private {?Array<string>}
33 * Enumeration of event types dispatched by the user info.
36 UserInfo
.EventType
= {
37 ACTIVE_USER_CHANGED
: 'print_preview.UserInfo.ACTIVE_USER_CHANGED',
38 USERS_CHANGED
: 'print_preview.UserInfo.USERS_CHANGED'
41 UserInfo
.prototype = {
42 __proto__
: cr
.EventTarget
.prototype,
44 /** @return {boolean} Whether user accounts are already retrieved. */
46 return this.users_
!= null;
49 /** @return {boolean} Whether user is logged in or not. */
51 return !!this.activeUser
;
55 * @return {?string} Email address of the logged in user or {@code null} if
59 return this.activeUser_
;
62 /** Changes active user. */
63 set activeUser(activeUser
) {
64 if (this.activeUser_
!= activeUser
) {
65 this.activeUser_
= activeUser
;
66 cr
.dispatchSimpleEvent(this, UserInfo
.EventType
.ACTIVE_USER_CHANGED
);
71 * @return {?Array<string>} Email addresses of the logged in users or
72 * empty array if no user is logged in. {@code null} if not known yet.
79 * Sets logged in user accounts info.
80 * @param {string} activeUser Active user account (email).
81 * @param {!Array<string>} users List of currently logged in accounts.
83 setUsers: function(activeUser
, users
) {
84 this.activeUser_
= activeUser
;
85 this.users_
= users
|| [];
86 cr
.dispatchSimpleEvent(this, UserInfo
.EventType
.USERS_CHANGED
);