Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/drive_banners.js |
| diff --git a/chrome/browser/resources/file_manager/js/drive_banners.js b/chrome/browser/resources/file_manager/js/drive_banners.js |
| index b1621e8ca22a218c03210f0d0aa5cb747cb5f611..b7efe6aeb27311fbd49b1a26cfa108ae6dbbc770 100644 |
| --- a/chrome/browser/resources/file_manager/js/drive_banners.js |
| +++ b/chrome/browser/resources/file_manager/js/drive_banners.js |
| @@ -14,9 +14,10 @@ function FileListBannerController(directoryModel, document) { |
| this.driveEnabled_ = false; |
| var board = str('CHROMEOS_RELEASE_BOARD'); |
| - // It is 'canary' or 'beta' for the other channels. |
| - var releaseChannel = str('BROWSER_VERSION_MODIFIER') == ''; |
| - this.newWelcome_ = board.match(/^(stumpy|lumpy)/i) && releaseChannel; |
| + if (board.match(/^(stumpy|lumpy)/i)) |
| + this.checkPromoAvailable_(); |
| + else |
| + this.newWelcome_ = false; |
| var handler = this.checkSpaceAndShowBanner_.bind(this); |
| this.directoryModel_.addEventListener('scan-completed', handler); |
| @@ -58,6 +59,8 @@ var GOOGLE_DRIVE_FAQ_URL = |
| var GOOGLE_DRIVE_BUY_STORAGE = |
| 'https://www.google.com/settings/storage'; |
| +var GOOGLE_DRIVE_REDEEM = 'https://drive.google.com/redeem'; |
| + |
| /** |
| * Location of the FAQ about the downloads directory. |
| */ |
| @@ -159,19 +162,23 @@ FileListBannerController.prototype.maybeShowBanner_ = function() { |
| // The timeout below is required because sometimes another |
| // 'rescan-completed' event arrives shortly with non-empty file list. |
| var self = this; |
| - setTimeout(function() { |
| + setTimeout(this.preparePromo_.bind(this, function() { |
| var container = self.document_.querySelector('.dialog-container'); |
| if (self.isOnGData() && |
| container.getAttribute('gdrive-welcome') != 'header') |
| self.showBanner_('page', 'GDATA_WELCOME_TEXT_LONG'); |
| - }, 2000); |
| + }, 2000)); |
| } else if (counter < WELCOME_HEADER_COUNTER_LIMIT) { |
| // We do not want to increment the counter when the user navigates |
| // between different directories on GDrive, but we increment the counter |
| // once anyway to prevent the full page banner from showing. |
| - if (!this.previousDirWasOnGData_ || counter == 0) |
| - localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; |
| - this.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); |
| + if (!this.previousDirWasOnGData_ || counter == 0) { |
| + var self = this; |
| + this.preparePromo_(function() { |
| + localStorage[WELCOME_HEADER_COUNTER_KEY] = ++counter; |
| + self.showBanner_('header', 'GDATA_WELCOME_TEXT_SHORT'); |
| + }); |
| + } |
| } else { |
| this.closeBanner_(); |
| } |
| @@ -188,6 +195,12 @@ FileListBannerController.prototype.showLowGDriveSpaceWarning_ = |
| function(show, sizeStats) { |
| var box = this.document_.querySelector('.gdrive-space-warning'); |
| + // Avoid showing two banners. |
| + // TODO(kaznacheev): Unify the low space warning and the promo header. |
| + if (show) this.cleanupGDataWelcome_(); |
| + |
| + if (box.hidden == !show) return; |
| + |
| // If the warning was dismissed before, this key stores the quota value |
| // (as of the moment of dismissal). |
| // If the warning was never dismissed or was reset this key stores 0. |
| @@ -206,12 +219,6 @@ FileListBannerController.prototype.showLowGDriveSpaceWarning_ = |
| } |
| } |
| - // Avoid showing two banners. |
| - // TODO(kaznacheev): Unify the low space warning and the promo header. |
| - if (show) this.cleanupGDataWelcome_(); |
| - |
| - if (box.hidden == !show) return; |
| - |
| box.textContent = ''; |
| if (show) { |
| var icon = this.document_.createElement('div'); |
| @@ -325,16 +332,18 @@ FileListBannerController.prototype.closeBanner_ = function() { |
| */ |
| FileListBannerController.prototype.checkSpaceAndShowBanner_ = function() { |
| var self = this; |
| - if (this.newWelcome_ && this.isOnGData()) |
| - chrome.fileBrowserPrivate.getSizeStats( |
| - util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), |
| - function(result) { |
| - if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. |
| - self.newWelcome_ = false; |
| - self.maybeShowBanner_(); |
| - }); |
| - else |
| - self.maybeShowBanner_(); |
| + this.preparePromo_(function() { |
| + if (this.newWelcome_ && this.isOnGData()) |
| + chrome.fileBrowserPrivate.getSizeStats( |
| + util.makeFilesystemUrl(this.directoryModel_.getCurrentRootPath()), |
| + function(result) { |
| + if (result.totalSizeKB >= 100 * 1024 * 1024) // Already >= 100 GB. |
| + self.newWelcome_ = false; |
| + self.maybeShowBanner_(); |
| + }); |
| + else |
| + self.maybeShowBanner_(); |
| + }); |
| }; |
| /** |
| @@ -414,3 +423,36 @@ FileListBannerController.prototype.showLowDownloadsSpaceWarning_ = |
| this.requestRelayout_(100); |
| }; |
| +/** |
| + * Detects what type of promo should be shown. |
| + * @private |
| + */ |
| +FileListBannerController.prototype.checkPromoAvailable_ = function() { |
| + var r = new XMLHttpRequest(); |
| + var self = this; |
|
Vladislav Kaznacheev
2012/09/14 12:18:45
Why not bind(this)? It would save you 1 line of th
SeRya
2012/09/14 14:36:23
Done.
|
| + r.open('HEAD', GOOGLE_DRIVE_REDEEM, true); |
| + r.onreadystatechange = function() { |
| + if (r.readyState != 4) |
| + return; |
| + self.newWelcome_ = r.status == 404; |
|
Vladislav Kaznacheev
2012/09/14 12:18:45
It will show you the new welcome today, right?
I t
SeRya
2012/09/14 14:36:23
Done.
|
| + if (self.promoCallbacks_) { |
| + for (var i = 0; i < self.promoCallbacks_.length; i++) |
| + self.promoCallbacks_[i](); |
| + self.promoCallbacks_ = undefined; |
| + } |
| + }; |
| + r.send(); |
| +}; |
| + |
| +/** |
| + * @param {Function} completeCallback To be called (may be directly) when |
| + * this.newWelcome_ get ready. |
| + * @private |
| + */ |
| +FileListBannerController.prototype.preparePromo_ = function(completeCallback) { |
| + if (this.newWelcome_ !== undefined) |
| + completeCallback(); |
| + else |
| + (this.promoCallbacks_ = this.promoCallbacks_ || []).push(completeCallback); |
| +}; |
| + |