OLD | NEW |
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 |
22 }; // namespace | 24 }; // namespace |
23 | 25 |
| 26 bool GetBookmarksExperimentExtensionID(const PrefService* user_prefs, |
| 27 std::string* extension_id) { |
| 28 BookmarksExperimentState bookmarks_experiment_state = |
| 29 static_cast<BookmarksExperimentState>(user_prefs->GetInteger( |
| 30 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled)); |
| 31 if (bookmarks_experiment_state == kBookmarksExperimentEnabledFromFinch) { |
| 32 *extension_id = GetEnhancedBookmarksExtensionIdFromFinch(); |
| 33 return !extension_id->empty(); |
| 34 } |
| 35 if (bookmarks_experiment_state == kBookmarksExperimentEnabled) { |
| 36 *extension_id = user_prefs->GetString( |
| 37 sync_driver::prefs::kEnhancedBookmarksExtensionId); |
| 38 return !extension_id->empty(); |
| 39 } |
| 40 |
| 41 return false; |
| 42 } |
| 43 |
| 44 void UpdateBookmarksExperimentState(const PrefService* user_prefs, |
| 45 PrefService* local_state, |
| 46 bool user_signed_in) { |
| 47 BookmarksExperimentState bookmarks_experiment_state_before = |
| 48 static_cast<BookmarksExperimentState>(user_prefs->GetInteger( |
| 49 sync_driver::prefs::kEnhancedBookmarksExperimentEnabled)); |
| 50 // If user signed out, clear possible previous state. |
| 51 if (!user_signed_in) { |
| 52 bookmarks_experiment_state_before = kNoBookmarksExperiment; |
| 53 UpdateBookmarksExperiment(local_state, kNoBookmarksExperiment); |
| 54 } |
| 55 |
| 56 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". |
| 57 // "0" - user opted out. |
| 58 bool opt_out = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 59 switches::kEnhancedBookmarksExperiment) == "0"; |
| 60 |
| 61 BookmarksExperimentState bookmarks_experiment_new_state = |
| 62 kNoBookmarksExperiment; |
| 63 bool enabled_from_finch = false; |
| 64 if (IsEnhancedBookmarksExperimentEnabledFromFinch()) { |
| 65 enabled_from_finch = !user_signed_in; |
| 66 if (user_signed_in) { |
| 67 bookmarks_experiment_new_state = |
| 68 kBookmarksExperimentEnabledFromFinchUserSignedIn; |
| 69 } |
| 70 } |
| 71 |
| 72 if (enabled_from_finch) { |
| 73 if (opt_out) { |
| 74 // Experiment enabled but user opted out. |
| 75 bookmarks_experiment_new_state = kBookmarksExperimentOptOutFromFinch; |
| 76 } else { |
| 77 // Experiment enabled. |
| 78 bookmarks_experiment_new_state = kBookmarksExperimentEnabledFromFinch; |
| 79 } |
| 80 } else if (bookmarks_experiment_state_before == kBookmarksExperimentEnabled) { |
| 81 if (opt_out) { |
| 82 // Experiment enabled but user opted out. |
| 83 bookmarks_experiment_new_state = kBookmarksExperimentEnabledUserOptOut; |
| 84 } else { |
| 85 bookmarks_experiment_new_state = kBookmarksExperimentEnabled; |
| 86 } |
| 87 } else if (bookmarks_experiment_state_before == |
| 88 kBookmarksExperimentEnabledUserOptOut) { |
| 89 if (opt_out) { |
| 90 bookmarks_experiment_new_state = kBookmarksExperimentEnabledUserOptOut; |
| 91 } else { |
| 92 // User opted in again. |
| 93 bookmarks_experiment_new_state = kBookmarksExperimentEnabled; |
| 94 } |
| 95 } |
| 96 |
| 97 UMA_HISTOGRAM_ENUMERATION("EnhancedBookmarks.SyncExperimentState", |
| 98 bookmarks_experiment_new_state, |
| 99 kBookmarksExperimentEnumSize); |
| 100 if (bookmarks_experiment_state_before != bookmarks_experiment_new_state) |
| 101 UpdateBookmarksExperiment(local_state, bookmarks_experiment_new_state); |
| 102 } |
| 103 |
24 void UpdateBookmarksExperiment( | 104 void UpdateBookmarksExperiment( |
25 PrefService* local_state, | 105 PrefService* local_state, |
26 BookmarksExperimentState bookmarks_experiment_state) { | 106 BookmarksExperimentState bookmarks_experiment_state) { |
27 ListPrefUpdate update(local_state, prefs::kEnabledLabsExperiments); | 107 ListPrefUpdate update(local_state, prefs::kEnabledLabsExperiments); |
28 base::ListValue* experiments_list = update.Get(); | 108 base::ListValue* experiments_list = update.Get(); |
29 size_t index; | 109 size_t index; |
30 if (bookmarks_experiment_state == kNoBookmarksExperiment) { | 110 if (bookmarks_experiment_state == kNoBookmarksExperiment) { |
31 experiments_list->Remove( | 111 experiments_list->Remove( |
32 base::StringValue(switches::kManualEnhancedBookmarks), &index); | 112 base::StringValue(switches::kManualEnhancedBookmarks), &index); |
33 experiments_list->Remove( | 113 experiments_list->Remove( |
(...skipping 12 matching lines...) Expand all Loading... |
46 } | 126 } |
47 } | 127 } |
48 | 128 |
49 bool IsEnhancedBookmarksExperimentEnabled() { | 129 bool IsEnhancedBookmarksExperimentEnabled() { |
50 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 130 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
51 if (command_line->HasSwitch(switches::kManualEnhancedBookmarks) || | 131 if (command_line->HasSwitch(switches::kManualEnhancedBookmarks) || |
52 command_line->HasSwitch(switches::kManualEnhancedBookmarksOptout)) { | 132 command_line->HasSwitch(switches::kManualEnhancedBookmarksOptout)) { |
53 return true; | 133 return true; |
54 } | 134 } |
55 | 135 |
| 136 return IsEnhancedBookmarksExperimentEnabledFromFinch(); |
| 137 } |
| 138 |
| 139 bool IsEnhancedBookmarksExperimentEnabledFromFinch() { |
56 std::string ext_id = GetEnhancedBookmarksExtensionIdFromFinch(); | 140 std::string ext_id = GetEnhancedBookmarksExtensionIdFromFinch(); |
57 extensions::FeatureProvider* feature_provider = | 141 extensions::FeatureProvider* feature_provider = |
58 extensions::FeatureProvider::GetPermissionFeatures(); | 142 extensions::FeatureProvider::GetPermissionFeatures(); |
59 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate"); | 143 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate"); |
60 return feature && feature->IsIdInWhitelist(ext_id); | 144 return feature && feature->IsIdInWhitelist(ext_id); |
61 } | 145 } |
62 | 146 |
63 bool IsEnableDomDistillerSet() { | 147 bool IsEnableDomDistillerSet() { |
64 if (CommandLine::ForCurrentProcess()-> | 148 if (CommandLine::ForCurrentProcess()-> |
65 HasSwitch(switches::kEnableDomDistiller)) { | 149 HasSwitch(switches::kEnableDomDistiller)) { |
(...skipping 14 matching lines...) Expand all Loading... |
80 if (chrome_variations::GetVariationParamValue( | 164 if (chrome_variations::GetVariationParamValue( |
81 kFieldTrialName, "enable-sync-articles") == "1") | 165 kFieldTrialName, "enable-sync-articles") == "1") |
82 return true; | 166 return true; |
83 | 167 |
84 return false; | 168 return false; |
85 } | 169 } |
86 | 170 |
87 std::string GetEnhancedBookmarksExtensionIdFromFinch() { | 171 std::string GetEnhancedBookmarksExtensionIdFromFinch() { |
88 return chrome_variations::GetVariationParamValue(kFieldTrialName, "id"); | 172 return chrome_variations::GetVariationParamValue(kFieldTrialName, "id"); |
89 } | 173 } |
OLD | NEW |