| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/offline_pages/offline_page_feature.h" | 5 #include "components/offline_pages/offline_page_feature.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "base/command_line.h" |  | 
| 10 #include "base/feature_list.h" | 9 #include "base/feature_list.h" | 
| 11 #include "base/metrics/field_trial.h" |  | 
| 12 #include "base/strings/string_util.h" |  | 
| 13 #include "build/build_config.h" |  | 
| 14 #include "components/offline_pages/offline_page_switches.h" |  | 
| 15 #include "components/version_info/version_info.h" |  | 
| 16 | 10 | 
| 17 namespace offline_pages { | 11 namespace offline_pages { | 
| 18 | 12 | 
| 19 namespace { | 13 const base::Feature kOfflineBookmarksFeature { | 
| 20 const char kOfflinePagesFieldTrialName[] = "OfflinePages"; | 14    "OfflineBookmarks", base::FEATURE_DISABLED_BY_DEFAULT | 
| 21 // The old experiment has only one mode to enable offline pages. | 15 }; | 
| 22 const char kEnabledGroupName[] = "Enabled"; |  | 
| 23 // The new experiment supports two modes for offline pages. |  | 
| 24 const char kEnabledAsBookmarksGroupName[] = "EnabledAsBookmarks"; |  | 
| 25 const char kEnabledAsSavedPagesGroupName[] = "EnabledAsSavedPages"; |  | 
| 26 }  // namespace |  | 
| 27 | 16 | 
| 28 const base::Feature kOffliningRecentPagesFeature { | 17 const base::Feature kOffliningRecentPagesFeature { | 
| 29    "offline-recent-pages", base::FEATURE_DISABLED_BY_DEFAULT | 18    "OfflineRecentPages", base::FEATURE_DISABLED_BY_DEFAULT | 
| 30 }; | 19 }; | 
| 31 | 20 | 
| 32 const base::Feature kOfflinePagesBackgroundLoadingFeature { | 21 const base::Feature kOfflinePagesBackgroundLoadingFeature { | 
| 33    "offline-pages-background-loading", base::FEATURE_DISABLED_BY_DEFAULT | 22    "OfflinePagesBackgroundLoading", base::FEATURE_DISABLED_BY_DEFAULT | 
| 34 }; | 23 }; | 
| 35 | 24 | 
| 36 FeatureMode GetOfflinePageFeatureMode() { | 25 bool IsOfflinePagesEnabled() { | 
| 37   // Note: It's important to query the field trial state first, to ensure that | 26   return IsOfflineBookmarksEnabled() || IsOffliningRecentPagesEnabled() || | 
| 38   // UMA reports the correct group. | 27          IsOfflinePagesBackgroundLoadingEnabled(); | 
| 39   std::string group_name = |  | 
| 40       base::FieldTrialList::FindFullName(kOfflinePagesFieldTrialName); |  | 
| 41 |  | 
| 42   // The old experiment 'Enabled' defaults to showing saved page. |  | 
| 43   if (base::CommandLine::ForCurrentProcess()->HasSwitch( |  | 
| 44           switches::kEnableOfflinePages)) { |  | 
| 45     return FeatureMode::ENABLED_AS_SAVED_PAGES; |  | 
| 46   } |  | 
| 47   // The new experiment can control showing either bookmark or saved page. |  | 
| 48   if (base::CommandLine::ForCurrentProcess()->HasSwitch( |  | 
| 49           switches::kEnableOfflinePagesAsBookmarks)) { |  | 
| 50     return FeatureMode::ENABLED_AS_BOOKMARKS; |  | 
| 51   } |  | 
| 52   if (base::CommandLine::ForCurrentProcess()->HasSwitch( |  | 
| 53           switches::kEnableOfflinePagesAsSavedPages)) { |  | 
| 54     return FeatureMode::ENABLED_AS_SAVED_PAGES; |  | 
| 55   } |  | 
| 56   if (base::CommandLine::ForCurrentProcess()->HasSwitch( |  | 
| 57           switches::kDisableOfflinePages)) { |  | 
| 58     return FeatureMode::DISABLED; |  | 
| 59   } |  | 
| 60 |  | 
| 61   // The old experiment 'Enabled' defaults to showing saved page. |  | 
| 62   if (group_name == kEnabledGroupName) |  | 
| 63     return FeatureMode::ENABLED_AS_SAVED_PAGES; |  | 
| 64   // The new experiment can control showing either bookmark or saved page. |  | 
| 65   if (base::StartsWith(group_name, kEnabledAsBookmarksGroupName, |  | 
| 66                        base::CompareCase::SENSITIVE)) { |  | 
| 67     return FeatureMode::ENABLED_AS_BOOKMARKS; |  | 
| 68   } |  | 
| 69   if (base::StartsWith(group_name, kEnabledAsSavedPagesGroupName, |  | 
| 70                        base::CompareCase::SENSITIVE)) { |  | 
| 71     return FeatureMode::ENABLED_AS_SAVED_PAGES; |  | 
| 72   } |  | 
| 73 |  | 
| 74   // Enabled by default on trunk. |  | 
| 75   return version_info::IsOfficialBuild() ? FeatureMode::DISABLED |  | 
| 76                                          : FeatureMode::ENABLED_AS_BOOKMARKS; |  | 
| 77 } | 28 } | 
| 78 | 29 | 
| 79 bool IsOfflinePagesEnabled() { | 30 bool IsOfflineBookmarksEnabled() { | 
| 80   FeatureMode mode = GetOfflinePageFeatureMode(); | 31   return base::FeatureList::IsEnabled(kOfflineBookmarksFeature); | 
| 81   return mode == FeatureMode::ENABLED_AS_BOOKMARKS || |  | 
| 82          mode == FeatureMode::ENABLED_AS_SAVED_PAGES; |  | 
| 83 } | 32 } | 
| 84 | 33 | 
| 85 bool IsOffliningRecentPagesEnabled() { | 34 bool IsOffliningRecentPagesEnabled() { | 
| 86   return  base::FeatureList::IsEnabled(kOffliningRecentPagesFeature) && | 35   return  base::FeatureList::IsEnabled(kOffliningRecentPagesFeature); | 
| 87           IsOfflinePagesEnabled(); |  | 
| 88 } | 36 } | 
| 89 | 37 | 
| 90 bool IsOfflinePagesBackgroundLoadingEnabled() { | 38 bool IsOfflinePagesBackgroundLoadingEnabled() { | 
| 91   return base::FeatureList::IsEnabled(kOfflinePagesBackgroundLoadingFeature) | 39   return base::FeatureList::IsEnabled(kOfflinePagesBackgroundLoadingFeature); | 
| 92       && IsOfflinePagesEnabled(); |  | 
| 93 } | 40 } | 
| 94 | 41 | 
| 95 }  // namespace offline_pages | 42 }  // namespace offline_pages | 
| OLD | NEW | 
|---|