Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / bookmarks / enhanced_bookmarks_features.cc
blob8f69f07755d66f766decb50a167c5ba59c7fdb84
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 #if defined(OS_ANDROID)
18 #include "base/android/build_info.h"
19 #endif // defined(OS_ANDROID)
21 namespace {
23 const char kFieldTrialName[] = "EnhancedBookmarks";
25 bool GetBookmarksExperimentExtensionID(std::string* extension_id) {
26 *extension_id = variations::GetVariationParamValue(kFieldTrialName, "id");
27 if (extension_id->empty())
28 return false;
30 #if defined(OS_ANDROID) || defined(OS_IOS)
31 return true;
32 #else
33 const extensions::FeatureProvider* feature_provider =
34 extensions::FeatureProvider::GetPermissionFeatures();
35 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate");
36 return feature && feature->IsIdInWhitelist(*extension_id);
37 #endif // defined(OS_ANDROID) || defined(OS_IOS)
40 } // namespace
42 #if defined(OS_ANDROID)
43 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) {
44 if (IsEnhancedBookmarksEnabled())
45 return true;
47 // Salient images are collected from visited bookmarked pages even if the
48 // enhanced bookmark feature is turned off. This is to have some images
49 // available so that in the future, when the feature is turned on, the user
50 // experience is not a big list of flat colors. However as a precautionary
51 // measure it is possible to disable this collection of images from finch.
52 std::string disable_fetching = variations::GetVariationParamValue(
53 kFieldTrialName, "DisableImagesFetching");
54 return disable_fetching.empty();
56 #endif // defined(OS_ANDROID)
58 bool IsEnhancedBookmarksEnabled() {
59 std::string extension_id;
60 return IsEnhancedBookmarksEnabled(&extension_id);
63 bool IsEnhancedBookmarksEnabled(std::string* extension_id) {
64 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
65 // "0" - user opted out. "1" is only possible on mobile as desktop needs a
66 // extension id that would not be available by just using the flag.
68 #if defined(OS_ANDROID) || defined(OS_IOS)
69 // Tests use command line flag to force enhanced bookmark to be on.
70 bool opt_in = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
71 switches::kEnhancedBookmarksExperiment) == "1";
72 if (opt_in)
73 return true;
74 #endif // defined(OS_ANDROID) || defined(OS_IOS)
76 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
77 switches::kEnhancedBookmarksExperiment) == "0";
78 #if defined(OS_ANDROID)
79 opt_out |= base::android::BuildInfo::GetInstance()->sdk_int() <
80 base::android::SdkVersion::SDK_VERSION_ICE_CREAM_SANDWICH_MR1;
81 #endif // defined(OS_ANDROID)
83 if (opt_out)
84 return false;
86 return GetBookmarksExperimentExtensionID(extension_id);
89 bool IsEnableDomDistillerSet() {
90 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
91 switches::kEnableDomDistiller)) {
92 return true;
94 if (variations::GetVariationParamValue(
95 kFieldTrialName, "enable-dom-distiller") == "1")
96 return true;
98 return false;
101 bool IsEnableSyncArticlesSet() {
102 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
103 switches::kEnableSyncArticles)) {
104 return true;
106 if (variations::GetVariationParamValue(
107 kFieldTrialName, "enable-sync-articles") == "1")
108 return true;
110 return false;