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

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 /** @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 /** @private */
103 clearDisplayedSyncedDevices_: function() {
104 this.syncedDevices_ = [];
105 },
106
107 /**
108 * Decide whether or not should display no synced tabs message.
109 * @param {boolean} signInState
110 * @param {number} syncedDevicesLength
111 * @return {boolean}
112 */
113 showNoSyncedMessage: function(signInState, syncedDevicesLength) {
114 return signInState && syncedDevicesLength == 0;
115 },
116
117 /**
118 * Decide what message should be displayed when user is logged in and there
119 * are no synced tabs.
120 * @param {boolean} fetchingSyncedTabs
121 * @return {string}
122 */
123 noSyncedTabsMessage: function(fetchingSyncedTabs) {
124 return loadTimeData.getString(
125 fetchingSyncedTabs ? 'loading' : 'noSyncedResults');
126 },
127
84 /** 128 /**
85 * Replaces the currently displayed synced tabs with |sessionList|. It is 129 * 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 130 * 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 131 * avoid doing extra work in this case. The logic could be more intelligent
88 * about updating individual tabs rather than replacing whole sessions, but 132 * about updating individual tabs rather than replacing whole sessions, but
89 * this approach seems to have acceptable performance. 133 * this approach seems to have acceptable performance.
90 * @param {?Array<!ForeignSession>} sessionList 134 * @param {?Array<!ForeignSession>} sessionList
91 */ 135 */
92 updateSyncedDevices: function(sessionList) { 136 updateSyncedDevices: function(sessionList) {
137 this.fetchingSyncedTabs_ = false;
138
93 if (!sessionList) 139 if (!sessionList)
94 return; 140 return;
95 141
96 // First, update any existing devices that have changed. 142 // First, update any existing devices that have changed.
97 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); 143 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length);
98 for (var i = 0; i < updateCount; i++) { 144 for (var i = 0; i < updateCount; i++) {
99 var oldDevice = this.syncedDevices_[i]; 145 var oldDevice = this.syncedDevices_[i];
100 if (oldDevice.tag != sessionList[i].tag || 146 if (oldDevice.tag != sessionList[i].tag ||
101 oldDevice.timestamp != sessionList[i].timestamp) { 147 oldDevice.timestamp != sessionList[i].timestamp) {
102 this.splice( 148 this.splice(
103 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); 149 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i]));
104 } 150 }
105 } 151 }
106 152
107 // Then, append any new devices. 153 // Then, append any new devices.
108 for (var i = updateCount; i < sessionList.length; i++) { 154 for (var i = updateCount; i < sessionList.length; i++) {
109 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); 155 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i]));
110 } 156 }
111 }, 157 },
112 158
159 /**
160 * Get called when user's sign in state changes, this will affect UI of synced
161 * tabs page. Sign in promo gets displayed when user is signed out, and
162 * different messages are shown when there are no synced tabs.
163 * @param {boolean} isUserSignedIn
164 */
165 updateSignInState: function(isUserSignedIn) {
166 // If user's sign in state didn't change, then don't change message or
167 // update UI.
168 if (this.signInState_ == isUserSignedIn)
169 return;
170
171 this.signInState_ = isUserSignedIn;
172
173 // User signed out, clear synced device list and show the sign in promo.
174 if (!isUserSignedIn) {
175 this.clearDisplayedSyncedDevices_();
176 return;
177 }
178 // User signed in, show the loading message when querying for synced
179 // devices.
180 this.fetchingSyncedTabs_ = true;
181 },
182
113 searchTermChanged: function(searchedTerm) { 183 searchTermChanged: function(searchedTerm) {
114 this.syncedDevices_ = []; 184 this.clearDisplayedSyncedDevices_();
115 this.updateSyncedDevices(this.sessionList); 185 this.updateSyncedDevices(this.sessionList);
116 } 186 }
117 }); 187 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_history/synced_device_manager.html ('k') | chrome/browser/ui/webui/md_history_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698