Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / bookmarks / enhanced_bookmarks_features.cc
blobe18f18f7dbe637a817560ef643d0c8dd6d4e1176
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"
18 namespace {
20 const char kFieldTrialName[] = "EnhancedBookmarks";
22 }; // namespace
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();
29 size_t index;
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)) {
53 return true;
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)) {
66 return true;
68 if (chrome_variations::GetVariationParamValue(
69 kFieldTrialName, "enable-dom-distiller") == "1")
70 return true;
72 return false;
75 bool IsEnableSyncArticlesSet() {
76 if (CommandLine::ForCurrentProcess()->
77 HasSwitch(switches::kEnableSyncArticles)) {
78 return true;
80 if (chrome_variations::GetVariationParamValue(
81 kFieldTrialName, "enable-sync-articles") == "1")
82 return true;
84 return false;
87 std::string GetEnhancedBookmarksExtensionIdFromFinch() {
88 return chrome_variations::GetVariationParamValue(kFieldTrialName, "id");