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

Side by Side Diff: chrome/browser/history/most_visited_tiles_experiment.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 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
(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 (ShouldRemoveURL(open_urls, url, items->size()))
75 items->erase(items->begin() + i);
76 else
77 ++i;
78 }
79 }
80
81 // static
82 void MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs(
83 const std::set<std::string>& open_urls,
84 base::ListValue* pages_value) {
85 for (size_t i = 0; i < pages_value->GetSize(); ) {
86 base::DictionaryValue* page_value;
87 std::string url;
88 if (pages_value->GetDictionary(i, &page_value) &&
89 page_value->GetString("url", &url) &&
90 ShouldRemoveURL(open_urls, url, pages_value->GetSize())) {
91 pages_value->Remove(*page_value, &i);
92 } else {
93 ++i;
94 }
95 }
96 }
97
98 // static
99 void MostVisitedTilesExperiment::LogInHistogram(
100 NtpTileExperimentActions action) {
101 UMA_HISTOGRAM_ENUMERATION(kMostVisitedExperimentHistogramName,
102 action,
103 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
104 }
105
106 // static
107 bool MostVisitedTilesExperiment::ShouldRemoveURL(
108 const std::set<std::string>& open_urls,
109 const std::string& url,
110 const size_t size) {
111 if (open_urls.count(url) == 0)
112 return false;
113
114 if (size <= kMinUrlSuggestions) {
115 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL);
116 return false;
117 } else {
Alexei Svitkine (slow) 2013/07/24 21:04:31 Nit: No need for the else block if you're returnin
annark1 2013/07/24 21:51:40 Done.
118 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL);
119 return true;
120 }
121 }
122
123 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698