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