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.
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.
16 /** @suppress {duplicate} */
17 var remoting
= remoting
|| {};
21 // Storage key used for the migration settings.
22 var MIGRATION_KEY_
= 'remoting-v2-migration';
25 * @param {string} email
26 * @param {string} fullName
29 remoting
.MigrationSettings = function(email
, fullName
) {
31 this.fullName
= fullName
;
34 remoting
.AppsV2Migration = function() {};
37 * @return {Promise} A Promise object that would resolve to
38 * {remoting.MigrationSettings} if the user has previously signed-in to
39 * the v1 app with a different account that has hosts registered to it.
40 * Otherwise, the promise will be rejected.
42 remoting
.AppsV2Migration
.hasHostsInV1App = function() {
43 if (!base
.isAppsV2()) {
44 return Promise
.reject(false);
47 var getV1UserInfo
= base
.Promise
.as(chrome
.storage
.local
.get,
49 chrome
.storage
.local
);
50 var getEmail
= remoting
.identity
.getEmail();
52 return Promise
.all([getV1UserInfo
, getEmail
]).then(
53 /** @param {Object} results */
56 /**@type {remoting.MigrationSettings} */ (results
[0][MIGRATION_KEY_
]);
57 var currentEmail
= /** @type {string}*/ (results
[1]);
59 if (v1User
&& v1User
.email
&& v1User
.email
!== currentEmail
) {
60 return Promise
.resolve(v1User
);
62 return Promise
.reject(false);
68 * @param {string} email
69 * @param {string} fullName
72 remoting
.AppsV2Migration
.buildMigrationTips = function(email
, fullName
) {
76 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' +
79 return l10n
.getTranslationOrError(
80 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params
);
84 * Saves the email and full name of the current user as the migration settings
85 * in the v1 app. Clears the migration settings in the v2 app.
87 remoting
.AppsV2Migration
.saveUserInfo = function() {
88 if (base
.isAppsV2()) {
89 chrome
.storage
.local
.remove(MIGRATION_KEY_
);
91 remoting
.identity
.getUserInfo().then(
92 /** @param {{email:string, name:string}} userInfo */
95 preference
[MIGRATION_KEY_
] =
96 new remoting
.MigrationSettings(userInfo
.email
, userInfo
.name
);
97 chrome
.storage
.local
.set(preference
);
98 }).catch(base
.doNothing
);