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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 // Total number of tiles displayed. | 52 // Total number of tiles displayed. |
| 53 const char kNumTilesHistogramName[] = "NewTabPage.NumberOfTiles"; | 53 const char kNumTilesHistogramName[] = "NewTabPage.NumberOfTiles"; |
| 54 // Tracking thumbnails. | 54 // Tracking thumbnails. |
| 55 const char kNumLocalThumbnailTilesHistogramName[] = | 55 const char kNumLocalThumbnailTilesHistogramName[] = |
| 56 "NewTabPage.NumberOfThumbnailTiles"; | 56 "NewTabPage.NumberOfThumbnailTiles"; |
| 57 const char kNumEmptyTilesHistogramName[] = "NewTabPage.NumberOfGrayTiles"; | 57 const char kNumEmptyTilesHistogramName[] = "NewTabPage.NumberOfGrayTiles"; |
| 58 const char kNumServerTilesHistogramName[] = "NewTabPage.NumberOfExternalTiles"; | 58 const char kNumServerTilesHistogramName[] = "NewTabPage.NumberOfExternalTiles"; |
| 59 // Client suggestion opened. | 59 // Client suggestion opened. |
| 60 const char kOpenedItemClientHistogramName[] = "NewTabPage.MostVisited.client"; | 60 const char kOpenedItemClientHistogramName[] = "NewTabPage.MostVisited.client"; |
| 61 // Control group suggestion opened. | |
| 62 const char kOpenedItemControlHistogramName[] = "NewTabPage.MostVisited.client0"; | |
| 61 // Server suggestion opened, no provider. | 63 // Server suggestion opened, no provider. |
| 62 const char kOpenedItemServerHistogramName[] = "NewTabPage.MostVisited.server"; | 64 const char kOpenedItemServerHistogramName[] = "NewTabPage.MostVisited.server"; |
| 63 // Server suggestion opened with provider. | 65 // Server suggestion opened with provider. |
| 64 const char kOpenedItemServerProviderHistogramFormat[] = | 66 const char kOpenedItemServerProviderHistogramFormat[] = |
| 65 "NewTabPage.MostVisited.server%d"; | 67 "NewTabPage.MostVisited.server%d"; |
| 66 // Client impression. | 68 // Client impression. |
| 67 const char kImpressionClientHistogramName[] = | 69 const char kImpressionClientHistogramName[] = |
| 68 "NewTabPage.SuggestionsImpression.client"; | 70 "NewTabPage.SuggestionsImpression.client"; |
| 71 // Control group impression. | |
| 72 const char kImpressionControlHistogramName[] = | |
| 73 "NewTabPage.SuggestionsImpression.client0"; | |
| 69 // Server suggestion impression, no provider. | 74 // Server suggestion impression, no provider. |
| 70 const char kImpressionServerHistogramName[] = | 75 const char kImpressionServerHistogramName[] = |
| 71 "NewTabPage.SuggestionsImpression.server"; | 76 "NewTabPage.SuggestionsImpression.server"; |
| 72 // Server suggestion impression with provider. | 77 // Server suggestion impression with provider. |
| 73 const char kImpressionServerHistogramFormat[] = | 78 const char kImpressionServerHistogramFormat[] = |
| 74 "NewTabPage.SuggestionsImpression.server%d"; | 79 "NewTabPage.SuggestionsImpression.server%d"; |
| 75 | 80 |
| 76 void ExtractMostVisitedTitlesAndURLs( | 81 void ExtractMostVisitedTitlesAndURLs( |
| 77 const history::MostVisitedURLList& visited_list, | 82 const history::MostVisitedURLList& visited_list, |
| 78 std::vector<base::string16>* titles, | 83 std::vector<base::string16>* titles, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 1, | 166 1, |
| 162 num_sites, | 167 num_sites, |
| 163 num_sites + 1, | 168 num_sites + 1, |
| 164 base::Histogram::kUmaTargetedHistogramFlag); | 169 base::Histogram::kUmaTargetedHistogramFlag); |
| 165 counter->Add(position); | 170 counter->Add(position); |
| 166 } | 171 } |
| 167 | 172 |
| 168 } // namespace | 173 } // namespace |
| 169 | 174 |
| 170 MostVisitedSites::MostVisitedSites(Profile* profile) | 175 MostVisitedSites::MostVisitedSites(Profile* profile) |
| 171 : profile_(profile), num_sites_(0), num_local_thumbs_(0), | 176 : profile_(profile), num_sites_(0), is_control_group_(false), |
| 172 num_server_thumbs_(0), num_empty_thumbs_(0), weak_ptr_factory_(this) { | 177 num_local_thumbs_(0), num_server_thumbs_(0), num_empty_thumbs_(0), |
| 178 weak_ptr_factory_(this) { | |
| 173 // Register the debugging page for the Suggestions Service and the thumbnails | 179 // Register the debugging page for the Suggestions Service and the thumbnails |
| 174 // debugging page. | 180 // debugging page. |
| 175 content::URLDataSource::Add(profile_, | 181 content::URLDataSource::Add(profile_, |
| 176 new suggestions::SuggestionsSource(profile_)); | 182 new suggestions::SuggestionsSource(profile_)); |
| 177 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); | 183 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); |
| 178 } | 184 } |
| 179 | 185 |
| 180 MostVisitedSites::~MostVisitedSites() { | 186 MostVisitedSites::~MostVisitedSites() { |
| 181 } | 187 } |
| 182 | 188 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 break; | 277 break; |
| 272 } | 278 } |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 276 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, | 282 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, |
| 277 jobject obj, | 283 jobject obj, |
| 278 jint index) { | 284 jint index) { |
| 279 switch (mv_source_) { | 285 switch (mv_source_) { |
| 280 case TOP_SITES: { | 286 case TOP_SITES: { |
| 281 HISTOGRAM_SPARSE_SLOWLY(kOpenedItemClientHistogramName, index); | 287 const std::string histogram = is_control_group_ ? |
|
newt (away)
2014/06/18 21:25:09
why log a different histogram depending on which g
Mathieu
2014/06/18 21:55:17
See other comment, but we basically want to calcul
| |
| 288 kOpenedItemControlHistogramName : kOpenedItemClientHistogramName; | |
| 289 LogHistogramEvent(histogram, index, num_sites_); | |
| 282 break; | 290 break; |
| 283 } | 291 } |
| 284 case SUGGESTIONS_SERVICE: { | 292 case SUGGESTIONS_SERVICE: { |
| 285 if (server_suggestions_.suggestions_size() > index) { | 293 if (server_suggestions_.suggestions_size() > index) { |
| 286 if (server_suggestions_.suggestions(index).providers_size()) { | 294 if (server_suggestions_.suggestions(index).providers_size()) { |
| 287 std::string histogram = base::StringPrintf( | 295 std::string histogram = base::StringPrintf( |
| 288 kOpenedItemServerProviderHistogramFormat, | 296 kOpenedItemServerProviderHistogramFormat, |
| 289 server_suggestions_.suggestions(index).providers(0)); | 297 server_suggestions_.suggestions(index).providers(0)); |
| 290 LogHistogramEvent(histogram, index, num_sites_); | 298 LogHistogramEvent(histogram, index, num_sites_); |
| 291 } else { | 299 } else { |
| 292 HISTOGRAM_SPARSE_SLOWLY(kOpenedItemServerHistogramName, index); | 300 UMA_HISTOGRAM_SPARSE_SLOWLY(kOpenedItemServerHistogramName, index); |
| 293 } | 301 } |
| 294 } | 302 } |
| 295 break; | 303 break; |
| 296 } | 304 } |
| 297 } | 305 } |
| 298 } | 306 } |
| 299 | 307 |
| 300 void MostVisitedSites::Observe(int type, | 308 void MostVisitedSites::Observe(int type, |
| 301 const content::NotificationSource& source, | 309 const content::NotificationSource& source, |
| 302 const content::NotificationDetails& details) { | 310 const content::NotificationDetails& details) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 ScopedJavaGlobalRef<jobject>* j_observer, | 354 ScopedJavaGlobalRef<jobject>* j_observer, |
| 347 int num_sites, | 355 int num_sites, |
| 348 const history::MostVisitedURLList& visited_list) { | 356 const history::MostVisitedURLList& visited_list) { |
| 349 std::vector<base::string16> titles; | 357 std::vector<base::string16> titles; |
| 350 std::vector<std::string> urls; | 358 std::vector<std::string> urls; |
| 351 ExtractMostVisitedTitlesAndURLs(visited_list, &titles, &urls, num_sites); | 359 ExtractMostVisitedTitlesAndURLs(visited_list, &titles, &urls, num_sites); |
| 352 | 360 |
| 353 mv_source_ = TOP_SITES; | 361 mv_source_ = TOP_SITES; |
| 354 | 362 |
| 355 int num_tiles = urls.size(); | 363 int num_tiles = urls.size(); |
| 356 HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, num_tiles); | 364 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, num_tiles); |
| 357 for (int i = 0; i < num_tiles; ++i) { | 365 for (int i = 0; i < num_tiles; ++i) { |
| 358 HISTOGRAM_SPARSE_SLOWLY(kImpressionClientHistogramName, i); | 366 const std::string histogram = is_control_group_ ? |
|
newt (away)
2014/06/18 21:25:09
pull the string assignment out of the loop
Mathieu
2014/06/19 01:45:52
Done.
| |
| 367 kImpressionControlHistogramName : kImpressionClientHistogramName; | |
| 368 LogHistogramEvent(histogram, i, num_sites_); | |
| 359 } | 369 } |
| 360 | 370 |
| 361 JNIEnv* env = AttachCurrentThread(); | 371 JNIEnv* env = AttachCurrentThread(); |
| 362 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 372 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
| 363 env, | 373 env, |
| 364 j_observer->obj(), | 374 j_observer->obj(), |
| 365 ToJavaArrayOfStrings(env, titles).obj(), | 375 ToJavaArrayOfStrings(env, titles).obj(), |
| 366 ToJavaArrayOfStrings(env, urls).obj()); | 376 ToJavaArrayOfStrings(env, urls).obj()); |
| 367 } | 377 } |
| 368 | 378 |
| 369 void MostVisitedSites::OnSuggestionsProfileAvailable( | 379 void MostVisitedSites::OnSuggestionsProfileAvailable( |
| 370 ScopedJavaGlobalRef<jobject>* j_observer, | 380 ScopedJavaGlobalRef<jobject>* j_observer, |
| 371 const SuggestionsProfile& suggestions_profile) { | 381 const SuggestionsProfile& suggestions_profile) { |
| 372 int size = suggestions_profile.suggestions_size(); | 382 int size = suggestions_profile.suggestions_size(); |
| 373 if (size == 0) { | 383 |
| 374 // No suggestions data available, initiate Top Sites query. | 384 // Determine if the user is in a control group (they would have received |
| 385 // suggestions, but are in a group where they shouldn't). | |
| 386 is_control_group_ = size && SuggestionsService::IsControlGroup(); | |
|
newt (away)
2014/06/18 21:25:09
why check size here? why not just:
is_control
Mathieu
2014/06/18 21:55:17
the main reason is that we have a population bias
| |
| 387 | |
| 388 // If no suggestions data is available or the user is in a control group, | |
| 389 // initiate Top Sites query. | |
| 390 if (is_control_group_ || !size) { | |
| 375 InitiateTopSitesQuery(); | 391 InitiateTopSitesQuery(); |
| 376 return; | 392 return; |
| 377 } | 393 } |
| 378 | 394 |
| 379 std::vector<base::string16> titles; | 395 std::vector<base::string16> titles; |
| 380 std::vector<std::string> urls; | 396 std::vector<std::string> urls; |
| 381 | 397 |
| 382 int i = 0; | 398 int i = 0; |
| 383 for (; i < size && i < num_sites_; ++i) { | 399 for (; i < size && i < num_sites_; ++i) { |
| 384 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); | 400 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); |
| 385 titles.push_back(base::UTF8ToUTF16(suggestion.title())); | 401 titles.push_back(base::UTF8ToUTF16(suggestion.title())); |
| 386 urls.push_back(suggestion.url()); | 402 urls.push_back(suggestion.url()); |
| 387 if (suggestion.providers_size()) { | 403 if (suggestion.providers_size()) { |
| 388 std::string histogram = base::StringPrintf( | 404 std::string histogram = base::StringPrintf( |
| 389 kImpressionServerHistogramFormat, suggestion.providers(0)); | 405 kImpressionServerHistogramFormat, suggestion.providers(0)); |
| 390 LogHistogramEvent(histogram, i, num_sites_); | 406 LogHistogramEvent(histogram, i, num_sites_); |
| 391 } else { | 407 } else { |
| 392 HISTOGRAM_SPARSE_SLOWLY(kImpressionServerHistogramName, i); | 408 UMA_HISTOGRAM_SPARSE_SLOWLY(kImpressionServerHistogramName, i); |
| 393 } | 409 } |
| 394 } | 410 } |
| 395 HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, i); | 411 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, i); |
| 396 | 412 |
| 397 mv_source_ = SUGGESTIONS_SERVICE; | 413 mv_source_ = SUGGESTIONS_SERVICE; |
| 398 // Keep a copy of the suggestions for eventual logging. | 414 // Keep a copy of the suggestions for eventual logging. |
| 399 server_suggestions_ = suggestions_profile; | 415 server_suggestions_ = suggestions_profile; |
| 400 | 416 |
| 401 JNIEnv* env = AttachCurrentThread(); | 417 JNIEnv* env = AttachCurrentThread(); |
| 402 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 418 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
| 403 env, | 419 env, |
| 404 j_observer->obj(), | 420 j_observer->obj(), |
| 405 ToJavaArrayOfStrings(env, titles).obj(), | 421 ToJavaArrayOfStrings(env, titles).obj(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 gfx::ConvertToJavaBitmap(bitmap).obj()); | 463 gfx::ConvertToJavaBitmap(bitmap).obj()); |
| 448 } else { | 464 } else { |
| 449 num_empty_thumbs_++; | 465 num_empty_thumbs_++; |
| 450 } | 466 } |
| 451 | 467 |
| 452 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( | 468 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( |
| 453 env, j_callback->obj(), j_bitmap_ref->obj()); | 469 env, j_callback->obj(), j_bitmap_ref->obj()); |
| 454 } | 470 } |
| 455 | 471 |
| 456 void MostVisitedSites::RecordUMAMetrics() { | 472 void MostVisitedSites::RecordUMAMetrics() { |
| 457 HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, | 473 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, |
| 458 num_local_thumbs_); | 474 num_local_thumbs_); |
| 459 num_local_thumbs_ = 0; | 475 num_local_thumbs_ = 0; |
| 460 HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); | 476 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); |
| 461 num_empty_thumbs_ = 0; | 477 num_empty_thumbs_ = 0; |
| 462 HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); | 478 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); |
| 463 num_server_thumbs_ = 0; | 479 num_server_thumbs_ = 0; |
| 464 } | 480 } |
| 465 | 481 |
| 466 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { | 482 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { |
| 467 MostVisitedSites* most_visited_sites = | 483 MostVisitedSites* most_visited_sites = |
| 468 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 484 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 469 return reinterpret_cast<intptr_t>(most_visited_sites); | 485 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 470 } | 486 } |
| OLD | NEW |