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

Unified Diff: chrome/browser/resources/print_preview/search/destination_search.js

Issue 233623003: Remember and restore the account last used destination is registered for. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust PrintPreview unit test. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/search/destination_search.js
diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js
index 71f02017b8a7633bc0d70a4f28eebc4b24f117dd..9d25c35c2c2ff2193f8d2b1126d942a9c46a809f 100644
--- a/chrome/browser/resources/print_preview/search/destination_search.js
+++ b/chrome/browser/resources/print_preview/search/destination_search.js
@@ -147,6 +147,9 @@ cr.define('print_preview', function() {
print_preview.Metrics.DestinationSearchBucket.
CLOUDPRINT_PROMO_SHOWN);
}
+ if (this.userInfo_.initialized) {
+ this.onUsersChanged_();
+ }
this.reflowLists_();
} else {
this.getElement().classList.add('transparent');
@@ -224,7 +227,7 @@ cr.define('print_preview', function() {
this.tracker.add(
this.destinationStore_,
print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE,
- this.updateThrobbers_.bind(this));
+ this.onDestinationSearchDone_.bind(this));
this.tracker.add(
this.localList_,
@@ -312,7 +315,9 @@ cr.define('print_preview', function() {
var cloudDestinations = [];
var unregisteredCloudDestinations = [];
- this.destinationStore_.destinations.forEach(function(destination) {
+ var destinations =
+ this.destinationStore_.destinations(this.userInfo_.activeUser);
+ destinations.forEach(function(destination) {
if (destination.isRecent) {
recentDestinations.push(destination);
}
@@ -408,18 +413,16 @@ cr.define('print_preview', function() {
this.reflowLists_();
},
-
/**
- * Updates the account selection UI.
- * @param {string} email Email of the logged in user.
- * @param {!Array.<string>} accounts List of logged in user accounts.
+ * Called when user's logged in accounts change. Updates the UI.
+ * @private
*/
- setAccounts_: function(email, accounts) {
- var loggedIn = !!email;
+ onUsersChanged_: function() {
+ var loggedIn = this.userInfo_.loggedIn;
if (loggedIn) {
var accountSelectEl = this.getChildElement('.account-select');
accountSelectEl.innerHTML = '';
- accounts.forEach(function(account) {
+ this.userInfo_.users.forEach(function(account) {
var option = document.createElement('option');
option.text = account;
option.value = account;
@@ -430,7 +433,8 @@ cr.define('print_preview', function() {
option.value = '';
accountSelectEl.add(option);
- accountSelectEl.selectedIndex = accounts.indexOf(email);
+ accountSelectEl.selectedIndex =
+ this.userInfo_.users.indexOf(this.userInfo_.activeUser);
}
setIsVisible(this.getChildElement('.user-info'), loggedIn);
@@ -480,7 +484,8 @@ cr.define('print_preview', function() {
* @private
*/
onDestinationStoreSelect_: function() {
- var destinations = this.destinationStore_.destinations;
+ var destinations =
+ this.destinationStore_.destinations(this.userInfo_.activeUser);
var recentDestinations = [];
destinations.forEach(function(destination) {
if (destination.isRecent) {
@@ -502,6 +507,17 @@ cr.define('print_preview', function() {
},
/**
+ * Called when destinations are inserted into the store. Rerenders
+ * destinations.
+ * @private
+ */
+ onDestinationSearchDone_: function() {
+ this.updateThrobbers_();
+ this.renderDestinations_();
+ this.reflowLists_();
+ },
+
+ /**
* Called when the manage cloud printers action is activated.
* @private
*/
@@ -543,6 +559,7 @@ cr.define('print_preview', function() {
accountSelectEl.options[accountSelectEl.selectedIndex].value;
if (account) {
this.userInfo_.activeUser = account;
+ this.destinationStore_.reloadUserCookieBasedDestinations();
} else {
cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT);
// Set selection back to the active user.
@@ -584,14 +601,6 @@ cr.define('print_preview', function() {
},
/**
- * Called when user's logged in accounts change. Updates the UI.
- * @private
- */
- onUsersChanged_: function() {
- this.setAccounts_(this.userInfo_.activeUser, this.userInfo_.users);
- },
-
- /**
* Called when the window is resized. Reflows layout of destination lists.
* @private
*/

Powered by Google App Engine
This is Rietveld 408576698