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/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/flags_storage.h" | 14 #include "chrome/browser/flags_storage.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/signin/core/browser/signin_manager.h" | 19 #include "components/signin/core/browser/signin_manager.h" |
| 20 #include "components/sync_driver/pref_names.h" | 20 #include "components/sync_driver/pref_names.h" |
| 21 #include "components/variations/variations_associated_data.h" | 21 #include "components/variations/variations_associated_data.h" |
| 22 #include "extensions/common/features/feature.h" | 22 #include "extensions/common/features/feature.h" |
| 23 #include "extensions/common/features/feature_provider.h" | 23 #include "extensions/common/features/feature_provider.h" |
|
danduong
2015/03/19 18:51:18
can you clean up the includes too?
| |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 26 #include "base/android/build_info.h" | 26 #include "base/android/build_info.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kFieldTrialName[] = "EnhancedBookmarks"; | 31 const char kFieldTrialName[] = "EnhancedBookmarks"; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 bool GetBookmarksExperimentExtensionID(std::string* extension_id) { | 35 bool GetBookmarksExperimentExtensionID(std::string* extension_id) { |
| 36 *extension_id = variations::GetVariationParamValue(kFieldTrialName, "id"); | 36 *extension_id = variations::GetVariationParamValue(kFieldTrialName, "id"); |
| 37 if (extension_id->empty()) | 37 if (extension_id->empty()) |
| 38 return false; | 38 return false; |
| 39 | 39 |
| 40 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". | |
| 41 // "0" - user opted out. | |
| 42 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 43 switches::kEnhancedBookmarksExperiment) == "0"; | |
| 44 | |
| 45 if (opt_out) | |
| 46 return false; | |
| 47 | |
| 48 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
| 49 return base::android::BuildInfo::GetInstance()->sdk_int() > | 41 return true; |
| 50 base::android::SdkVersion::SDK_VERSION_ICE_CREAM_SANDWICH_MR1; | |
| 51 #else | 42 #else |
| 52 const extensions::FeatureProvider* feature_provider = | 43 const extensions::FeatureProvider* feature_provider = |
| 53 extensions::FeatureProvider::GetPermissionFeatures(); | 44 extensions::FeatureProvider::GetPermissionFeatures(); |
| 54 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate"); | 45 extensions::Feature* feature = feature_provider->GetFeature("metricsPrivate"); |
| 55 return feature && feature->IsIdInWhitelist(*extension_id); | 46 return feature && feature->IsIdInWhitelist(*extension_id); |
| 56 #endif | 47 #endif |
| 57 } | 48 } |
| 58 | 49 |
| 59 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
| 60 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) { | 51 bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) { |
| 61 if (IsEnhancedBookmarksEnabled()) | 52 if (IsEnhancedBookmarksEnabled()) |
| 62 return true; | 53 return true; |
| 63 | 54 |
| 64 // Salient images are collected from visited bookmarked pages even if the | 55 // Salient images are collected from visited bookmarked pages even if the |
| 65 // enhanced bookmark feature is turned off. This is to have some images | 56 // enhanced bookmark feature is turned off. This is to have some images |
| 66 // available so that in the future, when the feature is turned on, the user | 57 // available so that in the future, when the feature is turned on, the user |
| 67 // experience is not a big list of flat colors. However as a precautionary | 58 // experience is not a big list of flat colors. However as a precautionary |
| 68 // measure it is possible to disable this collection of images from finch. | 59 // measure it is possible to disable this collection of images from finch. |
| 69 std::string disable_fetching = variations::GetVariationParamValue( | 60 std::string disable_fetching = variations::GetVariationParamValue( |
| 70 kFieldTrialName, "DisableImagesFetching"); | 61 kFieldTrialName, "DisableImagesFetching"); |
| 71 return disable_fetching.empty(); | 62 return disable_fetching.empty(); |
| 72 } | 63 } |
| 73 | 64 |
| 74 bool IsEnhancedBookmarksEnabled() { | 65 bool IsEnhancedBookmarksEnabled() { |
| 75 std::string extension_id; | 66 std::string extension_id; |
| 76 return GetBookmarksExperimentExtensionID(&extension_id); | 67 return IsEnhancedBookmarksEnabled(&extension_id); |
| 77 } | 68 } |
| 78 #endif | 69 #endif |
| 79 | 70 |
| 71 bool IsEnhancedBookmarksEnabled(std::string* extension_id) { | |
| 72 // kEnhancedBookmarksExperiment flag could have values "", "1" and "0". | |
| 73 // "0" - user opted out. | |
| 74 bool opt_out = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 75 switches::kEnhancedBookmarksExperiment) == "0"; | |
| 76 | |
| 77 #if defined(OS_ANDROID) | |
| 78 opt_out |= base::android::BuildInfo::GetInstance()->sdk_int() < | |
| 79 base::android::SdkVersion::SDK_VERSION_ICE_CREAM_SANDWICH_MR1; | |
| 80 | |
| 81 // Android tests use command line flag to force enhanced bookmark to be on. | |
| 82 bool opt_in = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 83 switches::kEnhancedBookmarksExperiment) == "1"; | |
| 84 if (opt_in) | |
| 85 return true; | |
| 86 #endif | |
| 87 | |
| 88 if (opt_out) | |
| 89 return false; | |
| 90 | |
| 91 return GetBookmarksExperimentExtensionID(extension_id); | |
| 92 } | |
| 93 | |
| 80 bool IsEnableDomDistillerSet() { | 94 bool IsEnableDomDistillerSet() { |
| 81 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 95 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 82 switches::kEnableDomDistiller)) { | 96 switches::kEnableDomDistiller)) { |
| 83 return true; | 97 return true; |
| 84 } | 98 } |
| 85 if (variations::GetVariationParamValue( | 99 if (variations::GetVariationParamValue( |
| 86 kFieldTrialName, "enable-dom-distiller") == "1") | 100 kFieldTrialName, "enable-dom-distiller") == "1") |
| 87 return true; | 101 return true; |
| 88 | 102 |
| 89 return false; | 103 return false; |
| 90 } | 104 } |
| 91 | 105 |
| 92 bool IsEnableSyncArticlesSet() { | 106 bool IsEnableSyncArticlesSet() { |
| 93 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 107 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 94 switches::kEnableSyncArticles)) { | 108 switches::kEnableSyncArticles)) { |
| 95 return true; | 109 return true; |
| 96 } | 110 } |
| 97 if (variations::GetVariationParamValue( | 111 if (variations::GetVariationParamValue( |
| 98 kFieldTrialName, "enable-sync-articles") == "1") | 112 kFieldTrialName, "enable-sync-articles") == "1") |
| 99 return true; | 113 return true; |
| 100 | 114 |
| 101 return false; | 115 return false; |
| 102 } | 116 } |
| OLD | NEW |