Chromium Code Reviews| Index: chrome/browser/resources/md_history/synced_device_manager.js |
| diff --git a/chrome/browser/resources/md_history/synced_device_manager.js b/chrome/browser/resources/md_history/synced_device_manager.js |
| index ab273b3e73a71c7d4dddb73667f6e435bae428f2..92679068ca0971d7486bcbc92af01418ef12c1bb 100644 |
| --- a/chrome/browser/resources/md_history/synced_device_manager.js |
| +++ b/chrome/browser/resources/md_history/synced_device_manager.js |
| @@ -36,6 +36,16 @@ Polymer({ |
| syncedDevices_: { |
| type: Array, |
| value: function() { return []; } |
| + }, |
| + |
| + signInState_: { |
| + type: Boolean, |
| + value: loadTimeData.getBoolean('isUserSignedIn'), |
| + }, |
| + |
| + fetchingSyncedTabs_: { |
| + type: Boolean, |
| + value: false, |
| } |
| }, |
| @@ -81,6 +91,35 @@ Polymer({ |
| }; |
| }, |
| + |
| + onSignInTap_: function() { |
| + chrome.send('SyncSetupShowSetupUI'); |
| + chrome.send('SyncSetupStartSignIn', [false]); |
| + }, |
| + |
| + clearDisplayedSyncedDevices: function() { |
| + this.syncedDevices_ = []; |
| + }, |
| + |
| + /** |
| + * Decide whether or not should display no synced tabs message. |
| + * @param {boolean} signInState |
| + * @param {number} syncedDevicesLength |
|
tsergeant
2016/06/21 04:33:51
Add an @return
lshang
2016/06/21 05:40:00
Done.
|
| + */ |
| + showNoSyncedMessage: function(signInState, syncedDevicesLength) { |
| + return signInState && syncedDevicesLength == 0; |
| + }, |
| + |
| + /** |
| + * 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.
|
| + * no synced tabs. |
| + * @param {boolean} fetchingSyncedTabs |
|
tsergeant
2016/06/21 04:33:51
Add an @return as well
lshang
2016/06/21 05:40:00
Done.
|
| + */ |
| + noSyncedTabsMessage: function(fetchingSyncedTabs) { |
| + return loadTimeData.getString( |
| + fetchingSyncedTabs ? 'loading' : 'noSyncedResults'); |
| + }, |
| + |
| /** |
| * Replaces the currently displayed synced tabs with |sessionList|. It is |
| * common for only a single session within the list to have changed, We try to |
| @@ -90,8 +129,10 @@ Polymer({ |
| * @param {?Array<!ForeignSession>} sessionList |
| */ |
| updateSyncedDevices: function(sessionList) { |
| - if (!sessionList) |
| + if (!sessionList) { |
| + 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.
|
| return; |
| + } |
| // First, update any existing devices that have changed. |
| var updateCount = Math.min(sessionList.length, this.syncedDevices_.length); |
| @@ -108,10 +149,35 @@ Polymer({ |
| for (var i = updateCount; i < sessionList.length; i++) { |
| this.push('syncedDevices_', this.createInternalDevice_(sessionList[i])); |
| } |
| + |
| + this.fetchingSyncedTabs_ = false; |
| + }, |
| + |
| + /** |
| + * Get called when user's sign in state changes, this will affect UI of synced |
| + * tabs page. Sign in promo gets displayed when user is signed out, and |
| + * different messages are shown when there is no synced tabs. |
| + * @param {boolean} isUserSignedIn |
| + */ |
| + updateSignInState: function(isUserSignedIn) { |
| + // If user's sign in state didn't change, then don't change message or |
| + // update UI. |
| + if (this.signInState_ == isUserSignedIn) |
| + return; |
| + this.signInState_ = isUserSignedIn; |
| + |
| + // User signed out, clear synced device list and show the sign in promo. |
| + if (!isUserSignedIn) { |
| + this.clearDisplayedSyncedDevices(); |
| + } else { |
| + // User signed in, show the loading message when querying for synced |
| + // devices. |
| + this.fetchingSyncedTabs_ = true; |
| + } |
| }, |
| searchTermChanged: function(searchedTerm) { |
| - this.syncedDevices_ = []; |
| + this.clearDisplayedSyncedDevices(); |
| this.updateSyncedDevices(this.sessionList); |
| } |
| }); |