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/metrics/field_trial.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "components/variations/variations_associated_data.h"
13 #include "extensions/common/features/feature.h"
14 #include "extensions/common/features/feature_provider.h"
18 const char kFieldTrialName
[] = "EnhancedBookmarks";
20 bool IsBookmarksExtensionHash(const std::string
& sha1_hex
) {
21 return sha1_hex
== "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2" ||
22 sha1_hex
== "D57DE394F36DC1C3220E7604C575D29C51A6C495";
27 bool IsBookmarksExtensionInstalled(
28 const extensions::ExtensionIdSet
& extension_ids
) {
29 // Compare installed extension ids with ones we expect.
30 for (extensions::ExtensionIdSet::const_iterator iter
= extension_ids
.begin();
31 iter
!= extension_ids
.end(); ++iter
) {
32 const std::string id_hash
= base::SHA1HashString(*iter
);
33 DCHECK_EQ(id_hash
.length(), base::kSHA1Length
);
34 std::string hash
= base::HexEncode(id_hash
.c_str(), id_hash
.length());
36 if (IsBookmarksExtensionHash(hash
))
42 bool OptInIntoBookmarksExperiment() {
43 if (base::FieldTrialList::FindFullName(kFieldTrialName
) != "Default")
46 // Opt-in user into Finch group.
47 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
48 command_line
->AppendSwitch(switches::kManualEnhancedBookmarks
);
52 bool IsEnhancedBookmarksExperimentEnabled() {
53 std::string ext_id
= GetEnhancedBookmarksExtensionIdFromFinch();
54 extensions::FeatureProvider
* feature_provider
=
55 extensions::FeatureProvider::GetPermissionFeatures();
56 extensions::Feature
* feature
= feature_provider
->GetFeature("metricsPrivate");
57 return feature
&& feature
->IsIdInWhitelist(ext_id
);
60 bool IsEnableDomDistillerSet() {
61 if (CommandLine::ForCurrentProcess()->
62 HasSwitch(switches::kEnableDomDistiller
)) {
65 if (chrome_variations::GetVariationParamValue(
66 kFieldTrialName
, "enable-dom-distiller") == "1")
72 bool IsEnableSyncArticlesSet() {
73 if (CommandLine::ForCurrentProcess()->
74 HasSwitch(switches::kEnableSyncArticles
)) {
77 if (chrome_variations::GetVariationParamValue(
78 kFieldTrialName
, "enable-sync-articles") == "1")
84 std::string
GetEnhancedBookmarksExtensionIdFromFinch() {
85 return chrome_variations::GetVariationParamValue(kFieldTrialName
, "id");