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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Client suggestion opened. |
| 63 const char kOpenedItemClientHistogramName[] = "NewTabPage.MostVisited.client"; | 63 const char kOpenedItemClientHistogramName[] = "NewTabPage.MostVisited.client"; |
| 64 // Control group suggestion opened. | |
| 65 const char kOpenedItemControlHistogramName[] = "NewTabPage.MostVisited.client0"; | |
| 66 // Server suggestion opened, no provider. | 64 // Server suggestion opened, no provider. |
| 67 const char kOpenedItemServerHistogramName[] = "NewTabPage.MostVisited.server"; | 65 const char kOpenedItemServerHistogramName[] = "NewTabPage.MostVisited.server"; |
| 68 // Server suggestion opened with provider. | 66 // Server suggestion opened with provider. |
| 69 const char kOpenedItemServerProviderHistogramFormat[] = | 67 const char kOpenedItemServerProviderHistogramFormat[] = |
| 70 "NewTabPage.MostVisited.server%d"; | 68 "NewTabPage.MostVisited.server%d"; |
| 71 // Client impression. | 69 // Client impression. |
| 72 const char kImpressionClientHistogramName[] = | 70 const char kImpressionClientHistogramName[] = |
| 73 "NewTabPage.SuggestionsImpression.client"; | 71 "NewTabPage.SuggestionsImpression.client"; |
| 74 // Control group impression. | |
| 75 const char kImpressionControlHistogramName[] = | |
| 76 "NewTabPage.SuggestionsImpression.client0"; | |
| 77 // Server suggestion impression, no provider. | 72 // Server suggestion impression, no provider. |
| 78 const char kImpressionServerHistogramName[] = | 73 const char kImpressionServerHistogramName[] = |
| 79 "NewTabPage.SuggestionsImpression.server"; | 74 "NewTabPage.SuggestionsImpression.server"; |
| 80 // Server suggestion impression with provider. | 75 // Server suggestion impression with provider. |
| 81 const char kImpressionServerHistogramFormat[] = | 76 const char kImpressionServerHistogramFormat[] = |
| 82 "NewTabPage.SuggestionsImpression.server%d"; | 77 "NewTabPage.SuggestionsImpression.server%d"; |
| 83 | 78 |
| 84 void ExtractMostVisitedTitlesAndURLs( | 79 void ExtractMostVisitedTitlesAndURLs( |
| 85 const history::MostVisitedURLList& visited_list, | 80 const history::MostVisitedURLList& visited_list, |
| 86 std::vector<base::string16>* titles, | 81 std::vector<base::string16>* titles, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 return SyncState::SYNC_OR_HISTORY_SYNC_DISABLED; | 177 return SyncState::SYNC_OR_HISTORY_SYNC_DISABLED; |
| 183 return suggestions::GetSyncState( | 178 return suggestions::GetSyncState( |
| 184 sync->IsSyncEnabledAndLoggedIn(), | 179 sync->IsSyncEnabledAndLoggedIn(), |
| 185 sync->SyncActive() && sync->ConfigurationDone(), | 180 sync->SyncActive() && sync->ConfigurationDone(), |
| 186 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES)); | 181 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES)); |
| 187 } | 182 } |
| 188 | 183 |
| 189 } // namespace | 184 } // namespace |
| 190 | 185 |
| 191 MostVisitedSites::MostVisitedSites(Profile* profile) | 186 MostVisitedSites::MostVisitedSites(Profile* profile) |
| 192 : profile_(profile), num_sites_(0), is_control_group_(false), | 187 : profile_(profile), num_sites_(0), initial_load_done_(false), |
| 193 initial_load_done_(false), num_local_thumbs_(0), num_server_thumbs_(0), | 188 num_local_thumbs_(0), num_server_thumbs_(0), num_empty_thumbs_(0), |
| 194 num_empty_thumbs_(0), scoped_observer_(this), weak_ptr_factory_(this) { | 189 scoped_observer_(this), weak_ptr_factory_(this) { |
| 195 // Register the debugging page for the Suggestions Service and the thumbnails | 190 // Register the debugging page for the Suggestions Service and the thumbnails |
| 196 // debugging page. | 191 // debugging page. |
| 197 content::URLDataSource::Add(profile_, | 192 content::URLDataSource::Add(profile_, |
| 198 new suggestions::SuggestionsSource(profile_)); | 193 new suggestions::SuggestionsSource(profile_)); |
| 199 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); | 194 content::URLDataSource::Add(profile_, new ThumbnailListSource(profile_)); |
| 200 | 195 |
| 201 // Register this class as an observer to the sync service. It is important to | 196 // Register this class as an observer to the sync service. It is important to |
| 202 // be notified of changes in the sync state such as initialization, sync | 197 // be notified of changes in the sync state such as initialization, sync |
| 203 // being enabled or disabled, etc. | 198 // being enabled or disabled, etc. |
| 204 ProfileSyncService* profile_sync_service = | 199 ProfileSyncService* profile_sync_service = |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 break; | 304 break; |
| 310 } | 305 } |
| 311 } | 306 } |
| 312 } | 307 } |
| 313 | 308 |
| 314 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, | 309 void MostVisitedSites::RecordOpenedMostVisitedItem(JNIEnv* env, |
| 315 jobject obj, | 310 jobject obj, |
| 316 jint index) { | 311 jint index) { |
| 317 switch (mv_source_) { | 312 switch (mv_source_) { |
| 318 case TOP_SITES: { | 313 case TOP_SITES: { |
| 319 const std::string histogram = is_control_group_ ? | 314 UMA_HISTOGRAM_SPARSE_SLOWLY(kOpenedItemClientHistogramName, index); |
| 320 kOpenedItemControlHistogramName : kOpenedItemClientHistogramName; | |
| 321 LogHistogramEvent(histogram, index, num_sites_); | |
| 322 break; | 315 break; |
| 323 } | 316 } |
| 324 case SUGGESTIONS_SERVICE: { | 317 case SUGGESTIONS_SERVICE: { |
| 325 if (server_suggestions_.suggestions_size() > index) { | 318 if (server_suggestions_.suggestions_size() > index) { |
| 326 if (server_suggestions_.suggestions(index).providers_size()) { | 319 if (server_suggestions_.suggestions(index).providers_size()) { |
| 327 std::string histogram = base::StringPrintf( | 320 std::string histogram = base::StringPrintf( |
| 328 kOpenedItemServerProviderHistogramFormat, | 321 kOpenedItemServerProviderHistogramFormat, |
| 329 server_suggestions_.suggestions(index).providers(0)); | 322 server_suggestions_.suggestions(index).providers(0)); |
| 330 LogHistogramEvent(histogram, index, num_sites_); | 323 LogHistogramEvent(histogram, index, num_sites_); |
| 331 } else { | 324 } else { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 std::vector<base::string16> titles; | 379 std::vector<base::string16> titles; |
| 387 std::vector<std::string> urls; | 380 std::vector<std::string> urls; |
| 388 ExtractMostVisitedTitlesAndURLs(visited_list, &titles, &urls, num_sites); | 381 ExtractMostVisitedTitlesAndURLs(visited_list, &titles, &urls, num_sites); |
| 389 | 382 |
| 390 mv_source_ = TOP_SITES; | 383 mv_source_ = TOP_SITES; |
| 391 | 384 |
| 392 // Only log impression metrics on the initial load of the NTP. | 385 // Only log impression metrics on the initial load of the NTP. |
| 393 if (!initial_load_done_) { | 386 if (!initial_load_done_) { |
| 394 int num_tiles = urls.size(); | 387 int num_tiles = urls.size(); |
| 395 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, num_tiles); | 388 UMA_HISTOGRAM_SPARSE_SLOWLY(kNumTilesHistogramName, num_tiles); |
| 396 const std::string histogram = is_control_group_ ? | |
| 397 kImpressionControlHistogramName : kImpressionClientHistogramName; | |
| 398 for (int i = 0; i < num_tiles; ++i) { | 389 for (int i = 0; i < num_tiles; ++i) { |
| 399 LogHistogramEvent(histogram, i, num_sites_); | 390 UMA_HISTOGRAM_SPARSE_SLOWLY(kImpressionClientHistogramName, i); |
| 400 } | 391 } |
| 401 } | 392 } |
| 402 initial_load_done_ = true; | 393 initial_load_done_ = true; |
| 403 | 394 |
| 404 JNIEnv* env = AttachCurrentThread(); | 395 JNIEnv* env = AttachCurrentThread(); |
| 405 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( | 396 Java_MostVisitedURLsObserver_onMostVisitedURLsAvailable( |
| 406 env, | 397 env, |
| 407 j_observer->obj(), | 398 j_observer->obj(), |
| 408 ToJavaArrayOfStrings(env, titles).obj(), | 399 ToJavaArrayOfStrings(env, titles).obj(), |
| 409 ToJavaArrayOfStrings(env, urls).obj()); | 400 ToJavaArrayOfStrings(env, urls).obj()); |
| 410 } | 401 } |
| 411 | 402 |
| 412 void MostVisitedSites::OnSuggestionsProfileAvailable( | 403 void MostVisitedSites::OnSuggestionsProfileAvailable( |
| 413 ScopedJavaGlobalRef<jobject>* j_observer, | 404 ScopedJavaGlobalRef<jobject>* j_observer, |
| 414 const SuggestionsProfile& suggestions_profile) { | 405 const SuggestionsProfile& suggestions_profile) { |
| 415 int size = suggestions_profile.suggestions_size(); | |
| 416 | |
| 417 // Determine if the user is in a control group (they would have received | |
| 418 // suggestions, but are in a group where they shouldn't). | |
| 419 is_control_group_ = size && SuggestionsService::IsControlGroup(); | |
| 420 | |
| 421 // If no suggestions data is available or the user is in a control group, | |
| 422 // initiate Top Sites query. | |
| 423 if (is_control_group_ || !size) { | |
| 424 InitiateTopSitesQuery(); | |
| 425 return; | |
| 426 } | |
| 427 | |
| 428 std::vector<base::string16> titles; | 406 std::vector<base::string16> titles; |
|
huangs
2015/03/24 15:17:26
So if size == 0 you no longer need to call Initiat
Mathieu
2015/03/24 15:26:16
Done. Gosh, I feel so silly :\
| |
| 429 std::vector<std::string> urls; | 407 std::vector<std::string> urls; |
| 430 | |
| 431 int i = 0; | 408 int i = 0; |
| 432 for (; i < size && i < num_sites_; ++i) { | 409 for (; i < suggestions_profile.suggestions_size() && i < num_sites_; ++i) { |
| 433 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); | 410 const ChromeSuggestion& suggestion = suggestions_profile.suggestions(i); |
| 434 titles.push_back(base::UTF8ToUTF16(suggestion.title())); | 411 titles.push_back(base::UTF8ToUTF16(suggestion.title())); |
| 435 urls.push_back(suggestion.url()); | 412 urls.push_back(suggestion.url()); |
| 436 // Only log impression metrics on the initial NTP load. | 413 // Only log impression metrics on the initial NTP load. |
| 437 if (!initial_load_done_) { | 414 if (!initial_load_done_) { |
| 438 if (suggestion.providers_size()) { | 415 if (suggestion.providers_size()) { |
| 439 std::string histogram = base::StringPrintf( | 416 std::string histogram = base::StringPrintf( |
| 440 kImpressionServerHistogramFormat, suggestion.providers(0)); | 417 kImpressionServerHistogramFormat, suggestion.providers(0)); |
| 441 LogHistogramEvent(histogram, i, num_sites_); | 418 LogHistogramEvent(histogram, i, num_sites_); |
| 442 } else { | 419 } else { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 // The displayed suggestions are invalidated. | 503 // The displayed suggestions are invalidated. |
| 527 QueryMostVisitedURLs(); | 504 QueryMostVisitedURLs(); |
| 528 } | 505 } |
| 529 } | 506 } |
| 530 | 507 |
| 531 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { | 508 static jlong Init(JNIEnv* env, jobject obj, jobject jprofile) { |
| 532 MostVisitedSites* most_visited_sites = | 509 MostVisitedSites* most_visited_sites = |
| 533 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); | 510 new MostVisitedSites(ProfileAndroid::FromProfileAndroid(jprofile)); |
| 534 return reinterpret_cast<intptr_t>(most_visited_sites); | 511 return reinterpret_cast<intptr_t>(most_visited_sites); |
| 535 } | 512 } |
| OLD | NEW |