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
3 // found in the LICENSE file.
5 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/sha1.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/variations/variations_associated_data.h"
15 #include "extensions/common/features/feature.h"
16 #include "extensions/common/features/feature_provider.h"
20 const char kFieldTrialName
[] = "EnhancedBookmarks";
24 void UpdateBookmarksExperiment(
25 PrefService
* local_state
,
26 BookmarksExperimentState bookmarks_experiment_state
) {
27 ListPrefUpdate
update(local_state
, prefs::kEnabledLabsExperiments
);
28 base::ListValue
* experiments_list
= update
.Get();
30 if (bookmarks_experiment_state
== kNoBookmarksExperiment
) {
31 experiments_list
->Remove(
32 base::StringValue(switches::kManualEnhancedBookmarks
), &index
);
33 experiments_list
->Remove(
34 base::StringValue(switches::kManualEnhancedBookmarksOptout
), &index
);
35 } else if (bookmarks_experiment_state
== kBookmarksExperimentEnabled
) {
36 experiments_list
->Remove(
37 base::StringValue(switches::kManualEnhancedBookmarksOptout
), &index
);
38 experiments_list
->AppendIfNotPresent(
39 new base::StringValue(switches::kManualEnhancedBookmarks
));
40 } else if (bookmarks_experiment_state
==
41 kBookmarksExperimentEnabledUserOptOut
) {
42 experiments_list
->Remove(
43 base::StringValue(switches::kManualEnhancedBookmarks
), &index
);
44 experiments_list
->AppendIfNotPresent(
45 new base::StringValue(switches::kManualEnhancedBookmarksOptout
));
49 bool IsEnhancedBookmarksExperimentEnabled() {
50 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
51 if (command_line
->HasSwitch(switches::kManualEnhancedBookmarks
) ||
52 command_line
->HasSwitch(switches::kManualEnhancedBookmarksOptout
)) {
56 std::string ext_id
= GetEnhancedBookmarksExtensionIdFromFinch();
57 extensions::FeatureProvider
* feature_provider
=
58 extensions::FeatureProvider::GetPermissionFeatures();
59 extensions::Feature
* feature
= feature_provider
->GetFeature("metricsPrivate");
60 return feature
&& feature
->IsIdInWhitelist(ext_id
);
63 bool IsEnableDomDistillerSet() {
64 if (CommandLine::ForCurrentProcess()->
65 HasSwitch(switches::kEnableDomDistiller
)) {
68 if (chrome_variations::GetVariationParamValue(
69 kFieldTrialName
, "enable-dom-distiller") == "1")
75 bool IsEnableSyncArticlesSet() {
76 if (CommandLine::ForCurrentProcess()->
77 HasSwitch(switches::kEnableSyncArticles
)) {
80 if (chrome_variations::GetVariationParamValue(
81 kFieldTrialName
, "enable-sync-articles") == "1")
87 std::string
GetEnhancedBookmarksExtensionIdFromFinch() {
88 return chrome_variations::GetVariationParamValue(kFieldTrialName
, "id");