Convert cacheinvalidation_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / remoting / webapp / crd / js / apps_v2_migration.js
blobaab9994badb23d7b6a018c6d522ef21b86d5c7ad
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.
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.
14 'use strict';
16 /** @suppress {duplicate} */
17 var remoting = remoting || {};
19 (function() {
21 // Storage key used for the migration settings.
22 var MIGRATION_KEY_ = 'remoting-v2-migration';
24 /**
25 * @param {string} email
26 * @param {string} fullName
27 * @constructor
29 remoting.MigrationSettings = function(email, fullName) {
30 this.email = email;
31 this.fullName = fullName;
34 remoting.AppsV2Migration = function() {};
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.
42 remoting.AppsV2Migration.hasHostsInV1App = function() {
43 if (!base.isAppsV2()) {
44 return Promise.reject(false);
47 var getV1UserInfo = base.Promise.as(chrome.storage.local.get,
48 [MIGRATION_KEY_],
49 chrome.storage.local);
50 var getEmail = remoting.identity.getEmail();
52 return Promise.all([getV1UserInfo, getEmail]).then(
53 /** @param {Object} results */
54 function(results){
55 var v1User =
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);
67 /**
68 * @param {string} email
69 * @param {string} fullName
70 * @return {string}
72 remoting.AppsV2Migration.buildMigrationTips = function(email, fullName) {
73 var params = [
74 fullName,
75 email,
76 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' +
77 'target="_blank">',
78 '</a>'];
79 return l10n.getTranslationOrError(
80 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params);
83 /**
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_);
90 } else {
91 remoting.identity.getUserInfo().then(
92 /** @param {{email:string, name:string}} userInfo */
93 function(userInfo) {
94 var preference = {};
95 preference[MIGRATION_KEY_] =
96 new remoting.MigrationSettings(userInfo.email, userInfo.name);
97 chrome.storage.local.set(preference);
98 }).catch(base.doNothing);
102 }());