Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: remoting/webapp/crd/js/apps_v2_migration.js

Issue 848993002: Improve apps v2 upgrade UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CL feedback Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
20 (function() {
21
22 // Storage key used for the migration settings.
23 var MIGRATION_KEY_ = 'remoting-v2-migration';
24
25 /**
26 * @constructor
27 * @param {string} email
28 * @param {string} fullName
29 */
30 remoting.MigrationSettings = function(email, fullName) {
31 this.email = email;
32 this.fullName = fullName;
33 };
34
35
36 /**
37 * @return {Promise} A Promise object that would resolve to the
38 * remoting.MigrationSettings
39 */
40 function loadPreferences_() {
41 return new Promise(
42 /** @param {function(*) : void} resolve */
43 function(resolve) {
44 /** @param {Object<string, remoting.MigrationSettings>} result */
45 chrome.storage.local.get(MIGRATION_KEY_, function(result) {
46 resolve(result[MIGRATION_KEY_]);
47 });
48 }
49 );
50 }
51
52 /**
53 * @return {Promise} A Promise object that would resolve to the email and full
54 * name of the current user.
55 */
56 function getEmail_() {
57 return new Promise(
58 /**
59 * @param {function(*) : void} resolve
60 * @param {function(*) : void} reject
61 */
62 function(resolve, reject) {
63 remoting.identity.getUserInfo(resolve, reject);
64 }
65 );
66 }
67
68 remoting.AppsV2Migration = function() {};
69
70 /**
71 * @return {Promise} A Promise object that would resolve to
72 * {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.
73 * the v1 app with a different account that has hosts registered to it.
74 * Otherwise, the promise will be rejected.
75 */
76 remoting.AppsV2Migration.hasHostsInV1App = function() {
77 if (!base.isAppsV2()) {
78 return Promise.reject(false);
79 }
80
81 return Promise.all([loadPreferences_(), getEmail_()]).then(
82 /** @param {Object} results */
83 function(results){
84 var v1 = /**@type {remoting.MigrationSettings} */ (results[0]);
85 var currentEmail = /** @type {string}*/ (results[1]);
86
87 if (v1 && v1.email && v1.email !== currentEmail) {
88 return Promise.resolve({
89 email: v1.email,
90 fullName: v1.fullName
Jamie 2015/01/21 22:02:20 This should be new remoting.MigrationSettings.
kelvinp 2015/01/22 02:10:55 Done.
91 });
92 }
93 return Promise.reject(false);
94 }
95 );
96 };
97
98 /**
99 * @param {string} email
100 * @param {string} fullName
101 * @return {string}
102 */
103 remoting.AppsV2Migration.buildMigrationTips = function(email, fullName) {
104 var params = [
105 fullName,
106 email,
107 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' +
108 'target="_blank">',
109 '</a>'];
110 return l10n.getTranslationOrError(
111 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params);
112 };
113
114 /**
115 * Saves the email and full name of the current user as the migration settings
116 * in the v1 app. Clears the migration settings in the v2 app.
117 */
118 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.
119 if (base.isAppsV2()) {
120 chrome.storage.local.remove(MIGRATION_KEY_);
121 } else {
122 /**
123 * @param {string} email
124 * @param {string} fullName
125 */
126 remoting.identity.getUserInfo(function(email, fullName) {
127 var preference = {};
128 preference[MIGRATION_KEY_] =
129 new remoting.MigrationSettings(email, fullName);
130 chrome.storage.local.set(preference);
131 }, base.doNothing);
132 }
133 };
134
135 }());
136
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698