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

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

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Set --bary flag Created 8 years, 6 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
OLDNEW
(Empty)
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.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Repository which stores information about the user. Events are dispatched
10 * when the information changes.
11 * @constructor
12 * @extends {cr.EventTarget}
13 */
14 function UserInfo() {
15 cr.EventTarget.call(this);
16
17 /**
18 * Tracker used to keep track of event listeners.
19 * @type {!EventTracker}
20 * @private
21 */
22 this.tracker_ = new EventTracker();
23
24 /**
25 * Google Cloud Print interface to listen to for events. Currently, through
26 * Google Cloud Print is how we determine the info of the logged in user.
27 * @type {cloudprint.CloudPrintInterface}
28 * @private
29 */
30 this.cloudPrintInterface_ = null;
31
32 /**
33 * Email address of the logged in user or {@code null} if no user is logged
34 * in.
35 * @type {?string}
36 * @private
37 */
38 this.userEmail_ = null;
39 };
40
41 /**
42 * Enumeration of event types dispatched by the user info.
43 * @enum {string}
44 */
45 UserInfo.EventType = {
46 EMIAL_CHANGE: 'print_preview.UserInfo.EMAIL_CHANGE'
47 };
48
49 UserInfo.prototype = {
50 __proto__: cr.EventTarget.prototype,
51
52 /**
53 * @return {?string} Email address of the logged in user or {@code null} if
54 * no user is logged.
55 */
56 getUserEmail: function() {
57 return this.userEmail_;
58 },
59
60 /**
61 * @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface
62 * to Google Cloud Print that the print preview uses.
63 */
64 setCloudPrintInterface: function(cloudPrintInterface) {
65 this.cloudPrintInterface_ = cloudPrintInterface;
66 this.tracker_.add(
67 this.cloudPrintInterface_,
68 cloudprint.CloudPrintInterface.EventType.SEARCH_DONE,
69 this.onCloudPrintSearchDone_.bind(this));
70 },
71
72 /** Removes all event listeners. */
73 removeEventListeners: function() {
74 this.tracker_.removeAll();
75 },
76
77 /**
78 * Called when a Google Cloud Print printer search completes. Updates user
79 * information.
80 * @type {cr.Event} event Contains information about the logged in user.
81 * @private
82 */
83 onCloudPrintSearchDone_: function(event) {
84 this.userEmail_ = event.email;
85 cr.dispatchSimpleEvent(this, UserInfo.EventType.EMAIL_CHANGE);
86 }
87 };
88
89 return {
90 UserInfo: UserInfo
91 };
92 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698