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