Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: components/offline_pages/offline_page_feature.cc

Issue 1899433002: Update flags used by offline pages and bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 IsOfflineBookmarksEnabled() {
37 // Note: It's important to query the field trial state first, to ensure that 26 return base::FeatureList::IsEnabled(kOfflineBookmarksFeature);
38 // UMA reports the correct group.
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 }
78
79 bool IsOfflinePagesEnabled() {
fgorski 2016/04/18 17:09:37 As mentioned above, keep this and make it an aggre
jianli 2016/04/18 21:17:00 Done.
80 FeatureMode mode = GetOfflinePageFeatureMode();
81 return mode == FeatureMode::ENABLED_AS_BOOKMARKS ||
82 mode == FeatureMode::ENABLED_AS_SAVED_PAGES;
83 } 27 }
84 28
85 bool IsOffliningRecentPagesEnabled() { 29 bool IsOffliningRecentPagesEnabled() {
86 return base::FeatureList::IsEnabled(kOffliningRecentPagesFeature) && 30 return base::FeatureList::IsEnabled(kOffliningRecentPagesFeature) &&
87 IsOfflinePagesEnabled(); 31 IsOfflineBookmarksEnabled();
fgorski 2016/04/18 17:09:37 No. These should be independent.
jianli 2016/04/18 21:17:00 Done.
88 } 32 }
89 33
90 bool IsOfflinePagesBackgroundLoadingEnabled() { 34 bool IsOfflinePagesBackgroundLoadingEnabled() {
91 return base::FeatureList::IsEnabled(kOfflinePagesBackgroundLoadingFeature) 35 return base::FeatureList::IsEnabled(kOfflinePagesBackgroundLoadingFeature)
92 && IsOfflinePagesEnabled(); 36 && IsOfflineBookmarksEnabled();
fgorski 2016/04/18 17:09:37 ditto.
jianli 2016/04/18 21:17:00 Done.
93 } 37 }
94 38
95 } // namespace offline_pages 39 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698