Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/browser/bookmarks/enhanced_bookmarks_features.cc

Issue 265843009: Restored an option to enable enhanced bookmarks experiment from Finch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 5 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/sha1.h" 11 #include "base/sha1.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "components/sync_driver/pref_names.h"
14 #include "components/variations/variations_associated_data.h" 16 #include "components/variations/variations_associated_data.h"
15 #include "extensions/common/features/feature.h" 17 #include "extensions/common/features/feature.h"
16 #include "extensions/common/features/feature_provider.h" 18 #include "extensions/common/features/feature_provider.h"
17 19
18 namespace { 20 namespace {
19 21
20 const char kFieldTrialName[] = "EnhancedBookmarks"; 22 const char kFieldTrialName[] = "EnhancedBookmarks";
21 23
24 // Get extension id from Finch EnhancedBookmarks group parameters.
25 std::string GetEnhancedBookmarksExtensionIdFromFinch() {
26 return chrome_variations::GetVariationParamValue(kFieldTrialName, "id");
27 }
28
29 // Returns true if enhanced bookmarks experiment is enabled from Finch.
30 bool IsEnhancedBookmarksExperimentEnabledFromFinch() {
31 std::string ext_id = GetEnhancedBookmarksExtensionIdFromFinch();
32 extensions::FeatureProvider* feature_provider =
33 extensions::FeatureProvider::GetPermissionFeatures();
34 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate");
35 return feature && feature->IsIdInWhitelist(ext_id);
36 }
37
22 }; // namespace 38 }; // namespace
23 39
24 void UpdateBookmarksExperiment( 40 bool GetBookmarksExperimentExtensionID(const PrefService* user_prefs,
41 std::string* extension_id) {
42 BookmarksExperimentState bookmarks_experiment_state =
43 static_cast<BookmarksExperimentState>(user_prefs->GetInteger(
44 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
45 if (bookmarks_experiment_state == kBookmarksExperimentEnabledFromFinch) {
46 *extension_id = GetEnhancedBookmarksExtensionIdFromFinch();
47 return !extension_id->empty();
48 }
49 if (bookmarks_experiment_state == kBookmarksExperimentEnabled) {
50 *extension_id = user_prefs->GetString(
51 sync_driver::prefs::kEnhancedBookmarksExtensionId);
52 return !extension_id->empty();
53 }
54
55 return false;
56 }
57
58 void UpdateBookmarksExperimentState(const PrefService* user_prefs,
59 PrefService* local_state,
60 bool user_signed_in) {
61 BookmarksExperimentState bookmarks_experiment_state_before =
62 static_cast<BookmarksExperimentState>(user_prefs->GetInteger(
63 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
64 // If user signed out, clear possible previous state.
65 if (!user_signed_in) {
66 bookmarks_experiment_state_before = kNoBookmarksExperiment;
67 ForceFinchBoomarkExperimentIfNeeded(local_state, kNoBookmarksExperiment);
68 }
69
70 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0".
71 // "0" - user opted out.
72 bool opt_out = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
73 switches::kEnhancedBookmarksExperiment) == "0";
74
75 BookmarksExperimentState bookmarks_experiment_new_state =
76 kNoBookmarksExperiment;
77 bool enabled_from_finch = false;
78 if (IsEnhancedBookmarksExperimentEnabledFromFinch()) {
79 enabled_from_finch = !user_signed_in;
80 if (user_signed_in) {
81 bookmarks_experiment_new_state =
82 kBookmarksExperimentEnabledFromFinchUserSignedIn;
83 }
84 }
85
86 if (enabled_from_finch) {
87 if (opt_out) {
88 // Experiment enabled but user opted out.
89 bookmarks_experiment_new_state = kBookmarksExperimentOptOutFromFinch;
90 } else {
91 // Experiment enabled.
92 bookmarks_experiment_new_state = kBookmarksExperimentEnabledFromFinch;
93 }
94 } else if (bookmarks_experiment_state_before == kBookmarksExperimentEnabled) {
95 if (opt_out) {
96 // Experiment enabled but user opted out.
97 bookmarks_experiment_new_state = kBookmarksExperimentEnabledUserOptOut;
98 } else {
99 bookmarks_experiment_new_state = kBookmarksExperimentEnabled;
100 }
101 } else if (bookmarks_experiment_state_before ==
102 kBookmarksExperimentEnabledUserOptOut) {
103 if (opt_out) {
104 bookmarks_experiment_new_state = kBookmarksExperimentEnabledUserOptOut;
105 } else {
106 // User opted in again.
107 bookmarks_experiment_new_state = kBookmarksExperimentEnabled;
108 }
109 }
110
111 UMA_HISTOGRAM_ENUMERATION("EnhancedBookmarks.SyncExperimentState",
112 bookmarks_experiment_new_state,
113 kBookmarksExperimentEnumSize);
114 if (bookmarks_experiment_state_before != bookmarks_experiment_new_state)
115 ForceFinchBoomarkExperimentIfNeeded(local_state,
116 bookmarks_experiment_new_state);
117 }
118
119 void ForceFinchBoomarkExperimentIfNeeded(
25 PrefService* local_state, 120 PrefService* local_state,
26 BookmarksExperimentState bookmarks_experiment_state) { 121 BookmarksExperimentState bookmarks_experiment_state) {
27 ListPrefUpdate update(local_state, prefs::kEnabledLabsExperiments); 122 ListPrefUpdate update(local_state, prefs::kEnabledLabsExperiments);
28 base::ListValue* experiments_list = update.Get(); 123 base::ListValue* experiments_list = update.Get();
29 size_t index; 124 size_t index;
30 if (bookmarks_experiment_state == kNoBookmarksExperiment) { 125 if (bookmarks_experiment_state == kNoBookmarksExperiment) {
31 experiments_list->Remove( 126 experiments_list->Remove(
32 base::StringValue(switches::kManualEnhancedBookmarks), &index); 127 base::StringValue(switches::kManualEnhancedBookmarks), &index);
33 experiments_list->Remove( 128 experiments_list->Remove(
34 base::StringValue(switches::kManualEnhancedBookmarksOptout), &index); 129 base::StringValue(switches::kManualEnhancedBookmarksOptout), &index);
(...skipping 11 matching lines...) Expand all
46 } 141 }
47 } 142 }
48 143
49 bool IsEnhancedBookmarksExperimentEnabled() { 144 bool IsEnhancedBookmarksExperimentEnabled() {
50 CommandLine* command_line = CommandLine::ForCurrentProcess(); 145 CommandLine* command_line = CommandLine::ForCurrentProcess();
51 if (command_line->HasSwitch(switches::kManualEnhancedBookmarks) || 146 if (command_line->HasSwitch(switches::kManualEnhancedBookmarks) ||
52 command_line->HasSwitch(switches::kManualEnhancedBookmarksOptout)) { 147 command_line->HasSwitch(switches::kManualEnhancedBookmarksOptout)) {
53 return true; 148 return true;
54 } 149 }
55 150
56 std::string ext_id = GetEnhancedBookmarksExtensionIdFromFinch(); 151 return IsEnhancedBookmarksExperimentEnabledFromFinch();
57 extensions::FeatureProvider* feature_provider =
58 extensions::FeatureProvider::GetPermissionFeatures();
59 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate");
60 return feature && feature->IsIdInWhitelist(ext_id);
61 } 152 }
62 153
63 bool IsEnableDomDistillerSet() { 154 bool IsEnableDomDistillerSet() {
64 if (CommandLine::ForCurrentProcess()-> 155 if (CommandLine::ForCurrentProcess()->
65 HasSwitch(switches::kEnableDomDistiller)) { 156 HasSwitch(switches::kEnableDomDistiller)) {
66 return true; 157 return true;
67 } 158 }
68 if (chrome_variations::GetVariationParamValue( 159 if (chrome_variations::GetVariationParamValue(
69 kFieldTrialName, "enable-dom-distiller") == "1") 160 kFieldTrialName, "enable-dom-distiller") == "1")
70 return true; 161 return true;
71 162
72 return false; 163 return false;
73 } 164 }
74 165
75 bool IsEnableSyncArticlesSet() { 166 bool IsEnableSyncArticlesSet() {
76 if (CommandLine::ForCurrentProcess()-> 167 if (CommandLine::ForCurrentProcess()->
77 HasSwitch(switches::kEnableSyncArticles)) { 168 HasSwitch(switches::kEnableSyncArticles)) {
78 return true; 169 return true;
79 } 170 }
80 if (chrome_variations::GetVariationParamValue( 171 if (chrome_variations::GetVariationParamValue(
81 kFieldTrialName, "enable-sync-articles") == "1") 172 kFieldTrialName, "enable-sync-articles") == "1")
82 return true; 173 return true;
83 174
84 return false; 175 return false;
85 } 176 }
86
87 std::string GetEnhancedBookmarksExtensionIdFromFinch() {
88 return chrome_variations::GetVariationParamValue(kFieldTrialName, "id");
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698