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

Side by Side Diff: components/ntp_tiles/most_visited_sites.cc

Issue 2126263002: Add NewTabPage.MostVisited and .SuggestionsImpression on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_provider_id
Patch Set: rebase Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "components/ntp_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray", 246 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.IconsGray",
247 counts_per_type[ICON_DEFAULT]); 247 counts_per_type[ICON_DEFAULT]);
248 } 248 }
249 249
250 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) { 250 void MostVisitedSites::RecordOpenedMostVisitedItem(int index, int tile_type) {
251 // TODO(treib): |current_suggestions_| could be updated before this function 251 // TODO(treib): |current_suggestions_| could be updated before this function
252 // is called, leading to DCHECKs and/or memory corruption. Adjust this 252 // is called, leading to DCHECKs and/or memory corruption. Adjust this
253 // function to work with asynchronous UI. 253 // function to work with asynchronous UI.
254 DCHECK_GE(index, 0); 254 DCHECK_GE(index, 0);
255 DCHECK_LT(index, static_cast<int>(current_suggestions_.size())); 255 DCHECK_LT(index, static_cast<int>(current_suggestions_.size()));
256
257 UMA_HISTOGRAM_ENUMERATION("NewTabPage.MostVisited", index, num_sites_);
258
256 std::string histogram = base::StringPrintf( 259 std::string histogram = base::StringPrintf(
257 "NewTabPage.MostVisited.%s", 260 "NewTabPage.MostVisited.%s",
258 GetSourceHistogramName(current_suggestions_[index].source).c_str()); 261 GetSourceHistogramName(current_suggestions_[index].source).c_str());
259 LogHistogramEvent(histogram, index, num_sites_); 262 LogHistogramEvent(histogram, index, num_sites_);
260 263
261 histogram = base::StringPrintf( 264 histogram = base::StringPrintf(
262 "NewTabPage.TileTypeClicked.%s", 265 "NewTabPage.TileTypeClicked.%s",
263 GetSourceHistogramName(current_suggestions_[index].source).c_str()); 266 GetSourceHistogramName(current_suggestions_[index].source).c_str());
264 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES); 267 LogHistogramEvent(histogram, tile_type, NUM_TILE_TYPES);
265 } 268 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 source_list.AppendBoolean(suggestion.source != POPULAR); 498 source_list.AppendBoolean(suggestion.source != POPULAR);
496 } 499 }
497 prefs_->Set(ntp_tiles::prefs::kNTPSuggestionsIsPersonal, source_list); 500 prefs_->Set(ntp_tiles::prefs::kNTPSuggestionsIsPersonal, source_list);
498 prefs_->Set(ntp_tiles::prefs::kNTPSuggestionsURL, url_list); 501 prefs_->Set(ntp_tiles::prefs::kNTPSuggestionsURL, url_list);
499 } 502 }
500 503
501 void MostVisitedSites::NotifyMostVisitedURLsObserver() { 504 void MostVisitedSites::NotifyMostVisitedURLsObserver() {
502 if (received_most_visited_sites_ && received_popular_sites_ && 505 if (received_most_visited_sites_ && received_popular_sites_ &&
503 !recorded_uma_) { 506 !recorded_uma_) {
504 RecordImpressionUMAMetrics(); 507 RecordImpressionUMAMetrics();
505 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles",
506 current_suggestions_.size());
507 recorded_uma_ = true; 508 recorded_uma_ = true;
508 } 509 }
509 510
510 if (!observer_) 511 if (!observer_)
511 return; 512 return;
512 513
513 observer_->OnMostVisitedURLsAvailable(current_suggestions_); 514 observer_->OnMostVisitedURLsAvailable(current_suggestions_);
514 } 515 }
515 516
516 void MostVisitedSites::OnPopularSitesAvailable(bool success) { 517 void MostVisitedSites::OnPopularSitesAvailable(bool success) {
517 received_popular_sites_ = true; 518 received_popular_sites_ = true;
518 519
519 if (!success) { 520 if (!success) {
520 LOG(WARNING) << "Download of popular sites failed"; 521 LOG(WARNING) << "Download of popular sites failed";
521 return; 522 return;
522 } 523 }
523 524
524 // Pass the popular sites to the observer. This will cause it to fetch any 525 // Pass the popular sites to the observer. This will cause it to fetch any
525 // missing icons, but will *not* cause it to display the popular sites. 526 // missing icons, but will *not* cause it to display the popular sites.
526 observer_->OnPopularURLsAvailable(popular_sites_->sites()); 527 observer_->OnPopularURLsAvailable(popular_sites_->sites());
527 528
528 // Re-build the suggestions list. Once done, this will notify the observer. 529 // Re-build the suggestions list. Once done, this will notify the observer.
529 BuildCurrentSuggestions(); 530 BuildCurrentSuggestions();
530 } 531 }
531 532
532 void MostVisitedSites::RecordImpressionUMAMetrics() { 533 void MostVisitedSites::RecordImpressionUMAMetrics() {
534 UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.NumberOfTiles",
535 current_suggestions_.size());
536
533 for (size_t i = 0; i < current_suggestions_.size(); i++) { 537 for (size_t i = 0; i < current_suggestions_.size(); i++) {
538 UMA_HISTOGRAM_ENUMERATION(
539 "NewTabPage.SuggestionsImpression", static_cast<int>(i), num_sites_);
540
534 std::string histogram = base::StringPrintf( 541 std::string histogram = base::StringPrintf(
535 "NewTabPage.SuggestionsImpression.%s", 542 "NewTabPage.SuggestionsImpression.%s",
536 GetSourceHistogramName(current_suggestions_[i].source).c_str()); 543 GetSourceHistogramName(current_suggestions_[i].source).c_str());
537 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); 544 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_);
538 } 545 }
539 } 546 }
540 547
541 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {} 548 void MostVisitedSites::TopSitesLoaded(TopSites* top_sites) {}
542 549
543 void MostVisitedSites::TopSitesChanged(TopSites* top_sites, 550 void MostVisitedSites::TopSitesChanged(TopSites* top_sites,
544 ChangeReason change_reason) { 551 ChangeReason change_reason) {
545 if (mv_source_ == TOP_SITES) { 552 if (mv_source_ == TOP_SITES) {
546 // The displayed suggestions are invalidated. 553 // The displayed suggestions are invalidated.
547 InitiateTopSitesQuery(); 554 InitiateTopSitesQuery();
548 } 555 }
549 } 556 }
550 557
551 } // namespace ntp_tiles 558 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698