forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline_page_feature.cc
76 lines (64 loc) · 2.68 KB
/
offline_page_feature.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_pages/offline_page_feature.h"
#include <string>
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "components/offline_pages/offline_page_switches.h"
#if defined(OS_ANDROID)
namespace offline_pages {
namespace {
const char kOfflinePagesFieldTrialName[] = "OfflinePages";
// The old experiment has only one mode to enable offline pages.
const char kEnabledGroupName[] = "Enabled";
// The new experiment supports two modes for offline pages.
const char kEnabledAsBookmarksGroupName[] = "EnabledAsBookmarks";
const char kEnabledAsSavedPagesGroupName[] = "EnabledAsSavedPages";
} // namespace
FeatureMode GetOfflinePageFeatureMode() {
// Note: It's important to query the field trial state first, to ensure that
// UMA reports the correct group.
std::string group_name =
base::FieldTrialList::FindFullName(kOfflinePagesFieldTrialName);
// The old experiment 'Enabled' defaults to showing saved page.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOfflinePages)) {
return FeatureMode::ENABLED_AS_SAVED_PAGES;
}
// The new experiment can control showing either bookmark or saved page.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOfflinePagesAsBookmarks)) {
return FeatureMode::ENABLED_AS_BOOKMARKS;
}
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableOfflinePagesAsSavedPages)) {
return FeatureMode::ENABLED_AS_SAVED_PAGES;
}
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableOfflinePages)) {
return FeatureMode::DISABLED;
}
// The old experiment 'Enabled' defaults to showing saved page.
if (group_name == kEnabledGroupName)
return FeatureMode::ENABLED_AS_SAVED_PAGES;
// The new experiment can control showing either bookmark or saved page.
if (base::StartsWith(group_name, kEnabledAsBookmarksGroupName,
base::CompareCase::SENSITIVE)) {
return FeatureMode::ENABLED_AS_BOOKMARKS;
}
if (base::StartsWith(group_name, kEnabledAsSavedPagesGroupName,
base::CompareCase::SENSITIVE)) {
return FeatureMode::ENABLED_AS_SAVED_PAGES;
}
return FeatureMode::DISABLED;
}
bool IsOfflinePagesEnabled() {
FeatureMode mode = GetOfflinePageFeatureMode();
return mode == FeatureMode::ENABLED_AS_BOOKMARKS ||
mode == FeatureMode::ENABLED_AS_SAVED_PAGES;
}
} // namespace offline_pages
#endif