OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview | |
7 * The current v1 web-app allows users to sign in as any user. Some users may | |
8 * be signed in using a different account than their chrome profile. When these | |
9 * users upgrade to the v2 app, their host list will be empty and it is not | |
10 * obvious why. remoting.AppsV2Migration shows a migration tip to the user to | |
11 * sign in to their previous accounts if necessary. | |
12 */ | |
13 | |
14 'use strict'; | |
15 | |
16 /** @suppress {duplicate} */ | |
17 var remoting = remoting || {}; | |
18 | |
19 | |
20 (function() { | |
21 | |
22 // Storage key used for the migration settings. | |
23 var MIGRATION_KEY_ = 'remoting-v2-migration'; | |
24 | |
25 /** @constructor */ | |
26 remoting.MigrationSettings = function() {}; | |
27 remoting.MigrationSettings.prototype.email = /** @type {string}*/ (''); | |
28 remoting.MigrationSettings.prototype.fullName = /** @type {string}*/ (''); | |
29 remoting.MigrationSettings.prototype.hasHosts = /** @type {boolean}*/ (false); | |
Jamie
2015/01/20 22:32:01
These should be member variables, not prototype va
Jamie
2015/01/20 22:32:01
Is it necessary to save hasHosts, or could we just
kelvinp
2015/01/21 21:16:20
Done.
kelvinp
2015/01/21 21:16:21
Done.
| |
30 | |
31 | |
32 /** | |
33 * @return {Promise} A Promise object that would resolve to the | |
34 * remoting.MigrationSettings | |
35 */ | |
36 function loadPreferences_() { | |
37 return new Promise( | |
38 /** @param {function(*) : void} resolve */ | |
39 function(resolve) { | |
40 /** @param {Object<string, remoting.MigrationSettings>} result */ | |
41 chrome.storage.local.get(MIGRATION_KEY_, function(result) { | |
42 resolve(result[MIGRATION_KEY_]); | |
43 }); | |
44 } | |
45 ); | |
46 } | |
47 | |
48 /** | |
49 * @return {Promise} A Promise object that would resolve to the email of the | |
Jamie
2015/01/20 22:32:01
s/email/email and full name/ (or change it so that
kelvinp
2015/01/21 21:16:20
Done.
| |
50 * current user. | |
51 */ | |
52 function getEmail_() { | |
53 return new Promise( | |
54 /** | |
55 * @param {function(*) : void} resolve | |
56 * @param {function(*) : void} reject | |
57 */ | |
58 function(resolve, reject) { | |
59 remoting.identity.getUserInfo(resolve, reject); | |
60 } | |
61 ); | |
62 } | |
63 | |
64 remoting.AppsV2Migration = function() {}; | |
65 | |
66 /** | |
67 * @return {Promise} A Promise object that would resolve to | |
68 * { email: string, fullName: string} if the user has signed in with a | |
Jamie
2015/01/20 22:32:01
s/has signed in /has previously signed-in to the v
Jamie
2015/01/20 22:32:01
Nit: No space after "{".
kelvinp
2015/01/21 21:16:20
Done.
| |
69 * different account that has hosts registered to it. Otherwise, the promise | |
70 * will be rejected. | |
71 */ | |
72 remoting.AppsV2Migration.hasHostsInV1App = function() { | |
73 if (!base.isAppsV2()) { | |
74 return Promise.reject(false); | |
75 } | |
76 | |
77 return Promise.all([loadPreferences_(), getEmail_()]).then( | |
78 /** @param {Object} results */ | |
79 function(results){ | |
80 var v1 = /**@type{remoting.MigrationSettings}*/ (results[0]); | |
81 var currentEmail = /** @type {string} */ (results[1]); | |
82 | |
83 if (v1 && v1.email && v1.email !== currentEmail && v1.hasHosts) { | |
84 return { | |
Jamie
2015/01/20 22:32:01
Is this equivalent to return Promise.resolve(...)?
kelvinp
2015/01/21 21:16:21
Done.
| |
85 email: v1.email, | |
86 fullName: v1.fullName | |
87 }; | |
88 } | |
89 return Promise.reject(false); | |
90 }); | |
91 }; | |
92 | |
93 /** | |
94 * @param {string} email | |
95 * @param {string} fullName | |
96 * @return {string} | |
97 */ | |
98 remoting.AppsV2Migration.buildMigrationTips = function(email, fullName) { | |
99 var params = [ | |
100 fullName, | |
101 email, | |
102 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + | |
103 'target="_blank">', | |
104 '</a>']; | |
105 return l10n.getTranslationOrError( | |
106 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params); | |
107 }; | |
108 | |
109 /** @param {boolean} hasHosts */ | |
Jamie
2015/01/20 22:32:01
The behaviour of this function is quite subtle, so
kelvinp
2015/01/21 21:16:20
Done.
| |
110 remoting.AppsV2Migration.savePreferences = function(hasHosts) { | |
111 if (base.isAppsV2()) { | |
112 if (hasHosts) { | |
113 chrome.storage.local.remove(MIGRATION_KEY_); | |
114 } | |
115 return; | |
116 } | |
117 | |
118 var preference = /**@type{remoting.MigrationSettings}*/ ({}); | |
Jamie
2015/01/20 22:32:01
This would be clearer if the MigrationSettings cto
| |
119 preference.email = window.localStorage['remoting-email']; | |
120 preference.fullName = window.localStorage['remoting-fullname']; | |
Jamie
2015/01/20 22:32:01
Can these be passed in to the function? Using wind
kelvinp
2015/01/21 21:16:21
Done.
| |
121 preference.hasHosts = hasHosts; | |
122 | |
123 var container = {}; | |
124 container[MIGRATION_KEY_] = preference; | |
125 chrome.storage.local.set(container); | |
126 }; | |
127 | |
128 }()); | |
129 | |
OLD | NEW |