Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/history/most_visited_tiles_experiment.h" | |
| 6 | |
| 7 #include "base/metrics/field_trial.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/strings/string_util.h" | |
| 10 | |
| 11 namespace history { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Constants for the most visited tile placement field trial. | |
| 16 // ex: | |
| 17 // "OneEightGroup_Flipped" --> Will cause tile 1 and 8 to be flipped. | |
| 18 // "OneEightGroup_NoChange" --> Will not flip anything. | |
| 19 // | |
| 20 // See field trial config (MostVisitedTilePlacement.json) for details. | |
| 21 const char kMostVisitedFieldTrialName[] = "MostVisitedTilePlacement"; | |
| 22 // Name of histogram tracking types of actions carried out by the field trial. | |
| 23 const char kMostVisitedExperimentHistogramName[] = | |
| 24 "NewTabPage.MostVisitedTilePlacementExperiment"; | |
| 25 const char kOneEightGroupPrefix[] = "OneEight"; | |
| 26 const char kOneFourGroupPrefix[] = "OneFour"; | |
| 27 const char kFlippedSuffix[] = "Flipped"; | |
| 28 const char kDontShowOpenURLsGroupName[] = "DontShowOpenTabs"; | |
| 29 // Minimum number of Most Visited suggestions required in order for the Most | |
| 30 // Visited Field Trial to remove a URL already open in the browser. | |
| 31 const size_t kMinUrlSuggestions = 8; | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 // static | |
| 36 void MostVisitedTilesExperiment::MaybeShuffle(MostVisitedURLList* data) { | |
| 37 const std::string group_name = | |
| 38 base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName); | |
| 39 | |
| 40 // Depending on the study group of the client, we might flip the 1st and 4th | |
| 41 // tiles, or the 1st and 8th, or do nothing. | |
| 42 if (!EndsWith(group_name, kFlippedSuffix, true)) | |
| 43 return; | |
| 44 | |
| 45 size_t index_to_flip = 0; | |
| 46 if (StartsWithASCII(group_name, kOneEightGroupPrefix, true)) { | |
| 47 if (data->size() < 8) { | |
| 48 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_8); | |
| 49 return; | |
| 50 } | |
| 51 index_to_flip = 7; | |
| 52 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true)) { | |
| 53 if (data->size() < 4) { | |
| 54 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4); | |
| 55 return; | |
| 56 } | |
| 57 index_to_flip = 3; | |
| 58 } | |
| 59 std::swap((*data)[0], (*data)[index_to_flip]); | |
| 60 } | |
| 61 | |
| 62 // static | |
| 63 bool MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled() { | |
| 64 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) == | |
| 65 kDontShowOpenURLsGroupName; | |
| 66 } | |
| 67 | |
| 68 // static | |
| 69 void MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( | |
| 70 const std::set<std::string>& open_urls, | |
| 71 std::vector<InstantMostVisitedItem>* items) { | |
| 72 for (size_t i = 0; i < items->size(); ) { | |
| 73 const std::string& url = (*items)[i].url.spec(); | |
| 74 if (open_urls.count(url) != 0) { | |
|
Alexei Svitkine (slow)
2013/07/24 19:17:12
I think you can split out this block into a helper
annark1
2013/07/24 20:43:31
Nice! Thanks for this improvement.
On 2013/07/24
| |
| 75 if (items->size() <= kMinUrlSuggestions) { | |
| 76 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL); | |
| 77 ++i; | |
| 78 } else { | |
| 79 items->erase(items->begin() + i); | |
| 80 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL); | |
| 81 } | |
| 82 } else { | |
| 83 ++i; | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 // static | |
| 89 void MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( | |
| 90 const std::set<std::string>& open_urls, | |
| 91 base::ListValue* pages_value) { | |
| 92 for (size_t i = 0; i < pages_value->GetSize(); ) { | |
| 93 base::DictionaryValue* page_value; | |
| 94 std::string url; | |
| 95 if (pages_value->GetDictionary(i, &page_value) && | |
| 96 page_value->GetString("url", &url) && | |
| 97 open_urls.count(url) != 0) { | |
| 98 if (pages_value->GetSize() <= kMinUrlSuggestions) { | |
| 99 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL); | |
| 100 ++i; | |
| 101 } else { | |
| 102 pages_value->Remove(*page_value, &i); | |
| 103 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL); | |
| 104 } | |
| 105 } else { | |
| 106 ++i; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 // static | |
| 112 void MostVisitedTilesExperiment::LogInHistogram( | |
| 113 NtpTileExperimentActions action) { | |
| 114 UMA_HISTOGRAM_ENUMERATION(kMostVisitedExperimentHistogramName, | |
| 115 action, | |
| 116 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
| 117 } | |
| 118 | |
| 119 } // namespace history | |
| OLD | NEW |