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

Side by Side Diff: chrome/browser/android/most_visited_sites.cc

Issue 341943002: [Android NTP] Logging histograms for users that are part of a control group. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial 2 Created 6 years, 6 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 | Annotate | Revision Log
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 "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
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
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
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 UMA_HISTOGRAM_SPARSE_SLOWLY(is_control_group_ ?
288 kOpenedItemControlHistogramName : kOpenedItemClientHistogramName,
289 index);
beaudoin1 2014/06/18 17:46:54 I know many histogram macros do not support a dyna
Mathieu 2014/06/18 17:55:09 Ah good catch, I even have the function in this fi
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);
beaudoin1 2014/06/18 17:46:54 Out of curiosity: What's the difference between th
Mathieu 2014/06/18 17:55:09 The COUNTS macros don't work very well when the ma
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
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 UMA_HISTOGRAM_SPARSE_SLOWLY(is_control_group_ ?
367 kImpressionControlHistogramName : kImpressionClientHistogramName, i);
beaudoin1 2014/06/18 17:46:54 Same remark here.
Mathieu 2014/06/18 17:55:09 Done.
359 } 368 }
360 369
361 JNIEnv* env = AttachCurrentThread(); 370 JNIEnv* env = AttachCurrentThread();
362 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( 371 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
363 env, 372 env,
364 j_observer->obj(), 373 j_observer->obj(),
365 ToJavaArrayOfStrings(env, titles).obj(), 374 ToJavaArrayOfStrings(env, titles).obj(),
366 ToJavaArrayOfStrings(env, urls).obj()); 375 ToJavaArrayOfStrings(env, urls).obj());
367 } 376 }
368 377
369 void MostVisitedSites::OnSuggestionsProfileAvailable( 378 void MostVisitedSites::OnSuggestionsProfileAvailable(
370 ScopedJavaGlobalRef<jobject>* j_observer, 379 ScopedJavaGlobalRef<jobject>* j_observer,
371 const SuggestionsProfile& suggestions_profile) { 380 const SuggestionsProfile& suggestions_profile) {
372 int size = suggestions_profile.suggestions_size(); 381 int size = suggestions_profile.suggestions_size();
373 if (size == 0) { 382
374 // No suggestions data available, initiate Top Sites query. 383 // Determine if the user is in a control group (they would have received
384 // suggestions, but are in a group where they shouldn't).
385 is_control_group_ = size && SuggestionsService::IsControlGroup();
386
387 // If no suggestions data is available or the user is in a control group,
388 // initiate Top Sites query.
389 if (is_control_group_ || !size) {
375 InitiateTopSitesQuery(); 390 InitiateTopSitesQuery();
376 return; 391 return;
377 } 392 }
378 393
379 std::vector<base::string16> titles; 394 std::vector<base::string16> titles;
380 std::vector<std::string> urls; 395 std::vector<std::string> urls;
381 396
382 int i = 0; 397 int i = 0;
383 for (; i < size && i < num_sites_; ++i) { 398 for (; i < size && i < num_sites_; ++i) {
384 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); 399 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i);
385 titles.push_back(base::UTF8ToUTF16(suggestion.title())); 400 titles.push_back(base::UTF8ToUTF16(suggestion.title()));
386 urls.push_back(suggestion.url()); 401 urls.push_back(suggestion.url());
387 if (suggestion.providers_size()) { 402 if (suggestion.providers_size()) {
388 std::string histogram = base::StringPrintf( 403 std::string histogram = base::StringPrintf(
389 kImpressionServerHistogramFormat, suggestion.providers(0)); 404 kImpressionServerHistogramFormat, suggestion.providers(0));
390 LogHistogramEvent(histogram, i, num_sites_); 405 LogHistogramEvent(histogram, i, num_sites_);
391 } else { 406 } else {
392 HISTOGRAM_SPARSE_SLOWLY(kImpressionServerHistogramName, i); 407 UMA_HISTOGRAM_SPARSE_SLOWLY(kImpressionServerHistogramName, i);
393 } 408 }
394 } 409 }
395 HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, i); 410 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, i);
396 411
397 mv_source_ = SUGGESTIONS_SERVICE; 412 mv_source_ = SUGGESTIONS_SERVICE;
398 // Keep a copy of the suggestions for eventual logging. 413 // Keep a copy of the suggestions for eventual logging.
399 server_suggestions_ = suggestions_profile; 414 server_suggestions_ = suggestions_profile;
400 415
401 JNIEnv* env = AttachCurrentThread(); 416 JNIEnv* env = AttachCurrentThread();
402 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( 417 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable(
403 env, 418 env,
404 j_observer->obj(), 419 j_observer->obj(),
405 ToJavaArrayOfStrings(env, titles).obj(), 420 ToJavaArrayOfStrings(env, titles).obj(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 gfx::ConvertToJavaBitmap(bitmap).obj()); 462 gfx::ConvertToJavaBitmap(bitmap).obj());
448 } else { 463 } else {
449 num_empty_thumbs_++; 464 num_empty_thumbs_++;
450 } 465 }
451 466
452 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable( 467 Java_ThumbnailCallback_onMostVisitedURLsThumbnailAvailable(
453 env, j_callback->obj(), j_bitmap_ref->obj()); 468 env, j_callback->obj(), j_bitmap_ref->obj());
454 } 469 }
455 470
456 void MostVisitedSites::RecordUMAMetrics() { 471 void MostVisitedSites::RecordUMAMetrics() {
457 HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName, 472 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumLocalThumbnailTilesHistogramName,
458 num_local_thumbs_); 473 num_local_thumbs_);
459 num_local_thumbs_ = 0; 474 num_local_thumbs_ = 0;
460 HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_); 475 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumEmptyTilesHistogramName, num_empty_thumbs_);
461 num_empty_thumbs_ = 0; 476 num_empty_thumbs_ = 0;
462 HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_); 477 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumServerTilesHistogramName, num_server_thumbs_);
463 num_server_thumbs_ = 0; 478 num_server_thumbs_ = 0;
464 } 479 }
465 480
466 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { 481 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) {
467 MostVisitedSites* most_visited_sites = 482 MostVisitedSites* most_visited_sites =
468 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); 483 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile));
469 return reinterpret_cast<intptr_t>(most_visited_sites); 484 return reinterpret_cast<intptr_t>(most_visited_sites);
470 } 485 }
OLDNEW
« no previous file with comments | « chrome/browser/android/most_visited_sites.h ('k') | chrome/browser/search/suggestions/suggestions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698