Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/android/most_visited_sites.h" | 5 #include "chrome/browser/android/most_visited_sites.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 // Total number of tiles displayed. | 55 // Total number of tiles displayed. |
| 56 const char kNumTilesHistogramName[] = "NewTabPage.NumberOfTiles"; | 56 const char kNumTilesHistogramName[] = "NewTabPage.NumberOfTiles"; |
| 57 // Tracking thumbnails. | 57 // Tracking thumbnails. |
| 58 const char kNumLocalThumbnailTilesHistogramName[] = | 58 const char kNumLocalThumbnailTilesHistogramName[] = |
| 59 "NewTabPage.NumberOfThumbnailTiles"; | 59 "NewTabPage.NumberOfThumbnailTiles"; |
| 60 const char kNumEmptyTilesHistogramName[] = "NewTabPage.NumberOfGrayTiles"; | 60 const char kNumEmptyTilesHistogramName[] = "NewTabPage.NumberOfGrayTiles"; |
| 61 const char kNumServerTilesHistogramName[] = "NewTabPage.NumberOfExternalTiles"; | 61 const char kNumServerTilesHistogramName[] = "NewTabPage.NumberOfExternalTiles"; |
| 62 // Client suggestion opened. | 62 |
| 63 const char kOpenedItemClientHistogramName[] = "NewTabPage.MostVisited.client"; | 63 // Format for tile clicks histogram. |
| 64 // Server suggestion opened, no provider. | 64 const char kOpenedItemHistogramFormat[] = "NewTabPage.MostVisited.%s"; |
| 65 const char kOpenedItemServerHistogramName[] = "NewTabPage.MostVisited.server"; | 65 // Format for tile impressions histogram. |
| 66 // Server suggestion opened with provider. | 66 const char kImpressionHistogramFormat[] = "NewTabPage.SuggestionsImpression.%s"; |
| 67 const char kOpenedItemServerProviderHistogramFormat[] = | 67 // Identifiers for the various tile sources. |
| 68 "NewTabPage.MostVisited.server%d"; | 68 const char kHistogramClientName[] = "client"; |
| 69 // Client impression. | 69 const char kHistogramServerName[] = "server"; |
| 70 const char kImpressionClientHistogramName[] = | 70 const char kHistogramServerFormat[] = "server%d"; |
| 71 "NewTabPage.SuggestionsImpression.client"; | 71 const char kHistogramPopularName[] = "popular"; |
| 72 // Server suggestion impression, no provider. | |
| 73 const char kImpressionServerHistogramName[] = | |
| 74 "NewTabPage.SuggestionsImpression.server"; | |
| 75 // Server suggestion impression with provider. | |
| 76 const char kImpressionServerHistogramFormat[] = | |
| 77 "NewTabPage.SuggestionsImpression.server%d"; | |
| 78 | 72 |
| 79 const char kPopularSitesFieldTrialName[] = "NTPPopularSites"; | 73 const char kPopularSitesFieldTrialName[] = "NTPPopularSites"; |
| 80 | 74 |
| 81 scoped_ptr<SkBitmap> MaybeFetchLocalThumbnail( | 75 scoped_ptr<SkBitmap> MaybeFetchLocalThumbnail( |
| 82 const GURL& url, | 76 const GURL& url, |
| 83 const scoped_refptr<TopSites>& top_sites) { | 77 const scoped_refptr<TopSites>& top_sites) { |
| 84 DCHECK_CURRENTLY_ON(BrowserThread::DB); | 78 DCHECK_CURRENTLY_ON(BrowserThread::DB); |
| 85 scoped_refptr<base::RefCountedMemory> image; | 79 scoped_refptr<base::RefCountedMemory> image; |
| 86 scoped_ptr<SkBitmap> bitmap; | 80 scoped_ptr<SkBitmap> bitmap; |
| 87 if (top_sites && top_sites->GetPageThumbnail(url, false, &image)) | 81 if (top_sites && top_sites->GetPageThumbnail(url, false, &image)) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 ProfileSyncServiceFactory::GetForProfile(profile_); | 162 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 169 if (profile_sync_service && profile_sync_service->HasObserver(this)) | 163 if (profile_sync_service && profile_sync_service->HasObserver(this)) |
| 170 profile_sync_service->RemoveObserver(this); | 164 profile_sync_service->RemoveObserver(this); |
| 171 } | 165 } |
| 172 | 166 |
| 173 void MostVisitedSites::Destroy(JNIEnv* env, jobject obj) { | 167 void MostVisitedSites::Destroy(JNIEnv* env, jobject obj) { |
| 174 delete this; | 168 delete this; |
| 175 } | 169 } |
| 176 | 170 |
| 177 void MostVisitedSites::OnLoadingComplete(JNIEnv* env, jobject obj) { | 171 void MostVisitedSites::OnLoadingComplete(JNIEnv* env, jobject obj) { |
| 178 RecordUMAMetrics(); | 172 RecordThumbnailUMAMetrics(); |
| 179 } | 173 } |
| 180 | 174 |
| 181 void MostVisitedSites::SetMostVisitedURLsObserver(JNIEnv* env, | 175 void MostVisitedSites::SetMostVisitedURLsObserver(JNIEnv* env, |
| 182 jobject obj, | 176 jobject obj, |
| 183 jobject j_observer, | 177 jobject j_observer, |
| 184 jint num_sites) { | 178 jint num_sites) { |
| 185 observer_.Reset(env, j_observer); | 179 observer_.Reset(env, j_observer); |
| 186 num_sites_ = num_sites; | 180 num_sites_ = num_sites; |
| 187 | 181 |
| 188 QueryMostVisitedURLs(); | 182 QueryMostVisitedURLs(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 suggestions_service->BlacklistURL( | 279 suggestions_service->BlacklistURL( |
| 286 url, base::Bind(&MostVisitedSites::OnSuggestionsProfileAvailable, | 280 url, base::Bind(&MostVisitedSites::OnSuggestionsProfileAvailable, |
| 287 weak_ptr_factory_.GetWeakPtr()), | 281 weak_ptr_factory_.GetWeakPtr()), |
| 288 base::Closure()); | 282 base::Closure()); |
| 289 } | 283 } |
| 290 } | 284 } |
| 291 | 285 |
| 292 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, | 286 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, |
| 293 jobject obj, | 287 jobject obj, |
| 294 jint index) { | 288 jint index) { |
| 295 switch (mv_source_) { | 289 std::string histogram = base::StringPrintf(kOpenedItemHistogramFormat, |
| 296 case TOP_SITES: { | 290 tile_sources_[index].c_str()); |
| 297 UMA_HISTOGRAM_SPARSE_SLOWLY(kOpenedItemClientHistogramName, index); | 291 LogHistogramEvent(histogram, index, num_sites_); |
|
Marc Treib
2015/08/21 13:12:25
Some of the histograms used to be implemented as s
| |
| 298 break; | |
| 299 } | |
| 300 case SUGGESTIONS_SERVICE: { | |
| 301 if (server_suggestions_.suggestions_size() > index) { | |
| 302 if (server_suggestions_.suggestions(index).providers_size()) { | |
| 303 std::string histogram = base::StringPrintf( | |
| 304 kOpenedItemServerProviderHistogramFormat, | |
| 305 server_suggestions_.suggestions(index).providers(0)); | |
| 306 LogHistogramEvent(histogram, index, num_sites_); | |
| 307 } else { | |
| 308 UMA_HISTOGRAM_SPARSE_SLOWLY(kOpenedItemServerHistogramName, index); | |
| 309 } | |
| 310 } | |
| 311 break; | |
| 312 } | |
| 313 } | |
| 314 } | 292 } |
| 315 | 293 |
| 316 void MostVisitedSites::OnStateChanged() { | 294 void MostVisitedSites::OnStateChanged() { |
| 317 // There have been changes to the sync state. This class cares about a few | 295 // There have been changes to the sync state. This class cares about a few |
| 318 // (just initialized, enabled/disabled or history sync state changed). Re-run | 296 // (just initialized, enabled/disabled or history sync state changed). Re-run |
| 319 // the query code which will use the proper state. | 297 // the query code which will use the proper state. |
| 320 QueryMostVisitedURLs(); | 298 QueryMostVisitedURLs(); |
| 321 } | 299 } |
| 322 | 300 |
| 323 // static | 301 // static |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 347 top_sites->GetMostVisitedURLs( | 325 top_sites->GetMostVisitedURLs( |
| 348 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, | 326 base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable, |
| 349 weak_ptr_factory_.GetWeakPtr()), | 327 weak_ptr_factory_.GetWeakPtr()), |
| 350 false); | 328 false); |
| 351 } | 329 } |
| 352 | 330 |
| 353 void MostVisitedSites::OnMostVisitedURLsAvailable( | 331 void MostVisitedSites::OnMostVisitedURLsAvailable( |
| 354 const history::MostVisitedURLList& visited_list) { | 332 const history::MostVisitedURLList& visited_list) { |
| 355 std::vector<base::string16> titles; | 333 std::vector<base::string16> titles; |
| 356 std::vector<std::string> urls; | 334 std::vector<std::string> urls; |
| 335 tile_sources_.clear(); | |
| 357 int num_tiles = std::min(static_cast<int>(visited_list.size()), num_sites_); | 336 int num_tiles = std::min(static_cast<int>(visited_list.size()), num_sites_); |
| 358 for (int i = 0; i < num_tiles; ++i) { | 337 for (int i = 0; i < num_tiles; ++i) { |
| 359 const history::MostVisitedURL& visited = visited_list[i]; | 338 const history::MostVisitedURL& visited = visited_list[i]; |
| 360 if (visited.url.is_empty()) { | 339 if (visited.url.is_empty()) { |
| 361 num_tiles = i; | 340 num_tiles = i; |
| 362 break; // This is the signal that there are no more real visited sites. | 341 break; // This is the signal that there are no more real visited sites. |
| 363 } | 342 } |
| 364 titles.push_back(visited.title); | 343 titles.push_back(visited.title); |
| 365 urls.push_back(visited.url.spec()); | 344 urls.push_back(visited.url.spec()); |
| 345 tile_sources_.push_back(kHistogramClientName); | |
| 366 } | 346 } |
| 367 | 347 |
| 368 // Only log impression metrics on the initial load of the NTP. | |
| 369 if (!initial_load_done_) { | |
| 370 for (int i = 0; i < num_tiles; ++i) { | |
| 371 UMA_HISTOGRAM_SPARSE_SLOWLY(kImpressionClientHistogramName, i); | |
| 372 } | |
| 373 } | |
| 374 mv_source_ = TOP_SITES; | 348 mv_source_ = TOP_SITES; |
| 375 AddPopularSites(&titles, &urls); | 349 AddPopularSites(&titles, &urls); |
| 350 // Only log impression metrics on the initial load of the NTP. | |
| 351 if (!initial_load_done_) | |
| 352 RecordImpressionUMAMetrics(); | |
| 376 NotifyMostVisitedURLsObserver(titles, urls); | 353 NotifyMostVisitedURLsObserver(titles, urls); |
| 377 } | 354 } |
| 378 | 355 |
| 379 void MostVisitedSites::OnSuggestionsProfileAvailable( | 356 void MostVisitedSites::OnSuggestionsProfileAvailable( |
| 380 const SuggestionsProfile& suggestions_profile) { | 357 const SuggestionsProfile& suggestions_profile) { |
| 381 int num_tiles = suggestions_profile.suggestions_size(); | 358 int num_tiles = suggestions_profile.suggestions_size(); |
| 382 // With no server suggestions, fall back to local Most Visited. | 359 // With no server suggestions, fall back to local Most Visited. |
| 383 if (num_tiles == 0) { | 360 if (num_tiles == 0) { |
| 384 InitiateTopSitesQuery(); | 361 InitiateTopSitesQuery(); |
| 385 return; | 362 return; |
| 386 } | 363 } |
| 387 if (num_sites_ < num_tiles) | 364 if (num_sites_ < num_tiles) |
| 388 num_tiles = num_sites_; | 365 num_tiles = num_sites_; |
| 389 | 366 |
| 390 std::vector<base::string16> titles; | 367 std::vector<base::string16> titles; |
| 391 std::vector<std::string> urls; | 368 std::vector<std::string> urls; |
| 369 tile_sources_.clear(); | |
| 392 for (int i = 0; i < num_tiles; ++i) { | 370 for (int i = 0; i < num_tiles; ++i) { |
| 393 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); | 371 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); |
| 394 titles.push_back(base::UTF8ToUTF16(suggestion.title())); | 372 titles.push_back(base::UTF8ToUTF16(suggestion.title())); |
| 395 urls.push_back(suggestion.url()); | 373 urls.push_back(suggestion.url()); |
| 396 // Only log impression metrics on the initial NTP load. | 374 std::string tile_source; |
| 397 if (!initial_load_done_) { | 375 if (suggestion.providers_size()) { |
| 398 if (suggestion.providers_size()) { | 376 tile_source = |
| 399 std::string histogram = base::StringPrintf( | 377 base::StringPrintf(kHistogramServerFormat, suggestion.providers(0)); |
| 400 kImpressionServerHistogramFormat, suggestion.providers(0)); | 378 } else { |
| 401 LogHistogramEvent(histogram, i, num_sites_); | 379 tile_source = kHistogramServerName; |
| 402 } else { | |
| 403 UMA_HISTOGRAM_SPARSE_SLOWLY(kImpressionServerHistogramName, i); | |
| 404 } | |
| 405 } | 380 } |
| 381 tile_sources_.push_back(tile_source); | |
| 406 } | 382 } |
| 407 mv_source_ = SUGGESTIONS_SERVICE; | 383 mv_source_ = SUGGESTIONS_SERVICE; |
| 408 // Keep a copy of the suggestions for eventual logging. | |
| 409 server_suggestions_ = suggestions_profile; | |
| 410 AddPopularSites(&titles, &urls); | 384 AddPopularSites(&titles, &urls); |
| 385 // Only log impression metrics on the initial NTP load. | |
| 386 if (!initial_load_done_) | |
| 387 RecordImpressionUMAMetrics(); | |
| 411 NotifyMostVisitedURLsObserver(titles, urls); | 388 NotifyMostVisitedURLsObserver(titles, urls); |
| 412 } | 389 } |
| 413 | 390 |
| 414 void MostVisitedSites::AddPopularSites(std::vector<base::string16>* titles, | 391 void MostVisitedSites::AddPopularSites(std::vector<base::string16>* titles, |
| 415 std::vector<std::string>* urls) const { | 392 std::vector<std::string>* urls) { |
| 416 if (!popular_sites_) | 393 if (!popular_sites_) |
| 417 return; | 394 return; |
| 418 | 395 |
| 419 DCHECK_EQ(titles->size(), urls->size()); | 396 DCHECK_EQ(titles->size(), urls->size()); |
| 397 DCHECK_EQ(titles->size(), tile_sources_.size()); | |
| 420 DCHECK_LE(static_cast<int>(titles->size()), num_sites_); | 398 DCHECK_LE(static_cast<int>(titles->size()), num_sites_); |
| 421 | 399 |
| 422 // Collect all non-blacklisted popular suggestions. | 400 // Collect all non-blacklisted popular suggestions. |
| 423 std::vector<base::string16> new_titles; | 401 std::vector<base::string16> popular_titles; |
| 424 std::vector<std::string> new_urls; | 402 std::vector<std::string> popular_urls; |
| 425 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); | 403 scoped_refptr<TopSites> top_sites(TopSitesFactory::GetForProfile(profile_)); |
| 426 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { | 404 for (const PopularSites::Site& popular_site : popular_sites_->sites()) { |
| 427 // Skip blacklisted sites. | 405 // Skip blacklisted sites. |
| 428 if (top_sites && top_sites->IsBlacklisted(popular_site.url)) | 406 if (top_sites && top_sites->IsBlacklisted(popular_site.url)) |
| 429 continue; | 407 continue; |
| 430 | 408 |
| 431 new_titles.push_back(popular_site.title); | 409 popular_titles.push_back(popular_site.title); |
| 432 new_urls.push_back(popular_site.url.spec()); | 410 popular_urls.push_back(popular_site.url.spec()); |
| 433 if (static_cast<int>(new_titles.size()) >= num_sites_) | 411 if (static_cast<int>(popular_titles.size()) >= num_sites_) |
| 434 break; | 412 break; |
| 435 } | 413 } |
| 436 | 414 |
| 437 AddPopularSitesImpl(num_sites_, titles, urls, new_titles, new_urls); | 415 AddPopularSitesImpl( |
| 416 num_sites_, titles, urls, &tile_sources_, popular_titles, popular_urls); | |
| 438 } | 417 } |
| 439 | 418 |
| 440 // static | 419 // static |
| 441 void MostVisitedSites::AddPopularSitesImpl( | 420 void MostVisitedSites::AddPopularSitesImpl( |
| 442 int num_sites, | 421 int num_sites, |
| 443 std::vector<base::string16>* titles, | 422 std::vector<base::string16>* titles, |
| 444 std::vector<std::string>* urls, | 423 std::vector<std::string>* urls, |
| 424 std::vector<std::string>* tile_sources, | |
| 445 const std::vector<base::string16>& popular_titles, | 425 const std::vector<base::string16>& popular_titles, |
| 446 const std::vector<std::string>& popular_urls) { | 426 const std::vector<std::string>& popular_urls) { |
| 447 // Start off with the popular suggestions. | 427 // Start off with the popular suggestions. |
| 448 std::vector<base::string16> new_titles(popular_titles); | 428 std::vector<base::string16> new_titles(popular_titles); |
| 449 std::vector<std::string> new_urls(popular_urls); | 429 std::vector<std::string> new_urls(popular_urls); |
| 430 std::vector<std::string> new_tile_sources(new_titles.size(), | |
| 431 kHistogramPopularName); | |
| 450 | 432 |
| 451 // Now, go over the personalized suggestions and replace matching popular | 433 // Now, go over the personalized suggestions and replace matching popular |
| 452 // suggestions. This is so that when some of the popular suggestions become | 434 // suggestions. This is so that when some of the popular suggestions become |
| 453 // personal, they retain their absolute positions. | 435 // personal, they retain their absolute positions. |
| 454 std::vector<bool> new_is_personalized(new_titles.size(), false); | |
| 455 std::vector<base::string16> titles_to_insert; | 436 std::vector<base::string16> titles_to_insert; |
| 456 std::vector<std::string> urls_to_insert; | 437 std::vector<std::string> urls_to_insert; |
| 438 std::vector<std::string> tile_sources_to_insert; | |
| 457 for (size_t site_index = 0; site_index < titles->size(); site_index++) { | 439 for (size_t site_index = 0; site_index < titles->size(); site_index++) { |
| 458 const base::string16& title = (*titles)[site_index]; | 440 const base::string16& title = (*titles)[site_index]; |
| 459 const std::string& url = (*urls)[site_index]; | 441 const std::string& url = (*urls)[site_index]; |
| 442 const std::string& tile_source = (*tile_sources)[site_index]; | |
| 460 // See if we already have a matching popular site. | 443 // See if we already have a matching popular site. |
| 461 bool found = false; | 444 bool found = false; |
| 462 for (size_t i = 0; i < new_urls.size(); i++) { | 445 for (size_t i = 0; i < new_urls.size(); i++) { |
| 463 if (!new_is_personalized[i] && | 446 if (new_tile_sources[i] == kHistogramPopularName && |
| 464 GURL(new_urls[i]).host() == GURL(url).host()) { | 447 GURL(new_urls[i]).host() == GURL(url).host()) { |
| 465 // We have a matching popular sites suggestion. Replace it with the | 448 // We have a matching popular sites suggestion. Replace it with the |
| 466 // actual URL and title. | 449 // actual URL and title. |
| 467 new_titles[i] = title; | 450 new_titles[i] = title; |
| 468 new_urls[i] = url; | 451 new_urls[i] = url; |
| 469 new_is_personalized[i] = true; | 452 new_tile_sources[i] = tile_source; |
| 470 found = true; | 453 found = true; |
| 471 break; | 454 break; |
| 472 } | 455 } |
| 473 } | 456 } |
| 474 if (!found) { | 457 if (!found) { |
| 475 titles_to_insert.push_back(title); | 458 titles_to_insert.push_back(title); |
| 476 urls_to_insert.push_back(url); | 459 urls_to_insert.push_back(url); |
| 460 tile_sources_to_insert.push_back(tile_source); | |
| 477 } | 461 } |
| 478 } | 462 } |
| 479 | 463 |
| 480 // Append personalized suggestions at the end if there's room. | 464 // Append personalized suggestions at the end if there's room. |
| 481 size_t num_to_append = | 465 size_t num_to_append = |
| 482 std::min(static_cast<size_t>(num_sites) - new_titles.size(), | 466 std::min(static_cast<size_t>(num_sites) - new_titles.size(), |
| 483 titles_to_insert.size()); | 467 titles_to_insert.size()); |
| 484 new_titles.insert(new_titles.end(), | 468 new_titles.insert(new_titles.end(), |
| 485 titles_to_insert.end() - num_to_append, | 469 titles_to_insert.end() - num_to_append, |
| 486 titles_to_insert.end()); | 470 titles_to_insert.end()); |
| 487 new_urls.insert(new_urls.end(), | 471 new_urls.insert(new_urls.end(), |
| 488 urls_to_insert.end() - num_to_append, | 472 urls_to_insert.end() - num_to_append, |
| 489 urls_to_insert.end()); | 473 urls_to_insert.end()); |
| 490 new_is_personalized.insert(new_is_personalized.end(), num_to_append, true); | 474 new_tile_sources.insert(new_tile_sources.end(), |
| 475 tile_sources_to_insert.end() - num_to_append, | |
| 476 tile_sources_to_insert.end()); | |
| 491 | 477 |
| 492 // Finally, go over the remaining personalized suggestions and evict popular | 478 // Finally, go over the remaining personalized suggestions and evict popular |
| 493 // suggestions to accommodate them. Do it in reverse order, so the least | 479 // suggestions to accommodate them. Do it in reverse order, so the least |
| 494 // important popular suggestions will be evicted. | 480 // important popular suggestions will be evicted. |
| 495 for (size_t i = titles_to_insert.size() - num_to_append; i > 0; --i) { | 481 for (size_t i = titles_to_insert.size() - num_to_append; i > 0; --i) { |
| 496 const base::string16& title = titles_to_insert[i - 1]; | 482 const base::string16& title = titles_to_insert[i - 1]; |
| 497 const std::string& url = urls_to_insert[i - 1]; | 483 const std::string& url = urls_to_insert[i - 1]; |
| 484 const std::string& tile_source = tile_sources_to_insert[i - 1]; | |
| 498 for (size_t insert_i = new_titles.size(); insert_i > 0; --insert_i) { | 485 for (size_t insert_i = new_titles.size(); insert_i > 0; --insert_i) { |
| 499 size_t insert_index = insert_i - 1; | 486 size_t insert_index = insert_i - 1; |
| 500 if (!new_is_personalized[insert_index]) { | 487 if (new_tile_sources[insert_index] == kHistogramPopularName) { |
| 501 new_titles[insert_index] = title; | 488 new_titles[insert_index] = title; |
| 502 new_urls[insert_index] = url; | 489 new_urls[insert_index] = url; |
| 503 new_is_personalized[insert_index] = true; | 490 new_tile_sources[insert_index] = tile_source; |
| 504 break; | 491 break; |
| 505 } | 492 } |
| 506 } | 493 } |
| 507 } | 494 } |
| 508 | 495 |
| 509 titles->swap(new_titles); | 496 titles->swap(new_titles); |
| 510 urls->swap(new_urls); | 497 urls->swap(new_urls); |
| 498 tile_sources->swap(new_tile_sources); | |
| 511 } | 499 } |
| 512 | 500 |
| 513 void MostVisitedSites::NotifyMostVisitedURLsObserver( | 501 void MostVisitedSites::NotifyMostVisitedURLsObserver( |
| 514 const std::vector<base::string16>& titles, | 502 const std::vector<base::string16>& titles, |
| 515 const std::vector<std::string>& urls) { | 503 const std::vector<std::string>& urls) { |
| 516 DCHECK_EQ(titles.size(), urls.size()); | 504 DCHECK_EQ(titles.size(), urls.size()); |
| 517 if (!initial_load_done_) | 505 if (!initial_load_done_) |
| 518 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, titles.size()); | 506 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, titles.size()); |
| 519 initial_load_done_ = true; | 507 initial_load_done_ = true; |
| 520 JNIEnv* env = AttachCurrentThread(); | 508 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 539 favicon_urls.push_back(popular_site.favicon_url.spec()); | 527 favicon_urls.push_back(popular_site.favicon_url.spec()); |
| 540 } | 528 } |
| 541 JNIEnv* env = AttachCurrentThread(); | 529 JNIEnv* env = AttachCurrentThread(); |
| 542 Java_MostVisitedURLsObserver_onPopularURLsAvailable( | 530 Java_MostVisitedURLsObserver_onPopularURLsAvailable( |
| 543 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), | 531 env, observer_.obj(), ToJavaArrayOfStrings(env, urls).obj(), |
| 544 ToJavaArrayOfStrings(env, favicon_urls).obj()); | 532 ToJavaArrayOfStrings(env, favicon_urls).obj()); |
| 545 | 533 |
| 546 QueryMostVisitedURLs(); | 534 QueryMostVisitedURLs(); |
| 547 } | 535 } |
| 548 | 536 |
| 549 void MostVisitedSites::RecordUMAMetrics() { | 537 void MostVisitedSites::RecordThumbnailUMAMetrics() { |
| 550 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, | 538 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, |
| 551 num_local_thumbs_); | 539 num_local_thumbs_); |
| 552 num_local_thumbs_ = 0; | 540 num_local_thumbs_ = 0; |
| 553 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); | 541 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); |
| 554 num_empty_thumbs_ = 0; | 542 num_empty_thumbs_ = 0; |
| 555 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); | 543 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); |
| 556 num_server_thumbs_ = 0; | 544 num_server_thumbs_ = 0; |
| 557 } | 545 } |
| 558 | 546 |
| 547 void MostVisitedSites::RecordImpressionUMAMetrics() { | |
| 548 for (size_t i = 0; i < tile_sources_.size(); i++) { | |
| 549 std::string histogram = base::StringPrintf(kImpressionHistogramFormat, | |
| 550 tile_sources_[i].c_str()); | |
| 551 LogHistogramEvent(histogram, static_cast<int>(i), num_sites_); | |
| 552 } | |
| 553 } | |
| 554 | |
| 559 void MostVisitedSites::TopSitesLoaded(history::TopSites* top_sites) { | 555 void MostVisitedSites::TopSitesLoaded(history::TopSites* top_sites) { |
| 560 } | 556 } |
| 561 | 557 |
| 562 void MostVisitedSites::TopSitesChanged(history::TopSites* top_sites, | 558 void MostVisitedSites::TopSitesChanged(history::TopSites* top_sites, |
| 563 ChangeReason change_reason) { | 559 ChangeReason change_reason) { |
| 564 if (mv_source_ == TOP_SITES) { | 560 if (mv_source_ == TOP_SITES) { |
| 565 // The displayed suggestions are invalidated. | 561 // The displayed suggestions are invalidated. |
| 566 QueryMostVisitedURLs(); | 562 QueryMostVisitedURLs(); |
| 567 } | 563 } |
| 568 } | 564 } |
| 569 | 565 |
| 570 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { | 566 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { |
| 571 MostVisitedSites* most_visited_sites = | 567 MostVisitedSites* most_visited_sites = |
| 572 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 568 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 573 return reinterpret_cast<intptr_t>(most_visited_sites); | 569 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 574 } | 570 } |
| OLD | NEW |