Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
|
tsergeant
2016/06/17 06:22:03
I won't review this file until after calamity@ is
| |
| 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>, |
| 11 * tag: string}} | 11 * tag: string}} |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 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 showNoSyncedMessage_: { | |
| 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 Loading... | |
| 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 /** | |
| 101 * Change the message showing when user is logged in and there is no synced | |
| 102 * tabs. Also decide whether or not should display the message. | |
| 103 * @param {boolean} fetchingSyncedTabs | |
| 104 * @private | |
| 105 */ | |
| 106 updateSyncedTabMessage_: function(fetchingSyncedTabs) { | |
| 107 var messageId = fetchingSyncedTabs ? 'loading' : 'noSyncedResults'; | |
| 108 this.$['no-synced-tabs'].textContent = loadTimeData.getString(messageId); | |
| 109 this.showNoSyncedMessage_ = this.signInState_ && | |
| 110 (this.syncedDevices_.length == 0); | |
|
calamity
2016/06/17 06:25:45
It would be 'more Polymer' to use a computed bindi
lshang
2016/06/21 03:00:26
Done.
It's really cool that computed binding will
| |
| 111 }, | |
| 112 | |
| 84 /** | 113 /** |
| 85 * Replaces the currently displayed synced tabs with |sessionList|. It is | 114 * 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 | 115 * 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 | 116 * avoid doing extra work in this case. The logic could be more intelligent |
| 88 * about updating individual tabs rather than replacing whole sessions, but | 117 * about updating individual tabs rather than replacing whole sessions, but |
| 89 * this approach seems to have acceptable performance. | 118 * this approach seems to have acceptable performance. |
| 90 * @param {?Array<!ForeignSession>} sessionList | 119 * @param {?Array<!ForeignSession>} sessionList |
| 91 */ | 120 */ |
| 92 updateSyncedDevices: function(sessionList) { | 121 updateSyncedDevices: function(sessionList) { |
| 93 if (!sessionList) | 122 if (!sessionList) { |
| 123 this.updateSyncedTabMessage_(false); | |
| 94 return; | 124 return; |
| 125 } | |
| 95 | 126 |
| 96 // First, update any existing devices that have changed. | 127 // First, update any existing devices that have changed. |
| 97 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); | 128 var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); |
| 98 for (var i = 0; i < updateCount; i++) { | 129 for (var i = 0; i < updateCount; i++) { |
| 99 var oldDevice = this.syncedDevices_[i]; | 130 var oldDevice = this.syncedDevices_[i]; |
| 100 if (oldDevice.tag != sessionList[i].tag || | 131 if (oldDevice.tag != sessionList[i].tag || |
| 101 oldDevice.timestamp != sessionList[i].timestamp) { | 132 oldDevice.timestamp != sessionList[i].timestamp) { |
| 102 this.splice( | 133 this.splice( |
| 103 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); | 134 'syncedDevices_', i, 1, this.createInternalDevice_(sessionList[i])); |
| 104 } | 135 } |
| 105 } | 136 } |
| 106 | 137 |
| 107 // Then, append any new devices. | 138 // Then, append any new devices. |
| 108 for (var i = updateCount; i < sessionList.length; i++) { | 139 for (var i = updateCount; i < sessionList.length; i++) { |
| 109 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); | 140 this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); |
| 110 } | 141 } |
| 142 | |
| 143 this.updateSyncedTabMessage_(false); | |
| 144 }, | |
| 145 | |
| 146 updateSignInState: function(isUserSignedIn) { | |
| 147 // If user's sign in state didn't change, then don't change message or | |
| 148 // update synced devices. | |
| 149 if (this.signInState_ == isUserSignedIn) | |
| 150 return; | |
|
calamity
2016/06/17 06:25:45
You can remove this if you do the above since noti
lshang
2016/06/21 03:00:26
When user changes state from signed out to signed
| |
| 151 this.signInState_ = isUserSignedIn; | |
| 152 | |
| 153 // User signed out, clear session list and show the sign in promo. | |
| 154 if (!isUserSignedIn) { | |
| 155 this.sessionList = []; | |
| 156 this.syncedDevices_ = []; | |
|
calamity
2016/06/17 06:25:45
You should make a method called clearDisplayedSync
lshang
2016/06/21 03:00:26
Done.
Yeah I think we just want to clear the UI he
| |
| 157 this.updateSyncedDevices(this.sessionList); | |
|
calamity
2016/06/17 06:25:45
I don't think you'll need this line either.
lshang
2016/06/21 03:00:26
Done.
| |
| 158 } else { | |
| 159 // User signed in, show the loading message when querying for synced | |
| 160 // devices. | |
| 161 this.updateSyncedTabMessage_(true); | |
| 162 } | |
|
calamity
2016/06/17 06:25:45
All of this is fairly nuanced, we should have a te
lshang
2016/06/21 03:00:26
Done.
| |
| 111 }, | 163 }, |
| 112 | 164 |
| 113 searchTermChanged: function(searchedTerm) { | 165 searchTermChanged: function(searchedTerm) { |
| 114 this.syncedDevices_ = []; | 166 this.syncedDevices_ = []; |
| 115 this.updateSyncedDevices(this.sessionList); | 167 this.updateSyncedDevices(this.sessionList); |
| 116 } | 168 } |
| 117 }); | 169 }); |
| OLD | NEW |