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

Side by Side Diff: chrome/browser/bookmarks/enhanced_bookmarks_features.cc

Issue 1009673002: Remove enhanced bookmarks sync experiment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: rebase Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/bookmarks/enhanced_bookmarks_features.h" 5 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 12 matching lines...) Expand all
23 #include "extensions/common/features/feature_provider.h" 23 #include "extensions/common/features/feature_provider.h"
24 24
25 #if defined(OS_ANDROID) 25 #if defined(OS_ANDROID)
26 #include "base/android/build_info.h" 26 #include "base/android/build_info.h"
27 #endif 27 #endif
28 28
29 namespace { 29 namespace {
30 30
31 const char kFieldTrialName[] = "EnhancedBookmarks"; 31 const char kFieldTrialName[] = "EnhancedBookmarks";
32 32
33 // Get extension id from Finch EnhancedBookmarks group parameters. 33 } // namespace
34 std::string GetEnhancedBookmarksExtensionIdFromFinch() {
35 return variations::GetVariationParamValue(kFieldTrialName, "id");
36 }
37 34
38 // Returns true if enhanced bookmarks experiment is enabled from Finch. 35 bool GetBookmarksExperimentExtensionID(std::string* extension_id) {
39 bool IsEnhancedBookmarksExperimentEnabledFromFinch() { 36 *extension_id = variations::GetVariationParamValue(kFieldTrialName, "id");
40 const std::string ext_id = GetEnhancedBookmarksExtensionIdFromFinch(); 37 if (extension_id->empty())
38 return false;
39
40 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
41 // "0" - user opted out.
42 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
43 switches::kEnhancedBookmarksExperiment) == "0";
Ted C 2015/03/17 22:58:11 This seems like it removed the ability to opt into
danduong 2015/03/17 23:03:55 Ah, that's right. On mobile, the extension_id is n
Mike Wittman 2015/03/17 23:11:59 Yes. We'd have to continue to force the Finch expe
danduong 2015/03/17 23:15:44 Talked to Ian about it. He'll provide the fix. Thi
44
45 if (opt_out)
46 return false;
47
41 #if defined(OS_ANDROID) 48 #if defined(OS_ANDROID)
42 return !ext_id.empty(); 49 return base::android::BuildInfo::GetInstance()->sdk_int() >
50 base::android::SdkVersion::SDK_VERSION_ICE_CREAM_SANDWICH_MR1;
43 #else 51 #else
44 const extensions::FeatureProvider* feature_provider = 52 const extensions::FeatureProvider* feature_provider =
45 extensions::FeatureProvider::GetPermissionFeatures(); 53 extensions::FeatureProvider::GetPermissionFeatures();
46 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate"); 54 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate");
47 return feature && feature->IsIdInWhitelist(ext_id); 55 return feature && feature->IsIdInWhitelist(*extension_id);
48 #endif 56 #endif
49 } 57 }
50 58
51 }; // namespace
52
53 bool GetBookmarksExperimentExtensionID(const PrefService* user_prefs,
54 std::string* extension_id) {
55 BookmarksExperimentState bookmarks_experiment_state =
56 static_cast<BookmarksExperimentState>(user_prefs->GetInteger(
57 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
58 if (bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED_FROM_FINCH) {
59 *extension_id = GetEnhancedBookmarksExtensionIdFromFinch();
60 return !extension_id->empty();
61 }
62 if (bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED) {
63 *extension_id = user_prefs->GetString(
64 sync_driver::prefs::kEnhancedBookmarksExtensionId);
65 return !extension_id->empty();
66 }
67
68 return false;
69 }
70
71 void UpdateBookmarksExperimentState(
72 PrefService* user_prefs,
73 PrefService* local_state,
74 bool user_signed_in,
75 BookmarksExperimentState experiment_enabled_from_sync) {
76 PrefService* flags_storage = local_state;
77 #if defined(OS_CHROMEOS)
78 // Chrome OS is using user prefs for flags storage.
79 flags_storage = user_prefs;
80 #endif
81
82 BookmarksExperimentState bookmarks_experiment_state_before =
83 static_cast<BookmarksExperimentState>(user_prefs->GetInteger(
84 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
85 // If user signed out, clear possible previous state.
86 if (!user_signed_in) {
87 bookmarks_experiment_state_before = BOOKMARKS_EXPERIMENT_NONE;
88 ForceFinchBookmarkExperimentIfNeeded(flags_storage,
89 BOOKMARKS_EXPERIMENT_NONE);
90 }
91
92 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
93 // "0" - user opted out.
94 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
95 switches::kEnhancedBookmarksExperiment) == "0";
96
97 BookmarksExperimentState bookmarks_experiment_new_state =
98 BOOKMARKS_EXPERIMENT_NONE;
99
100 if (IsEnhancedBookmarksExperimentEnabledFromFinch() && !user_signed_in) {
101 if (opt_out) {
102 // Experiment enabled but user opted out.
103 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_OPT_OUT_FROM_FINCH;
104 } else {
105 // Experiment enabled.
106 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_ENABLED_FROM_FINCH;
107 }
108 } else if (experiment_enabled_from_sync == BOOKMARKS_EXPERIMENT_ENABLED) {
109 // Experiment enabled from Chrome sync.
110 if (opt_out) {
111 // Experiment enabled but user opted out.
112 bookmarks_experiment_new_state =
113 BOOKMARKS_EXPERIMENT_ENABLED_USER_OPT_OUT;
114 } else {
115 // Experiment enabled.
116 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_ENABLED;
117 }
118 } else if (experiment_enabled_from_sync == BOOKMARKS_EXPERIMENT_NONE) {
119 // Experiment is not enabled from Chrome sync.
120 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_NONE;
121 } else if (bookmarks_experiment_state_before ==
122 BOOKMARKS_EXPERIMENT_ENABLED) {
123 if (opt_out) {
124 // Experiment enabled but user opted out.
125 bookmarks_experiment_new_state =
126 BOOKMARKS_EXPERIMENT_ENABLED_USER_OPT_OUT;
127 } else {
128 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_ENABLED;
129 }
130 } else if (bookmarks_experiment_state_before ==
131 BOOKMARKS_EXPERIMENT_ENABLED_USER_OPT_OUT) {
132 if (opt_out) {
133 bookmarks_experiment_new_state =
134 BOOKMARKS_EXPERIMENT_ENABLED_USER_OPT_OUT;
135 } else {
136 // User opted in again.
137 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_ENABLED;
138 }
139 }
140
141 #if defined(OS_ANDROID)
142 if (base::android::BuildInfo::GetInstance()->sdk_int() <=
143 base::android::SdkVersion::SDK_VERSION_ICE_CREAM_SANDWICH_MR1) {
144 opt_out = true;
145 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_NONE;
146 }
147 bool opt_in = !opt_out &&
148 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
149 switches::kEnhancedBookmarksExperiment) == "1";
150 if (opt_in && bookmarks_experiment_new_state == BOOKMARKS_EXPERIMENT_NONE)
151 bookmarks_experiment_new_state = BOOKMARKS_EXPERIMENT_ENABLED;
152 #endif
153
154 UMA_HISTOGRAM_ENUMERATION("EnhancedBookmarks.SyncExperimentState",
155 bookmarks_experiment_new_state,
156 BOOKMARKS_EXPERIMENT_ENUM_SIZE);
157 user_prefs->SetInteger(
158 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled,
159 bookmarks_experiment_new_state);
160 ForceFinchBookmarkExperimentIfNeeded(flags_storage,
161 bookmarks_experiment_new_state);
162 }
163
164 void InitBookmarksExperimentState(Profile* profile) {
165 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
166 bool is_signed_in = signin && signin->IsAuthenticated();
167 UpdateBookmarksExperimentState(
168 profile->GetPrefs(),
169 g_browser_process->local_state(),
170 is_signed_in,
171 BOOKMARKS_EXPERIMENT_ENABLED_FROM_SYNC_UNKNOWN);
172 }
173
174 void ForceFinchBookmarkExperimentIfNeeded(
175 PrefService* flags_storage,
176 BookmarksExperimentState bookmarks_experiment_state) {
177 if (!flags_storage)
178 return;
179 ListPrefUpdate update(flags_storage, prefs::kEnabledLabsExperiments);
180 base::ListValue* experiments_list = update.Get();
181 if (!experiments_list)
182 return;
183 size_t index;
184 if (bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_NONE) {
185 experiments_list->Remove(
186 base::StringValue(switches::kManualEnhancedBookmarks), &index);
187 experiments_list->Remove(
188 base::StringValue(switches::kManualEnhancedBookmarksOptout), &index);
189 } else if (bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED) {
190 experiments_list->Remove(
191 base::StringValue(switches::kManualEnhancedBookmarksOptout), &index);
192 experiments_list->AppendIfNotPresent(
193 new base::StringValue(switches::kManualEnhancedBookmarks));
194 } else if (bookmarks_experiment_state ==
195 BOOKMARKS_EXPERIMENT_ENABLED_USER_OPT_OUT) {
196 experiments_list->Remove(
197 base::StringValue(switches::kManualEnhancedBookmarks), &index);
198 experiments_list->AppendIfNotPresent(
199 new base::StringValue(switches::kManualEnhancedBookmarksOptout));
200 }
201 }
202
203 bool IsEnhancedBookmarksExperimentEnabled(
204 about_flags::FlagsStorage* flags_storage) {
205 #if defined(OS_CHROMEOS)
206 // We are not setting command line flags on Chrome OS to avoid browser restart
207 // but still have flags in flags_storage. So check flags_storage instead.
208 const std::set<std::string> flags = flags_storage->GetFlags();
209 if (flags.find(switches::kManualEnhancedBookmarks) != flags.end())
210 return true;
211 if (flags.find(switches::kManualEnhancedBookmarksOptout) != flags.end())
212 return true;
213 #else
214 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
215 if (command_line->HasSwitch(switches::kManualEnhancedBookmarks) ||
216 command_line->HasSwitch(switches::kManualEnhancedBookmarksOptout)) {
217 return true;
218 }
219 #endif
220
221 return IsEnhancedBookmarksExperimentEnabledFromFinch();
222 }
223
224 #if defined(OS_ANDROID) 59 #if defined(OS_ANDROID)
225 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) { 60 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) {
226 if (IsEnhancedBookmarksEnabled(user_prefs)) 61 if (IsEnhancedBookmarksEnabled())
227 return true; 62 return true;
228 63
229 // Salient images are collected from visited bookmarked pages even if the 64 // Salient images are collected from visited bookmarked pages even if the
230 // enhanced bookmark feature is turned off. This is to have some images 65 // enhanced bookmark feature is turned off. This is to have some images
231 // available so that in the future, when the feature is turned on, the user 66 // available so that in the future, when the feature is turned on, the user
232 // experience is not a big list of flat colors. However as a precautionary 67 // experience is not a big list of flat colors. However as a precautionary
233 // measure it is possible to disable this collection of images from finch. 68 // measure it is possible to disable this collection of images from finch.
234 std::string disable_fetching = variations::GetVariationParamValue( 69 std::string disable_fetching = variations::GetVariationParamValue(
235 kFieldTrialName, "DisableImagesFetching"); 70 kFieldTrialName, "DisableImagesFetching");
236 return disable_fetching.empty(); 71 return disable_fetching.empty();
237 } 72 }
238 73
239 bool IsEnhancedBookmarksEnabled(const PrefService* user_prefs) { 74 bool IsEnhancedBookmarksEnabled() {
240 BookmarksExperimentState bookmarks_experiment_state = 75 std::string extension_id;
241 static_cast<BookmarksExperimentState>(user_prefs->GetInteger( 76 return GetBookmarksExperimentExtensionID(&extension_id);
242 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
243 return bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED ||
244 bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED_FROM_FINCH;
245 } 77 }
246 #endif 78 #endif
247 79
248 bool IsEnableDomDistillerSet() { 80 bool IsEnableDomDistillerSet() {
249 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 81 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
250 switches::kEnableDomDistiller)) { 82 switches::kEnableDomDistiller)) {
251 return true; 83 return true;
252 } 84 }
253 if (variations::GetVariationParamValue( 85 if (variations::GetVariationParamValue(
254 kFieldTrialName, "enable-dom-distiller") == "1") 86 kFieldTrialName, "enable-dom-distiller") == "1")
255 return true; 87 return true;
256 88
257 return false; 89 return false;
258 } 90 }
259 91
260 bool IsEnableSyncArticlesSet() { 92 bool IsEnableSyncArticlesSet() {
261 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 93 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
262 switches::kEnableSyncArticles)) { 94 switches::kEnableSyncArticles)) {
263 return true; 95 return true;
264 } 96 }
265 if (variations::GetVariationParamValue( 97 if (variations::GetVariationParamValue(
266 kFieldTrialName, "enable-sync-articles") == "1") 98 kFieldTrialName, "enable-sync-articles") == "1")
267 return true; 99 return true;
268 100
269 return false; 101 return false;
270 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698