OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/history/top_sites.h" | 5 #include "chrome/browser/history/top_sites.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/metrics/histogram.h" | |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/values.h" | |
9 #include "chrome/browser/history/top_sites_impl.h" | 11 #include "chrome/browser/history/top_sites_impl.h" |
10 #include "chrome/browser/history/top_sites_likely_impl.h" | 12 #include "chrome/browser/history/top_sites_likely_impl.h" |
13 #include "chrome/common/instant_types.h" | |
14 #include "content/public/browser/web_contents.h" | |
11 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
12 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
13 #include "grit/locale_settings.h" | 17 #include "grit/locale_settings.h" |
14 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
15 | 19 |
16 namespace history { | 20 namespace history { |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 // Constants for the most visited tile placement field trial. | 24 // Constants for the most visited tile placement field trial. |
21 // ex: | 25 // ex: |
22 // "OneEightGroup_Flipped" --> Will cause tile 1 and 8 to be flipped. | 26 // "OneEightGroup_Flipped" --> Will cause tile 1 and 8 to be flipped. |
23 // "OneEightGroup_NoChange" --> Will not flip anything. | 27 // "OneEightGroup_NoChange" --> Will not flip anything. |
24 // | 28 // |
25 // See field trial config (MostVisitedTilePlacement.json) for details. | 29 // See field trial config (MostVisitedTilePlacement.json) for details. |
26 const char kMostVisitedFieldTrialName[] = "MostVisitedTilePlacement"; | 30 const char kMostVisitedFieldTrialName[] = "MostVisitedTilePlacement"; |
27 const char kOneEightGroupPrefix[] = "OneEight"; | 31 const char kOneEightGroupPrefix[] = "OneEight"; |
28 const char kOneFourGroupPrefix[] = "OneFour"; | 32 const char kOneFourGroupPrefix[] = "OneFour"; |
29 const char kFlippedSuffix[] = "Flipped"; | 33 const char kFlippedSuffix[] = "Flipped"; |
34 const char kTabsGroupName[] = "DontShowOpenTabs"; | |
35 | |
36 // Minimum number of Most Visited suggestions required in order for the Most | |
37 // Visited Field Trial to remove a URL already open in the browser. | |
38 const size_t kMinUrlSuggestions = 8; | |
30 | 39 |
31 } // namespace | 40 } // namespace |
32 | 41 |
33 const TopSites::PrepopulatedPage kPrepopulatedPages[] = { | 42 const TopSites::PrepopulatedPage kPrepopulatedPages[] = { |
34 #if defined(OS_ANDROID) | 43 #if defined(OS_ANDROID) |
35 { IDS_MOBILE_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE, | 44 { IDS_MOBILE_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE, |
36 IDR_PRODUCT_LOGO_16, IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL, | 45 IDR_PRODUCT_LOGO_16, IDR_NEWTAB_CHROME_WELCOME_PAGE_THUMBNAIL, |
37 SkColorSetRGB(0, 147, 60) } | 46 SkColorSetRGB(0, 147, 60) } |
38 #else | 47 #else |
39 { IDS_CHROME_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE, | 48 { IDS_CHROME_WELCOME_URL, IDS_NEW_TAB_CHROME_WELCOME_PAGE_TITLE, |
(...skipping 22 matching lines...) Expand all Loading... | |
62 | 71 |
63 // static | 72 // static |
64 void TopSites::MaybeShuffle(MostVisitedURLList* data) { | 73 void TopSites::MaybeShuffle(MostVisitedURLList* data) { |
65 const std::string group_name = | 74 const std::string group_name = |
66 base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName); | 75 base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName); |
67 | 76 |
68 // Depending on the study group of the client, we might flip the 1st and 4th | 77 // Depending on the study group of the client, we might flip the 1st and 4th |
69 // tiles, or the 1st and 8th, or do nothing. | 78 // tiles, or the 1st and 8th, or do nothing. |
70 if (EndsWith(group_name, kFlippedSuffix, true)) { | 79 if (EndsWith(group_name, kFlippedSuffix, true)) { |
71 size_t index_to_flip = 0; | 80 size_t index_to_flip = 0; |
72 if (StartsWithASCII(group_name, kOneEightGroupPrefix, true) && | 81 if (StartsWithASCII(group_name, kOneEightGroupPrefix, true)) { |
73 data->size() >= 8) { | 82 if (data->size() < 8) { |
74 index_to_flip = 7; | 83 UMA_HISTOGRAM_ENUMERATION( |
75 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true) && | 84 "NewTabPage.MostVisitedTilePlacementExperiment", |
Alexei Svitkine (slow)
2013/07/04 20:28:30
I suggest making a helper function to log this his
annark1
2013/07/16 18:07:09
Done.
| |
76 data->size() >= 4) { | 85 NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_8, |
77 index_to_flip = 3; | 86 NUM_NTP_TILE_EXPERIMENT_ACTIONS); |
87 } else { | |
88 index_to_flip = 7; | |
89 } | |
90 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true)) { | |
91 if (data->size() < 4) { | |
92 UMA_HISTOGRAM_ENUMERATION( | |
93 "NewTabPage.MostVisitedTilePlacementExperiment", | |
94 NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4, | |
95 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
96 } else { | |
97 index_to_flip = 3; | |
98 } | |
78 } | 99 } |
79 | 100 |
80 if (data->empty() || (*data)[index_to_flip].url.is_empty()) | 101 if (data->empty() || (*data)[index_to_flip].url.is_empty()) { |
102 UMA_HISTOGRAM_ENUMERATION( | |
103 "NewTabPage.MostVisitedTilePlacementExperiment", | |
104 NTP_TILE_EXPERIMENT_ACTION_NO_URL_TO_FLIP, | |
105 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
81 return; | 106 return; |
107 } | |
82 std::swap((*data)[0], (*data)[index_to_flip]); | 108 std::swap((*data)[0], (*data)[index_to_flip]); |
83 } | 109 } |
84 } | 110 } |
85 | 111 |
112 // static | |
113 bool TopSites::IsClientInTabsGroup() { | |
114 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) == | |
115 kTabsGroupName; | |
116 } | |
117 | |
118 // static | |
119 void TopSites::RemoveItemsMatchingOpenTabs( | |
120 const std::set<std::string>& open_urls, | |
121 std::vector<InstantMostVisitedItem>* items) { | |
122 size_t i = 0; | |
123 while (i < items->size()) { | |
124 const std::string url = (*items)[i].url.spec(); | |
125 if (open_urls.count(url) != 0) { | |
126 if (items->size() <= kMinUrlSuggestions) { | |
127 UMA_HISTOGRAM_ENUMERATION( | |
128 "NewTabPage.MostVisitedTilePlacementExperiment", | |
129 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL, | |
130 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
131 ++i; | |
132 } else { | |
133 items->erase(items->begin()+i); | |
134 UMA_HISTOGRAM_ENUMERATION( | |
135 "NewTabPage.MostVisitedTilePlacementExperiment", | |
136 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL, | |
137 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
138 } | |
139 } else { | |
140 ++i; | |
141 } | |
142 } | |
143 } | |
144 | |
145 // static | |
146 void TopSites::RemovePageValuesMatchingOpenTabs( | |
147 const std::set<std::string>& open_urls, | |
148 base::ListValue* pages_value) { | |
149 size_t i = 0; | |
150 while (i < pages_value->GetSize()) { | |
151 base::DictionaryValue* page_value; | |
152 std::string url; | |
153 if (pages_value->GetDictionary(i, &page_value) && | |
154 page_value->GetString("url", &url) && | |
155 open_urls.count(url) != 0) { | |
156 if (pages_value->GetSize() <= kMinUrlSuggestions) { | |
157 UMA_HISTOGRAM_ENUMERATION( | |
158 "NewTabPage.MostVisitedTilePlacementExperiment", | |
159 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL, | |
160 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
161 ++i; | |
162 } else { | |
163 pages_value->Remove(*page_value, &i); | |
164 UMA_HISTOGRAM_ENUMERATION( | |
165 "NewTabPage.MostVisitedTilePlacementExperiment", | |
166 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL, | |
167 NUM_NTP_TILE_EXPERIMENT_ACTIONS); | |
168 } | |
169 } else { | |
170 ++i; | |
171 } | |
172 } | |
173 } | |
174 | |
86 } // namespace history | 175 } // namespace history |
OLD | NEW |