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 const char kOneEightGroupPrefix[] = "OneEight"; | |
23 const char kOneFourGroupPrefix[] = "OneFour"; | |
24 const char kFlippedSuffix[] = "Flipped"; | |
25 const char kDontShowOpenURLsGroupName[] = "DontShowOpenTabs"; | |
26 | |
27 // Minimum number of Most Visited suggestions required in order for the Most | |
28 // Visited Field Trial to remove a URL already open in the browser. | |
29 const size_t kMinUrlSuggestions = 8; | |
30 | |
31 } // namespace | |
32 | |
33 // static | |
34 void MostVisitedTilesExperiment::MaybeShuffle(MostVisitedURLList* data) { | |
35 const std::string group_name = | |
36 base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName); | |
37 | |
38 // Depending on the study group of the client, we might flip the 1st and 4th | |
39 // tiles, or the 1st and 8th, or do nothing. | |
40 if (EndsWith(group_name, kFlippedSuffix, true)) { | |
41 size_t index_to_flip = 0; | |
42 if (StartsWithASCII(group_name, kOneEightGroupPrefix, true)) { | |
43 if (data->size() < 8) { | |
44 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_8); | |
sky
2013/07/17 21:30:51
can't you early return here and 50?
annark1
2013/07/22 20:35:34
Done.
| |
45 } else { | |
46 index_to_flip = 7; | |
47 } | |
48 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true)) { | |
49 if (data->size() < 4) { | |
50 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4); | |
51 } else { | |
52 index_to_flip = 3; | |
53 } | |
54 } | |
55 | |
56 if (data->empty() || (*data)[index_to_flip].url.is_empty()) { | |
sky
2013/07/17 21:30:51
Can data ever be empty and can a url ever be empty
annark1
2013/07/22 20:35:34
Not so far as I can see. I've removed this code no
| |
57 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_NO_URL_TO_FLIP); | |
58 return; | |
59 } | |
60 std::swap((*data)[0], (*data)[index_to_flip]); | |
61 } | |
62 } | |
63 | |
64 // static | |
65 bool MostVisitedTilesExperiment::DontShowOpenURLsEnabled() { | |
66 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) == | |
67 kDontShowOpenURLsGroupName; | |
68 } | |
69 | |
70 // static | |
71 void MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( | |
72 const std::set<std::string>& open_urls, | |
73 std::vector<InstantMostVisitedItem>* items) { | |
74 size_t i = 0; | |
75 while (i < items->size()) { | |
sky
2013/07/17 21:30:51
How about a for loop here and below? It need not i
annark1
2013/07/22 20:35:34
Done.
| |
76 const std::string& url = (*items)[i].url.spec(); | |
77 if (open_urls.count(url) != 0) { | |
78 if (items->size() <= kMinUrlSuggestions) { | |
79 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL); | |
80 ++i; | |
81 } else { | |
82 items->erase(items->begin() + i); | |
83 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL); | |
84 } | |
85 } else { | |
86 ++i; | |
87 } | |
88 } | |
89 } | |
90 | |
91 // static | |
92 void MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs( | |
93 const std::set<std::string>& open_urls, | |
94 base::ListValue* pages_value) { | |
95 size_t i = 0; | |
96 while (i < pages_value->GetSize()) { | |
97 base::DictionaryValue* page_value; | |
98 std::string url; | |
99 if (pages_value->GetDictionary(i, &page_value) && | |
100 page_value->GetString("url", &url) && | |
101 open_urls.count(url) != 0) { | |
102 if (pages_value->GetSize() <= kMinUrlSuggestions) { | |
103 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL); | |
104 ++i; | |
105 } else { | |
106 pages_value->Remove(*page_value, &i); | |
107 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL); | |
108 } | |
109 } else { | |
110 ++i; | |
111 } | |
112 } | |
113 } | |
114 | |
115 // static | |
116 void MostVisitedTilesExperiment::LogInHistogram( | |
117 NtpTileExperimentActions action) { | |
118 UMA_HISTOGRAM_ENUMERATION( | |
119 "NewTabPage.MostVisitedTilePlacementExperiment", | |
120 action, | |
121 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
122 } | |
123 | |
124 } // namespace history | |
OLD | NEW |