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/enhanced_bookmarks/enhanced_bookmark_utils.h"
11 #include "components/variations/variations_associated_data.h"
13 #if !defined(OS_ANDROID) && !defined(OS_IOS)
14 #include "extensions/common/features/feature.h"
15 #include "extensions/common/features/feature_provider.h"
16 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
20 bool GetBookmarksExperimentExtensionID(std::string
* extension_id
) {
21 *extension_id
= variations::GetVariationParamValue(
22 enhanced_bookmarks::kFieldTrialName
, "id");
23 if (extension_id
->empty())
26 #if defined(OS_ANDROID) || defined(OS_IOS)
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)
38 #if defined(OS_ANDROID)
39 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService
* user_prefs
) {
40 if (IsEnhancedBookmarksEnabled())
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 enhanced_bookmarks::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";
70 #endif // defined(OS_ANDROID) || defined(OS_IOS)
72 bool opt_out
= base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
73 switches::kEnhancedBookmarksExperiment
) == "0";
78 return GetBookmarksExperimentExtensionID(extension_id
);
81 bool IsEnableDomDistillerSet() {
82 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
83 switches::kEnableDomDistiller
)) {
86 if (variations::GetVariationParamValue(enhanced_bookmarks::kFieldTrialName
,
87 "enable-dom-distiller") == "1")
93 bool IsEnableSyncArticlesSet() {
94 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
95 switches::kEnableSyncArticles
)) {
98 if (variations::GetVariationParamValue(enhanced_bookmarks::kFieldTrialName
,
99 "enable-sync-articles") == "1")