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

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: Spacing fix 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 const char kOneEightGroupPrefix[] = "OneEight";
23 const char kOneFourGroupPrefix[] = "OneFour";
24 const char kFlippedSuffix[] = "Flipped";
25 const char kDontShowOpenURLsGroupName[] = "DontShowOpenTabs";
26
27 } // namespace
28
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 MostVisitedTilesExperiment::kMinUrlSuggestions = 8;
32
33 const char MostVisitedTilesExperiment::kMostVisitedExperimentHistogramName[] =
34 "NewTabPage.MostVisitedTilePlacementExperiment";
Alexei Svitkine (slow) 2013/07/22 21:14:10 Is there a reason you're defining this here and no
annark1 2013/07/23 19:52:21 I missed implementing it, thanks for catching. On
35
36 // static
37 void MostVisitedTilesExperiment::MaybeShuffle(MostVisitedURLList* data) {
38 const std::string group_name =
39 base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName);
40
41 // Depending on the study group of the client, we might flip the 1st and 4th
42 // tiles, or the 1st and 8th, or do nothing.
43 if (!EndsWith(group_name, kFlippedSuffix, true))
44 return;
45
46 size_t index_to_flip = 0;
47 if (StartsWithASCII(group_name, kOneEightGroupPrefix, true)) {
48 if (data->size() < 8) {
49 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_8);
50 return;
51 }
52 index_to_flip = 7;
53 } else if (StartsWithASCII(group_name, kOneFourGroupPrefix, true)) {
54 if (data->size() < 4) {
55 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_TOO_FEW_URLS_TILES_1_4);
56 return;
57 }
58 index_to_flip = 3;
59 }
60 std::swap((*data)[0], (*data)[index_to_flip]);
61 }
62
63 // static
64 bool MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled() {
65 return base::FieldTrialList::FindFullName(kMostVisitedFieldTrialName) ==
66 kDontShowOpenURLsGroupName;
67 }
68
69 // static
70 void MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs(
71 const std::set<std::string>& open_urls,
72 std::vector<InstantMostVisitedItem>* items) {
73 for (size_t i = 0; i < items->size(); ) {
74 const std::string& url = (*items)[i].url.spec();
75 if (open_urls.count(url) != 0) {
76 if (items->size() <= MostVisitedTilesExperiment::kMinUrlSuggestions) {
77 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL);
78 ++i;
79 } else {
80 items->erase(items->begin() + i);
81 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL);
82 }
83 } else {
84 ++i;
85 }
86 }
87 }
88
89 // static
90 void MostVisitedTilesExperiment::RemovePageValuesMatchingOpenTabs(
91 const std::set<std::string>& open_urls,
92 base::ListValue* pages_value) {
93 for (size_t i = 0; i < pages_value->GetSize(); ) {
94 base::DictionaryValue* page_value;
95 std::string url;
96 if (pages_value->GetDictionary(i, &page_value) &&
97 page_value->GetString("url", &url) &&
98 open_urls.count(url) != 0) {
99 if (pages_value->GetSize() <=
100 MostVisitedTilesExperiment::kMinUrlSuggestions) {
101 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_DID_NOT_REMOVE_URL);
102 ++i;
103 } else {
104 pages_value->Remove(*page_value, &i);
105 LogInHistogram(NTP_TILE_EXPERIMENT_ACTION_REMOVED_URL);
106 }
107 } else {
108 ++i;
109 }
110 }
111 }
112
113 // static
114 void MostVisitedTilesExperiment::LogInHistogram(
115 NtpTileExperimentActions action) {
116 UMA_HISTOGRAM_ENUMERATION(
117 "NewTabPage.MostVisitedTilePlacementExperiment",
118 action,
119 NUM_NTP_TILE_EXPERIMENT_ACTIONS);
120 }
121
122 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698