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

Side by Side Diff: chrome/browser/resources/print_preview/data/user_info.js

Issue 233623003: Remember and restore the account last used destination is registered for. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust PrintPreview unit test. Created 6 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Repository which stores information about the user. Events are dispatched 9 * Repository which stores information about the user. Events are dispatched
10 * when the information changes. 10 * when the information changes.
11 * @constructor 11 * @constructor
12 * @extends {cr.EventTarget} 12 * @extends {cr.EventTarget}
13 */ 13 */
14 function UserInfo() { 14 function UserInfo() {
15 cr.EventTarget.call(this); 15 cr.EventTarget.call(this);
16 16
17 /** 17 /**
18 * Email address of the logged in user or {@code null} if no user is logged 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. 19 * in. In case of Google multilogin, can be changed by the user.
20 * @private {?string} 20 * @private {?string}
21 */ 21 */
22 this.activeUser_ = null; 22 this.activeUser_ = null;
23 23
24 /** 24 /**
25 * Email addresses of the logged in users or empty array if no user is 25 * Email addresses of the logged in users or empty array if no user is
26 * logged in. 26 * logged in. {@code null} if not known yet.
27 * @private {!Array.<string>} 27 * @private {?Array.<string>}
28 */ 28 */
29 this.users_ = []; 29 this.users_ = null;
30 }; 30 };
31 31
32 /** 32 /**
33 * Enumeration of event types dispatched by the user info. 33 * Enumeration of event types dispatched by the user info.
34 * @enum {string} 34 * @enum {string}
35 */ 35 */
36 UserInfo.EventType = { 36 UserInfo.EventType = {
37 ACTIVE_USER_CHANGED: 'print_preview.UserInfo.ACTIVE_USER_CHANGED', 37 ACTIVE_USER_CHANGED: 'print_preview.UserInfo.ACTIVE_USER_CHANGED',
38 USERS_CHANGED: 'print_preview.UserInfo.USERS_CHANGED' 38 USERS_CHANGED: 'print_preview.UserInfo.USERS_CHANGED'
39 }; 39 };
40 40
41 UserInfo.prototype = { 41 UserInfo.prototype = {
42 __proto__: cr.EventTarget.prototype, 42 __proto__: cr.EventTarget.prototype,
43 43
44 /** @return {boolean} Whether user accounts are already retrieved. */
45 get initialized() {
46 return this.users_ != null;
47 },
48
49 /** @return {boolean} Whether user is logged in or not. */
50 get loggedIn() {
51 return !!this.activeUser;
52 },
53
44 /** 54 /**
45 * @return {?string} Email address of the logged in user or {@code null} if 55 * @return {?string} Email address of the logged in user or {@code null} if
46 * no user is logged. 56 * no user is logged.
47 */ 57 */
48 get activeUser() { 58 get activeUser() {
49 return this.activeUser_; 59 return this.activeUser_;
50 }, 60 },
51 61
52 /** Changes active user. */ 62 /** Changes active user. */
53 set activeUser(activeUser) { 63 set activeUser(activeUser) {
54 if (this.activeUser_ != activeUser) { 64 if (this.activeUser_ != activeUser) {
55 this.activeUser_ = activeUser; 65 this.activeUser_ = activeUser;
56 cr.dispatchSimpleEvent(this, UserInfo.EventType.ACTIVE_USER_CHANGED); 66 cr.dispatchSimpleEvent(this, UserInfo.EventType.ACTIVE_USER_CHANGED);
57 } 67 }
58 }, 68 },
59 69
60
61 /** 70 /**
62 * @return {!Array.<string>} Email addresses of the logged in users or 71 * @return {?Array.<string>} Email addresses of the logged in users or
63 * empty array if no user is logged in. 72 * empty array if no user is logged in. {@code null} if not known yet.
64 */ 73 */
65 get users() { 74 get users() {
66 return this.users_; 75 return this.users_;
67 }, 76 },
68 77
69 /** 78 /**
70 * Sets logged in user accounts info. 79 * Sets logged in user accounts info.
71 * @param {string} user Currently logged in user (email). 80 * @param {string} activeUser Active user account (email).
72 * @param {!Array.<string>} users List of currently logged in accounts. 81 * @param {!Array.<string>} users List of currently logged in accounts.
73 */ 82 */
74 setUsers: function(activeUser, users) { 83 setUsers: function(activeUser, users) {
75 this.activeUser_ = activeUser; 84 this.activeUser_ = activeUser;
76 this.users_ = users || []; 85 this.users_ = users || [];
77 cr.dispatchSimpleEvent(this, UserInfo.EventType.USERS_CHANGED); 86 cr.dispatchSimpleEvent(this, UserInfo.EventType.USERS_CHANGED);
78 }, 87 },
79 }; 88 };
80 89
81 return { 90 return {
82 UserInfo: UserInfo 91 UserInfo: UserInfo
83 }; 92 };
84 }); 93 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698