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

Side by Side Diff: chrome/browser/resources/md_history/synced_device_manager.js

Issue 2077473002: MD History: add sign in promo in synced tabs when user isn't logged in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @typedef {{device: string, 6 * @typedef {{device: string,
7 * lastUpdateTime: string, 7 * lastUpdateTime: string,
8 * separatorIndexes: !Array<number>, 8 * separatorIndexes: !Array<number>,
9 * timestamp: number, 9 * timestamp: number,
10 * tabs: !Array<!ForeignSessionTab>, 10 * tabs: !Array<!ForeignSessionTab>,
(...skipping 18 matching lines...) Expand all
29 observer: 'searchTermChanged' 29 observer: 'searchTermChanged'
30 }, 30 },
31 31
32 /** 32 /**
33 * An array of synced devices with synced tab data. 33 * An array of synced devices with synced tab data.
34 * @type {!Array<!ForeignDeviceInternal>} 34 * @type {!Array<!ForeignDeviceInternal>}
35 */ 35 */
36 syncedDevices_: { 36 syncedDevices_: {
37 type: Array, 37 type: Array,
38 value: function() { return []; } 38 value: function() { return []; }
39 },
40
41 signInState_: {
42 type: Boolean,
43 value: loadTimeData.getBoolean('isUserSignedIn'),
44 },
45
46 fetchingSyncedTabs_: {
47 type: Boolean,
48 value: false,
39 } 49 }
40 }, 50 },
41 51
42 /** 52 /**
43 * @param {!ForeignSession} session 53 * @param {!ForeignSession} session
44 * @return {!ForeignDeviceInternal} 54 * @return {!ForeignDeviceInternal}
45 */ 55 */
46 createInternalDevice_: function(session) { 56 createInternalDevice_: function(session) {
47 var tabs = []; 57 var tabs = [];
48 var separatorIndexes = []; 58 var separatorIndexes = [];
(...skipping 25 matching lines...) Expand all
74 return { 84 return {
75 device: session.name, 85 device: session.name,
76 lastUpdateTime: '– ' + session.modifiedTime, 86 lastUpdateTime: '– ' + session.modifiedTime,
77 separatorIndexes: separatorIndexes, 87 separatorIndexes: separatorIndexes,
78 timestamp: session.timestamp, 88 timestamp: session.timestamp,
79 tabs: tabs, 89 tabs: tabs,
80 tag: session.tag, 90 tag: session.tag,
81 }; 91 };
82 }, 92 },
83 93
94
95 onSignInTap_: function() {
96 chrome.send('SyncSetupShowSetupUI');
97 chrome.send('SyncSetupStartSignIn', [false]);
98 },
99
100 clearDisplayedSyncedDevices: function() {
101 this.syncedDevices_ = [];
102 },
103
104 /**
105 * Decide whether or not should display no synced tabs message.
106 * @param {boolean} signInState
107 * @param {number} syncedDevicesLength
tsergeant 2016/06/21 04:33:51 Add an @return
lshang 2016/06/21 05:40:00 Done.
108 */
109 showNoSyncedMessage: function(signInState, syncedDevicesLength) {
110 return signInState && syncedDevicesLength == 0;
111 },
112
113 /**
114 * Decide what message should be diaplayed when user is logged in and there is
tsergeant 2016/06/21 04:33:51 Minor nit: typo in "displayed" also, "there are
lshang 2016/06/21 05:40:00 Done.
115 * no synced tabs.
116 * @param {boolean} fetchingSyncedTabs
tsergeant 2016/06/21 04:33:51 Add an @return as well
lshang 2016/06/21 05:40:00 Done.
117 */
118 noSyncedTabsMessage: function(fetchingSyncedTabs) {
119 return loadTimeData.getString(
120 fetchingSyncedTabs ? 'loading' : 'noSyncedResults');
121 },
122
84 /** 123 /**
85 * Replaces the currently displayed synced tabs with |sessionList|. It is 124 * Replaces the currently displayed synced tabs with |sessionList|. It is
86 * common for only a single session within the list to have changed, We try to 125 * common for only a single session within the list to have changed, We try to
87 * avoid doing extra work in this case. The logic could be more intelligent 126 * avoid doing extra work in this case. The logic could be more intelligent
88 * about updating individual tabs rather than replacing whole sessions, but 127 * about updating individual tabs rather than replacing whole sessions, but
89 * this approach seems to have acceptable performance. 128 * this approach seems to have acceptable performance.
90 * @param {?Array<!ForeignSession>} sessionList 129 * @param {?Array<!ForeignSession>} sessionList
91 */ 130 */
92 updateSyncedDevices: function(sessionList) { 131 updateSyncedDevices: function(sessionList) {
93 if (!sessionList) 132 if (!sessionList) {
133 this.fetchingSyncedTabs_ = false;
tsergeant 2016/06/21 04:33:51 Just put this once at the very start of the method
lshang 2016/06/21 05:40:00 Done.
94 return; 134 return;
135 }
95 136
96 // First, update any existing devices that have changed. 137 // First, update any existing devices that have changed.
97 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); 138 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length);
98 for (var i = 0; i < updateCount; i++) { 139 for (var i = 0; i < updateCount; i++) {
99 var oldDevice = this.syncedDevices_[i]; 140 var oldDevice = this.syncedDevices_[i];
100 if (oldDevice.tag != sessionList[i].tag || 141 if (oldDevice.tag != sessionList[i].tag ||
101 oldDevice.timestamp != sessionList[i].timestamp) { 142 oldDevice.timestamp != sessionList[i].timestamp) {
102 this.splice( 143 this.splice(
103 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); 144 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i]));
104 } 145 }
105 } 146 }
106 147
107 // Then, append any new devices. 148 // Then, append any new devices.
108 for (var i = updateCount; i < sessionList.length; i++) { 149 for (var i = updateCount; i < sessionList.length; i++) {
109 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); 150 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i]));
110 } 151 }
152
153 this.fetchingSyncedTabs_ = false;
154 },
155
156 /**
157 * Get called when user's sign in state changes, this will affect UI of synced
158 * tabs page. Sign in promo gets displayed when user is signed out, and
159 * different messages are shown when there is no synced tabs.
160 * @param {boolean} isUserSignedIn
161 */
162 updateSignInState: function(isUserSignedIn) {
163 // If user's sign in state didn't change, then don't change message or
164 // update UI.
165 if (this.signInState_ == isUserSignedIn)
166 return;
167 this.signInState_ = isUserSignedIn;
168
169 // User signed out, clear synced device list and show the sign in promo.
170 if (!isUserSignedIn) {
171 this.clearDisplayedSyncedDevices();
172 } else {
173 // User signed in, show the loading message when querying for synced
174 // devices.
175 this.fetchingSyncedTabs_ = true;
176 }
111 }, 177 },
112 178
113 searchTermChanged: function(searchedTerm) { 179 searchTermChanged: function(searchedTerm) {
114 this.syncedDevices_ = []; 180 this.clearDisplayedSyncedDevices();
115 this.updateSyncedDevices(this.sessionList); 181 this.updateSyncedDevices(this.sessionList);
116 } 182 }
117 }); 183 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698