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

Side by Side Diff: chrome/browser/history/top_sites.cc

Issue 17114002: Field trial removing tiles from NTP if URL is already open - for 1993 clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
OLDNEW
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
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",
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 // The following 3 functions are part of an experiment that removes recommended
113 // Most Visited URLs if a matching URL is already open in the Browser. Note:
114 // the experiment targets only the top-level of sites i.e. if www.foo.com/bar is
115 // open in browser, and www.foo.com is a recommended URL, www.foo.com will still
116 // appear on the next NTP open. The experiment will not remove a URL if doing so
117 // would cause the number of Most Visited recommendations to drop below eight.
beaudoin 2013/06/20 21:55:44 We do not use comments describing >1 function. Put
annark1 2013/07/04 18:29:15 Done.
118
119 // static
120 bool TopSites::IsClientInTabsGroup() {
121 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) ==
122 kTabsGroupName;
123 }
124
125 // static
126 void TopSites::RemoveItemsMatchingOpenTabs(
127 const std::set<std::string>& open_urls,
128 std::vector<InstantMostVisitedItem>* items) {
129 size_t i = 0;
130 while (i < items->size()) {
131 const std::string url = (*items)[i].url.spec();
132 if (open_urls.count(url) != 0) {
133 if (items->size() <= kMinUrlSuggestions) {
134 UMA_HISTOGRAM_ENUMERATION(
135 "NewTabPage.MostVisitedTilePlacementExperiment",
136 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL,
137 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
138 ++i;
139 } else {
140 items->erase(items->begin()+i);
141 UMA_HISTOGRAM_ENUMERATION(
142 "NewTabPage.MostVisitedTilePlacementExperiment",
143 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL,
144 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
145 }
146 } else {
147 ++i;
148 }
149 }
150 }
151
152 // static
153 void TopSites::RemovePageValuesMatchingOpenTabs(
154 const std::set<std::string>& open_urls,
155 base::ListValue* pages_value) {
156 size_t i = 0;
157 while (i < pages_value->GetSize()) {
158 base::DictionaryValue* page_value;
159 std::string url;
160 if (pages_value->GetDictionary(i, &page_value) &&
161 page_value->GetString("url", &url) &&
162 open_urls.count(url) != 0) {
163 if (pages_value->GetSize() <= kMinUrlSuggestions) {
164 UMA_HISTOGRAM_ENUMERATION(
165 "NewTabPage.MostVisitedTilePlacementExperiment",
166 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL,
167 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
168 ++i;
169 } else {
170 pages_value->Remove(*page_value, &i);
171 UMA_HISTOGRAM_ENUMERATION(
172 "NewTabPage.MostVisitedTilePlacementExperiment",
173 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL,
174 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
175 }
176 } else {
177 ++i;
178 }
179 }
180 }
beaudoin 2013/06/20 21:55:44 These two functions are really quite similar. We c
annark1 2013/07/04 18:29:15 brettw, do you have a preference on how this shoul
181
86 } // namespace history 182 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698