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

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: address review comments 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 /** @private */
42 signInState_: {
43 type: Boolean,
44 value: loadTimeData.getBoolean('isUserSignedIn'),
45 },
46
47 /** @private */
48 fetchingSyncedTabs_: {
49 type: Boolean,
50 value: false,
39 } 51 }
40 }, 52 },
41 53
42 /** 54 /**
43 * @param {!ForeignSession} session 55 * @param {!ForeignSession} session
44 * @return {!ForeignDeviceInternal} 56 * @return {!ForeignDeviceInternal}
45 */ 57 */
46 createInternalDevice_: function(session) { 58 createInternalDevice_: function(session) {
47 var tabs = []; 59 var tabs = [];
48 var separatorIndexes = []; 60 var separatorIndexes = [];
(...skipping 25 matching lines...) Expand all
74 return { 86 return {
75 device: session.name, 87 device: session.name,
76 lastUpdateTime: '– ' + session.modifiedTime, 88 lastUpdateTime: '– ' + session.modifiedTime,
77 separatorIndexes: separatorIndexes, 89 separatorIndexes: separatorIndexes,
78 timestamp: session.timestamp, 90 timestamp: session.timestamp,
79 tabs: tabs, 91 tabs: tabs,
80 tag: session.tag, 92 tag: session.tag,
81 }; 93 };
82 }, 94 },
83 95
96
97 onSignInTap_: function() {
98 chrome.send('SyncSetupShowSetupUI');
99 chrome.send('SyncSetupStartSignIn', [false]);
100 },
101
102 clearDisplayedSyncedDevices: function() {
calamity 2016/06/22 02:20:48 This can be private.
lshang 2016/06/22 04:51:40 Done.
103 this.syncedDevices_ = [];
104 },
105
106 /**
107 * Decide whether or not should display no synced tabs message.
108 * @param {boolean} signInState
109 * @param {number} syncedDevicesLength
110 * @return {boolean}
111 */
112 showNoSyncedMessage: function(signInState, syncedDevicesLength) {
113 return signInState && syncedDevicesLength == 0;
114 },
115
116 /**
117 * Decide what message should be displayed when user is logged in and there
118 * are no synced tabs.
119 * @param {boolean} fetchingSyncedTabs
120 * @return {string}
121 */
122 noSyncedTabsMessage: function(fetchingSyncedTabs) {
123 return loadTimeData.getString(
124 fetchingSyncedTabs ? 'loading' : 'noSyncedResults');
125 },
126
84 /** 127 /**
85 * Replaces the currently displayed synced tabs with |sessionList|. It is 128 * 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 129 * 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 130 * avoid doing extra work in this case. The logic could be more intelligent
88 * about updating individual tabs rather than replacing whole sessions, but 131 * about updating individual tabs rather than replacing whole sessions, but
89 * this approach seems to have acceptable performance. 132 * this approach seems to have acceptable performance.
90 * @param {?Array<!ForeignSession>} sessionList 133 * @param {?Array<!ForeignSession>} sessionList
91 */ 134 */
92 updateSyncedDevices: function(sessionList) { 135 updateSyncedDevices: function(sessionList) {
136 this.fetchingSyncedTabs_ = false;
137
93 if (!sessionList) 138 if (!sessionList)
94 return; 139 return;
95 140
96 // First, update any existing devices that have changed. 141 // First, update any existing devices that have changed.
97 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); 142 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length);
98 for (var i = 0; i < updateCount; i++) { 143 for (var i = 0; i < updateCount; i++) {
99 var oldDevice = this.syncedDevices_[i]; 144 var oldDevice = this.syncedDevices_[i];
100 if (oldDevice.tag != sessionList[i].tag || 145 if (oldDevice.tag != sessionList[i].tag ||
101 oldDevice.timestamp != sessionList[i].timestamp) { 146 oldDevice.timestamp != sessionList[i].timestamp) {
102 this.splice( 147 this.splice(
103 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); 148 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i]));
104 } 149 }
105 } 150 }
106 151
107 // Then, append any new devices. 152 // Then, append any new devices.
108 for (var i = updateCount; i < sessionList.length; i++) { 153 for (var i = updateCount; i < sessionList.length; i++) {
109 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); 154 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i]));
110 } 155 }
111 }, 156 },
112 157
158 /**
159 * Get called when user's sign in state changes, this will affect UI of synced
160 * tabs page. Sign in promo gets displayed when user is signed out, and
161 * different messages are shown when there are no synced tabs.
162 * @param {boolean} isUserSignedIn
163 */
164 updateSignInState: function(isUserSignedIn) {
165 // If user's sign in state didn't change, then don't change message or
166 // update UI.
167 if (this.signInState_ == isUserSignedIn)
168 return;
calamity 2016/06/22 02:20:48 nit: newline after return.
lshang 2016/06/22 04:51:39 Done.
169 this.signInState_ = isUserSignedIn;
170
171 // User signed out, clear synced device list and show the sign in promo.
172 if (!isUserSignedIn) {
173 this.clearDisplayedSyncedDevices();
calamity 2016/06/22 02:20:48 nit: Use an early return here instead of if-else.
lshang 2016/06/22 04:51:40 Done.
174 } else {
175 // User signed in, show the loading message when querying for synced
176 // devices.
177 this.fetchingSyncedTabs_ = true;
178 }
179 },
180
113 searchTermChanged: function(searchedTerm) { 181 searchTermChanged: function(searchedTerm) {
114 this.syncedDevices_ = []; 182 this.clearDisplayedSyncedDevices();
115 this.updateSyncedDevices(this.sessionList); 183 this.updateSyncedDevices(this.sessionList);
116 } 184 }
117 }); 185 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698