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

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: Addressed asvitkines comments Created 7 years, 5 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 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_8);
75 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true) && 84 } else {
76 data->size() >= 4) { 85 index_to_flip = 7;
77 index_to_flip = 3; 86 }
87 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true)) {
88 if (data->size() < 4) {
89 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4);
90 } else {
91 index_to_flip = 3;
92 }
78 } 93 }
79 94
80 if (data->empty() || (*data)[index_to_flip].url.is_empty()) 95 if (data->empty() || (*data)[index_to_flip].url.is_empty()) {
96 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_NO_URL_TO_FLIP);
81 return; 97 return;
98 }
82 std::swap((*data)[0], (*data)[index_to_flip]); 99 std::swap((*data)[0], (*data)[index_to_flip]);
83 } 100 }
84 } 101 }
85 102
103 // static
104 bool TopSites::IsClientInTabsGroup() {
105 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) ==
106 kTabsGroupName;
107 }
108
109 // static
110 void TopSites::RemoveItemsMatchingOpenTabs(
111 const std::set<std::string>& open_urls,
112 std::vector<InstantMostVisitedItem>* items) {
113 size_t i = 0;
114 while (i < items->size()) {
115 const std::string url = (*items)[i].url.spec();
sky 2013/07/16 21:15:07 const std::string&
annark1 2013/07/17 17:45:52 Done.
116 if (open_urls.count(url) != 0) {
117 if (items->size() <= kMinUrlSuggestions) {
118 UMA_HISTOGRAM_ENUMERATION(
119 "NewTabPage.MostVisitedTilePlacementExperiment",
120 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL,
121 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
122 ++i;
123 } else {
124 items->erase(items->begin()+i);
sky 2013/07/16 21:15:07 use spaces
annark1 2013/07/17 17:45:52 Done.
125 UMA_HISTOGRAM_ENUMERATION(
126 "NewTabPage.MostVisitedTilePlacementExperiment",
127 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL,
128 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
129 }
130 } else {
131 ++i;
132 }
133 }
134 }
135
136 // static
137 void TopSites::RemovePageValuesMatchingOpenTabs(
sky 2013/07/16 21:15:07 Can't we implement one of these in terms of the ot
annark1 2013/07/17 17:45:52 I've discussed with Phillippe, and given the fact
138 const std::set<std::string>& open_urls,
139 base::ListValue* pages_value) {
140 size_t i = 0;
141 while (i < pages_value->GetSize()) {
142 base::DictionaryValue* page_value;
143 std::string url;
144 if (pages_value->GetDictionary(i, &page_value) &&
145 page_value->GetString("url", &url) &&
146 open_urls.count(url) != 0) {
147 if (pages_value->GetSize() <= kMinUrlSuggestions) {
148 UMA_HISTOGRAM_ENUMERATION(
149 "NewTabPage.MostVisitedTilePlacementExperiment",
150 NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL,
151 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
152 ++i;
153 } else {
154 pages_value->Remove(*page_value, &i);
155 UMA_HISTOGRAM_ENUMERATION(
156 "NewTabPage.MostVisitedTilePlacementExperiment",
157 NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL,
158 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
159 }
160 } else {
161 ++i;
162 }
163 }
164 }
165
166 // static
167 void TopSites::LogInHistogram(NtpTileExperimentActions action) {
168 UMA_HISTOGRAM_ENUMERATION(
169 "NewTabPage.MostVisitedTilePlacementExperiment",
170 action,
171 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
172 }
173
86 } // namespace history 174 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698