Remove 'RemoveTrailingSeparators' function from SimpleMenuModel
[chromium-blink-merge.git] / chrome / browser / bookmarks / enhanced_bookmarks_features.cc
blobbbe6335092052daa33d525ef524a42d0f10c7076
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 "chrome/common/chrome_switches.h"
10 #include "components/variations/variations_associated_data.h"
12 #if !defined(OS_ANDROID) && !defined(OS_IOS)
13 #include "extensions/common/features/feature.h"
14 #include "extensions/common/features/feature_provider.h"
15 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
17 namespace {
19 const char kFieldTrialName[] = "EnhancedBookmarks";
21 bool GetBookmarksExperimentExtensionID(std::string* extension_id) {
22 *extension_id = variations::GetVariationParamValue(kFieldTrialName, "id");
23 if (extension_id->empty())
24 return false;
26 #if defined(OS_ANDROID) || defined(OS_IOS)
27 return true;
28 #else
29 const extensions::FeatureProvider* feature_provider =
30 extensions::FeatureProvider::GetPermissionFeatures();
31 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate");
32 return feature && feature->IsIdInWhitelist(*extension_id);
33 #endif // defined(OS_ANDROID) || defined(OS_IOS)
36 } // namespace
38 #if defined(OS_ANDROID)
39 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) {
40 if (IsEnhancedBookmarksEnabled())
41 return true;
43 // Salient images are collected from visited bookmarked pages even if the
44 // enhanced bookmark feature is turned off. This is to have some images
45 // available so that in the future, when the feature is turned on, the user
46 // experience is not a big list of flat colors. However as a precautionary
47 // measure it is possible to disable this collection of images from finch.
48 std::string disable_fetching = variations::GetVariationParamValue(
49 kFieldTrialName, "DisableImagesFetching");
50 return disable_fetching.empty();
52 #endif // defined(OS_ANDROID)
54 bool IsEnhancedBookmarksEnabled() {
55 std::string extension_id;
56 return IsEnhancedBookmarksEnabled(&extension_id);
59 bool IsEnhancedBookmarksEnabled(std::string* extension_id) {
60 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
61 // "0" - user opted out. "1" is only possible on mobile as desktop needs a
62 // extension id that would not be available by just using the flag.
64 #if defined(OS_ANDROID) || defined(OS_IOS)
65 // Tests use command line flag to force enhanced bookmark to be on.
66 bool opt_in = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
67 switches::kEnhancedBookmarksExperiment) == "1";
68 if (opt_in)
69 return true;
70 #endif // defined(OS_ANDROID) || defined(OS_IOS)
72 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
73 switches::kEnhancedBookmarksExperiment) == "0";
75 if (opt_out)
76 return false;
78 return GetBookmarksExperimentExtensionID(extension_id);
81 bool IsEnableDomDistillerSet() {
82 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
83 switches::kEnableDomDistiller)) {
84 return true;
86 if (variations::GetVariationParamValue(
87 kFieldTrialName, "enable-dom-distiller") == "1")
88 return true;
90 return false;
93 bool IsEnableSyncArticlesSet() {
94 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
95 switches::kEnableSyncArticles)) {
96 return true;
98 if (variations::GetVariationParamValue(
99 kFieldTrialName, "enable-sync-articles") == "1")
100 return true;
102 return false;