-
Notifications
You must be signed in to change notification settings - Fork 8
/
apps_v2_migration.js
106 lines (91 loc) · 3.08 KB
/
apps_v2_migration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// 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;
};
remoting.AppsV2Migration = function() {};
/**
* @return {Promise} A Promise object that would resolve to
* {remoting.MigrationSettings} if the user has previously signed-in to
* 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);
}
var getV1UserInfo = base.Promise.as(chrome.storage.local.get,
[MIGRATION_KEY_],
chrome.storage.local);
var getEmail = base.Promise.as(remoting.identity.getUserInfo, [],
remoting.identity, true);
return Promise.all([getV1UserInfo, getEmail]).then(
/** @param {Object} results */
function(results){
var v1User =
/**@type {remoting.MigrationSettings} */ (results[0][MIGRATION_KEY_]);
var currentEmail = /** @type {string}*/ (results[1]);
if (v1User && v1User.email && v1User.email !== currentEmail) {
return Promise.resolve(v1User);
}
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.saveUserInfo = function() {
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);
}
};
}());