 Chromium Code Reviews
 Chromium Code Reviews Issue 10182006:
  Adds the MostVisitedAction stat. This stat will provide a baseline to compare  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/
    
  
    Issue 10182006:
  Adds the MostVisitedAction stat. This stat will provide a baseline to compare  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('ntp', function() { | 5 cr.define('ntp', function() { | 
| 6 'use strict'; | 6 'use strict'; | 
| 7 | 7 | 
| 8 var TilePage = ntp.TilePage; | 8 var TilePage = ntp.TilePage; | 
| 9 | 9 | 
| 10 /** | 10 /** | 
| 11 * See description for these values in suggestions_page_handler.h. | 11 * See description for these values in ntp_stats.h. | 
| 12 * @enum {number} | 12 * @enum {number} | 
| 13 */ | 13 */ | 
| 14 var SuggestedSitesAction = { | 14 var NtpFollowAction = { | 
| 15 CLICKED_SUGGESTED_TILE: 11, | 15 CLICKED_TILE: 11, | 
| 16 CLICKED_OTHER_NTP_PANE: 12, | 16 CLICKED_OTHER_NTP_PANE: 12, | 
| 17 OTHER: 13 | 17 OTHER: 13 | 
| 18 }; | 18 }; | 
| 19 | 19 | 
| 20 /** | 20 /** | 
| 21 * A counter for generating unique tile IDs. | 21 * A counter for generating unique tile IDs. | 
| 22 */ | 22 */ | 
| 23 var tileID = 0; | 23 var tileID = 0; | 
| 24 | 24 | 
| 25 /** | 25 /** | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 */ | 138 */ | 
| 139 handleClick_: function(e) { | 139 handleClick_: function(e) { | 
| 140 if (e.target.classList.contains('close-button')) { | 140 if (e.target.classList.contains('close-button')) { | 
| 141 this.blacklist_(); | 141 this.blacklist_(); | 
| 142 e.preventDefault(); | 142 e.preventDefault(); | 
| 143 } else { | 143 } else { | 
| 144 // Records the index of this tile. | 144 // Records the index of this tile. | 
| 145 chrome.send('metricsHandler:recordInHistogram', | 145 chrome.send('metricsHandler:recordInHistogram', | 
| 146 ['NewTabPage.SuggestedSite', this.index, 8]); | 146 ['NewTabPage.SuggestedSite', this.index, 8]); | 
| 147 chrome.send('suggestedSitesAction', | 147 chrome.send('suggestedSitesAction', | 
| 148 [SuggestedSitesAction.CLICKED_SUGGESTED_TILE]); | 148 [NtpFollowAction.CLICKED_TILE]); | 
| 149 } | 149 } | 
| 150 }, | 150 }, | 
| 151 | 151 | 
| 152 /** | 152 /** | 
| 153 * Allow blacklisting suggestions site using the keyboard. | 153 * Allow blacklisting suggestions site using the keyboard. | 
| 154 * @param {Event} e The keydown event. | 154 * @param {Event} e The keydown event. | 
| 155 */ | 155 */ | 
| 156 handleKeyDown_: function(e) { | 156 handleKeyDown_: function(e) { | 
| 157 if (!cr.isMac && e.keyCode == 46 || // Del | 157 if (!cr.isMac && e.keyCode == 46 || // Del | 
| 158 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 158 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 293 | 
| 294 SuggestionsPage.prototype = { | 294 SuggestionsPage.prototype = { | 
| 295 __proto__: TilePage.prototype, | 295 __proto__: TilePage.prototype, | 
| 296 | 296 | 
| 297 initialize: function() { | 297 initialize: function() { | 
| 298 this.classList.add('suggestions-page'); | 298 this.classList.add('suggestions-page'); | 
| 299 this.data_ = null; | 299 this.data_ = null; | 
| 300 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); | 300 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); | 
| 301 | 301 | 
| 302 this.addEventListener('carddeselected', this.handleCardDeselected_); | 302 this.addEventListener('carddeselected', this.handleCardDeselected_); | 
| 303 this.addEventListener('cardselected', this.handleCardSelected_); | 303 this.addEventListener('cardselected', this.handleCardSelected_); | 
| 
beaudoin
2012/04/23 16:46:52
I see it's being done this way here. I think havin
 
macourteau
2012/04/23 19:49:41
(see other comment).
 | |
| 304 }, | 304 }, | 
| 305 | 305 | 
| 306 /** | 306 /** | 
| 307 * Create blank (filler) tiles. | 307 * Create blank (filler) tiles. | 
| 308 * @private | 308 * @private | 
| 309 */ | 309 */ | 
| 310 createTiles_: function() { | 310 createTiles_: function() { | 
| 311 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 311 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 
| 312 this.appendTile(new Suggestion()); | 312 this.appendTile(new Suggestion()); | 
| 313 } | 313 } | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 327 tile.updateForData(page); | 327 tile.updateForData(page); | 
| 328 } | 328 } | 
| 329 }, | 329 }, | 
| 330 | 330 | 
| 331 /** | 331 /** | 
| 332 * Handles the 'card deselected' event (i.e. the user clicked to another | 332 * Handles the 'card deselected' event (i.e. the user clicked to another | 
| 333 * pane). | 333 * pane). | 
| 334 * @param {Event} e The CardChanged event. | 334 * @param {Event} e The CardChanged event. | 
| 335 */ | 335 */ | 
| 336 handleCardDeselected_: function(e) { | 336 handleCardDeselected_: function(e) { | 
| 337 chrome.send('suggestedSitesAction', | 337 if (!document.documentElement.classList.contains('starting-up')) { | 
| 338 [SuggestedSitesAction.CLICKED_OTHER_NTP_PANE]); | 338 chrome.send('suggestedSitesAction', | 
| 339 [NtpFollowAction.CLICKED_OTHER_NTP_PANE]); | |
| 340 } | |
| 339 }, | 341 }, | 
| 340 | 342 | 
| 341 /** | 343 /** | 
| 342 * Handles the 'card selected' event (i.e. the user clicked to select the | 344 * Handles the 'card selected' event (i.e. the user clicked to select the | 
| 343 * Suggested pane). | 345 * Suggested pane). | 
| 344 * @param {Event} e The CardChanged event. | 346 * @param {Event} e The CardChanged event. | 
| 345 */ | 347 */ | 
| 346 handleCardSelected_: function(e) { | 348 handleCardSelected_: function(e) { | 
| 347 chrome.send('suggestedSitesSelected'); | 349 if (!document.documentElement.classList.contains('starting-up')) { | 
| 350 chrome.send('suggestedSitesSelected'); | |
| 351 } | |
| 348 }, | 352 }, | 
| 349 | 353 | 
| 350 /** | 354 /** | 
| 351 * Array of suggestions data objects. | 355 * Array of suggestions data objects. | 
| 352 * @type {Array} | 356 * @type {Array} | 
| 353 */ | 357 */ | 
| 354 get data() { | 358 get data() { | 
| 355 return this.data_; | 359 return this.data_; | 
| 356 }, | 360 }, | 
| 357 set data(data) { | 361 set data(data) { | 
| 358 var startTime = Date.now(); | 362 var startTime = Date.now(); | 
| 359 | 363 | 
| 360 // The first time data is set, create the tiles. | 364 // The first time data is set, create the tiles. | 
| 361 if (!this.data_) { | 365 if (!this.data_) { | 
| 362 this.createTiles_(); | 366 this.createTiles_(); | 
| 363 this.data_ = data.slice(0, THUMBNAIL_COUNT); | 367 this.data_ = data.slice(0, THUMBNAIL_COUNT); | 
| 364 } else { | 368 } else { | 
| 365 this.data_ = refreshData(this.data_, data); | 369 this.data_ = refreshData(this.data_, data); | 
| 366 } | 370 } | 
| 367 | 371 | 
| 368 this.updateTiles_(); | 372 this.updateTiles_(); | 
| 369 logEvent('suggestions.layout: ' + (Date.now() - startTime)); | 373 logEvent('suggestions.layout: ' + (Date.now() - startTime)); | 
| 370 }, | 374 }, | 
| 371 | 375 | 
| 372 /** @inheritDoc */ | 376 /** @inheritDoc */ | 
| 373 shouldAcceptDrag: function(e) { | 377 shouldAcceptDrag: function(e) { | 
| 374 return false; | 378 return false; | 
| 375 }, | 379 }, | 
| 376 | 380 | 
| 381 /** | |
| 382 * Executed once the NTP has loaded. Checks if the Suggested pane is | |
| 383 * shown or not. | |
| 384 */ | |
| 385 onLoaded: function() { | |
| 386 if (ntp.getCardSlider() && ntp.getCardSlider().currentCardValue) { | |
| 387 if (ntp.getCardSlider().currentCardValue.classList | |
| 388 .contains('suggestions-page')) { | |
| 389 chrome.send('suggestedSitesSelected'); | |
| 390 } | |
| 391 } | |
| 392 }, | |
| 393 | |
| 377 /** @inheritDoc */ | 394 /** @inheritDoc */ | 
| 378 heightForWidth: heightForWidth, | 395 heightForWidth: heightForWidth, | 
| 379 }; | 396 }; | 
| 380 | 397 | 
| 381 /** | 398 /** | 
| 382 * We've gotten additional data for Suggestions page. Update our old data with | 399 * We've gotten additional data for Suggestions page. Update our old data with | 
| 383 * the new data. The ordering of the new data is not important, except when a | 400 * the new data. The ordering of the new data is not important, except when a | 
| 384 * page is pinned. Thus we try to minimize re-ordering. | 401 * page is pinned. Thus we try to minimize re-ordering. | 
| 385 * @param {Array} oldData The current Suggestions page list. | 402 * @param {Array} oldData The current Suggestions page list. | 
| 386 * @param {Array} newData The new Suggestions page list. | 403 * @param {Array} newData The new Suggestions page list. | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 } | 465 } | 
| 449 | 466 | 
| 450 return oldData; | 467 return oldData; | 
| 451 } | 468 } | 
| 452 | 469 | 
| 453 return { | 470 return { | 
| 454 SuggestionsPage: SuggestionsPage, | 471 SuggestionsPage: SuggestionsPage, | 
| 455 refreshData: refreshData, | 472 refreshData: refreshData, | 
| 456 }; | 473 }; | 
| 457 }); | 474 }); | 
| 475 | |
| 476 document.addEventListener('ntploaded', ntp.SuggestionsPage.prototype.onLoaded); | |
| 
beaudoin
2012/04/23 16:46:52
Same comment.
 
macourteau
2012/04/23 19:49:41
Done.
 | |
| OLD | NEW |