Chromium Code Reviews| Index: remoting/webapp/crd/js/apps_v2_migration.js |
| diff --git a/remoting/webapp/crd/js/apps_v2_migration.js b/remoting/webapp/crd/js/apps_v2_migration.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..97af120731f31072d41b3c6bc48c4f0a5858a653 |
| --- /dev/null |
| +++ b/remoting/webapp/crd/js/apps_v2_migration.js |
| @@ -0,0 +1,136 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| +* @fileoverview |
| +* The current v1 web-app allows users to sign in as any user. Some users may |
| +* be signed in using a different account than their chrome profile. When these |
| +* users upgrade to the v2 app, their host list will be empty and it is not |
| +* obvious why. remoting.AppsV2Migration shows a migration tip to the user to |
| +* sign in to their previous accounts if necessary. |
| +*/ |
| + |
| +'use strict'; |
| + |
| +/** @suppress {duplicate} */ |
| +var remoting = remoting || {}; |
| + |
| + |
| +(function() { |
| + |
| +// Storage key used for the migration settings. |
| +var MIGRATION_KEY_ = 'remoting-v2-migration'; |
| + |
| +/** |
| + * @constructor |
| + * @param {string} email |
| + * @param {string} fullName |
| + */ |
| +remoting.MigrationSettings = function(email, fullName) { |
| + this.email = email; |
| + this.fullName = fullName; |
| +}; |
| + |
| + |
| +/** |
| + * @return {Promise} A Promise object that would resolve to the |
| + * remoting.MigrationSettings |
| + */ |
| +function loadPreferences_() { |
| + return new Promise( |
| + /** @param {function(*) : void} resolve */ |
| + function(resolve) { |
| + /** @param {Object<string, remoting.MigrationSettings>} result */ |
| + chrome.storage.local.get(MIGRATION_KEY_, function(result) { |
| + resolve(result[MIGRATION_KEY_]); |
| + }); |
| + } |
| + ); |
| +} |
| + |
| +/** |
| + * @return {Promise} A Promise object that would resolve to the email and full |
| + * name of the current user. |
| + */ |
| +function getEmail_() { |
| + return new Promise( |
| + /** |
| + * @param {function(*) : void} resolve |
| + * @param {function(*) : void} reject |
| + */ |
| + function(resolve, reject) { |
| + remoting.identity.getUserInfo(resolve, reject); |
| + } |
| + ); |
| +} |
| + |
| +remoting.AppsV2Migration = function() {}; |
| + |
| +/** |
| + * @return {Promise} A Promise object that would resolve to |
| + * {email: string, fullName: string} if the user has previously signed-in to |
|
Jamie
2015/01/21 22:02:20
The promise should resolve to remoting.MigrationSe
kelvinp
2015/01/22 02:10:55
Done.
|
| + * the v1 app with a different account that has hosts registered to it. |
| + * Otherwise, the promise will be rejected. |
| + */ |
| +remoting.AppsV2Migration.hasHostsInV1App = function() { |
| + if (!base.isAppsV2()) { |
| + return Promise.reject(false); |
| + } |
| + |
| + return Promise.all([loadPreferences_(), getEmail_()]).then( |
| + /** @param {Object} results */ |
| + function(results){ |
| + var v1 = /**@type {remoting.MigrationSettings} */ (results[0]); |
| + var currentEmail = /** @type {string}*/ (results[1]); |
| + |
| + if (v1 && v1.email && v1.email !== currentEmail) { |
| + return Promise.resolve({ |
| + email: v1.email, |
| + fullName: v1.fullName |
|
Jamie
2015/01/21 22:02:20
This should be new remoting.MigrationSettings.
kelvinp
2015/01/22 02:10:55
Done.
|
| + }); |
| + } |
| + return Promise.reject(false); |
| + } |
| + ); |
| +}; |
| + |
| +/** |
| + * @param {string} email |
| + * @param {string} fullName |
| + * @return {string} |
| + */ |
| +remoting.AppsV2Migration.buildMigrationTips = function(email, fullName) { |
| + var params = [ |
| + fullName, |
| + email, |
| + '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + |
| + 'target="_blank">', |
| + '</a>']; |
| + return l10n.getTranslationOrError( |
| + /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params); |
| +}; |
| + |
| +/** |
| + * Saves the email and full name of the current user as the migration settings |
| + * in the v1 app. Clears the migration settings in the v2 app. |
| + */ |
| +remoting.AppsV2Migration.savePreferences = function() { |
|
Jamie
2015/01/21 22:02:20
Now that it only saves the user info, I think save
kelvinp
2015/01/22 02:10:54
Done.
|
| + if (base.isAppsV2()) { |
| + chrome.storage.local.remove(MIGRATION_KEY_); |
| + } else { |
| + /** |
| + * @param {string} email |
| + * @param {string} fullName |
| + */ |
| + remoting.identity.getUserInfo(function(email, fullName) { |
| + var preference = {}; |
| + preference[MIGRATION_KEY_] = |
| + new remoting.MigrationSettings(email, fullName); |
| + chrome.storage.local.set(preference); |
| + }, base.doNothing); |
| + } |
| +}; |
| + |
| +}()); |
| + |