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 (function() { |
| 20 |
| 21 // Storage key used for the migration settings. |
| 22 var MIGRATION_KEY_ = 'remoting-v2-migration'; |
| 23 |
| 24 /** |
| 25 * @constructor |
| 26 * @param {string} email |
| 27 * @param {string} fullName |
| 28 */ |
| 29 remoting.MigrationSettings = function(email, fullName) { |
| 30 this.email = email; |
| 31 this.fullName = fullName; |
| 32 }; |
| 33 |
| 34 remoting.AppsV2Migration = function() {}; |
| 35 |
| 36 /** |
| 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. |
| 41 */ |
| 42 remoting.AppsV2Migration.hasHostsInV1App = function() { |
| 43 if (!base.isAppsV2()) { |
| 44 return Promise.reject(false); |
| 45 } |
| 46 |
| 47 var getV1UserInfo = base.Promise.as(chrome.storage.local.get, |
| 48 [MIGRATION_KEY_], |
| 49 chrome.storage.local); |
| 50 var getEmail = base.Promise.as(remoting.identity.getUserInfo, [], |
| 51 remoting.identity, true); |
| 52 |
| 53 return Promise.all([getV1UserInfo, getEmail]).then( |
| 54 /** @param {Object} results */ |
| 55 function(results){ |
| 56 var v1User = |
| 57 /**@type {remoting.MigrationSettings} */ (results[0][MIGRATION_KEY_]); |
| 58 var currentEmail = /** @type {string}*/ (results[1]); |
| 59 |
| 60 if (v1User && v1User.email && v1User.email !== currentEmail) { |
| 61 return Promise.resolve(v1User); |
| 62 } |
| 63 return Promise.reject(false); |
| 64 } |
| 65 ); |
| 66 }; |
| 67 |
| 68 /** |
| 69 * @param {string} email |
| 70 * @param {string} fullName |
| 71 * @return {string} |
| 72 */ |
| 73 remoting.AppsV2Migration.buildMigrationTips = function(email, fullName) { |
| 74 var params = [ |
| 75 fullName, |
| 76 email, |
| 77 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + |
| 78 'target="_blank">', |
| 79 '</a>']; |
| 80 return l10n.getTranslationOrError( |
| 81 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params); |
| 82 }; |
| 83 |
| 84 /** |
| 85 * Saves the email and full name of the current user as the migration settings |
| 86 * in the v1 app. Clears the migration settings in the v2 app. |
| 87 */ |
| 88 remoting.AppsV2Migration.saveUserInfo = function() { |
| 89 if (base.isAppsV2()) { |
| 90 chrome.storage.local.remove(MIGRATION_KEY_); |
| 91 } else { |
| 92 /** |
| 93 * @param {string} email |
| 94 * @param {string} fullName |
| 95 */ |
| 96 remoting.identity.getUserInfo(function(email, fullName) { |
| 97 var preference = {}; |
| 98 preference[MIGRATION_KEY_] = |
| 99 new remoting.MigrationSettings(email, fullName); |
| 100 chrome.storage.local.set(preference); |
| 101 }, base.doNothing); |
| 102 } |
| 103 }; |
| 104 |
| 105 }()); |
| 106 |
OLD | NEW |