summaryrefslogtreecommitdiff
path: root/chromium/components/previews/core/previews_experiments.h
blob: b63c6c625098df706315b18695d11de7a7967728 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2016 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.

#ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_EXPERIMENTS_H_
#define COMPONENTS_PREVIEWS_CORE_PREVIEWS_EXPERIMENTS_H_

#include <string>
#include <utility>
#include <vector>

#include "base/time/time.h"
#include "net/nqe/effective_connection_type.h"

namespace previews {

enum class PreviewsType {
  // Used to indicate that there is no preview type.
  NONE = 0,

  // The user is shown an offline page as a preview.
  OFFLINE = 1,

  // Replace images with placeholders.
  LOFI = 2,

  // The user is shown a server lite page.
  LITE_PAGE = 3,

  // AMP version of the page is shown as a preview. Deprecated, and should not
  // be used.
  DEPRECATED_AMP_REDIRECTION = 4,

  // Preview that disables JavaScript for the navigation.
  NOSCRIPT = 5,

  // Special value that indicates that no specific type is identified. This
  // might be used for checks or logging that applies to any type.
  UNSPECIFIED = 6,

  // Request that resource loading hints be used during pageload.
  RESOURCE_LOADING_HINTS = 7,

  // Insert new enum values here. Keep values sequential to allow looping from
  // NONE+1 to LAST-1. Also add the enum to Previews.Types histogram suffix.
  LAST = 8,
};

typedef std::vector<std::pair<PreviewsType, int>> PreviewsTypeList;

// Gets the string representation of |type|.
std::string GetStringNameForType(PreviewsType type);

namespace params {

// The maximum number of recent previews navigations the black list looks at to
// determine if a host is blacklisted.
size_t MaxStoredHistoryLengthForPerHostBlackList();

// The maximum number of recent previews navigations the black list looks at to
// determine if all previews navigations are disallowed.
size_t MaxStoredHistoryLengthForHostIndifferentBlackList();

// The maximum number of hosts allowed in the in memory black list.
size_t MaxInMemoryHostsInBlackList();

// The number of recent navigations that were opted out of for a given host that
// would trigger that host to be blacklisted.
int PerHostBlackListOptOutThreshold();

// The number of recent navigations that were opted out of that would trigger
// all previews navigations to be disallowed.
int HostIndifferentBlackListOptOutThreshold();

// The amount of time a host remains blacklisted due to opt outs.
base::TimeDelta PerHostBlackListDuration();

// The amount of time all previews navigations are disallowed due to opt outs.
base::TimeDelta HostIndifferentBlackListPerHostDuration();

// The amount of time after any opt out that no previews should be shown.
base::TimeDelta SingleOptOutDuration();

// The amount of time that an offline page is considered fresh enough to be
// shown as a preview.
base::TimeDelta OfflinePreviewFreshnessDuration();

// The threshold of EffectiveConnectionType above which preview |type| will be
// triggered.
net::EffectiveConnectionType GetECTThresholdForPreview(
    previews::PreviewsType type);

// Whether any previews are allowed. Acts as a kill-switch or holdback check.
bool ArePreviewsAllowed();

// Whether the preview type is enabled.
bool IsOfflinePreviewsEnabled();
bool IsClientLoFiEnabled();
bool IsNoScriptPreviewsEnabled();
bool IsResourceLoadingHintsEnabled();

// The blacklist version for each preview type.
int OfflinePreviewsVersion();
int ClientLoFiVersion();
int NoScriptPreviewsVersion();
int ResourceLoadingHintsVersion();

// Whether server optimization hints are enabled.
bool IsOptimizationHintsEnabled();

// The threshold of EffectiveConnectionType above which Client Lo-Fi previews
// should not be served.
net::EffectiveConnectionType EffectiveConnectionTypeThresholdForClientLoFi();

// Returns the hosts that are blacklisted by the Client Lo-Fi field trial.
std::vector<std::string> GetBlackListedHostsForClientLoFiFieldTrial();

// For estimating NoScript data savings, this is the percentage factor to
// multiple by the network bytes for inflating the original_bytes count.
int NoScriptPreviewsInflationPercent();

// For estimating NoScript data savings, this is the number of bytes to
// for inflating the original_bytes count.
int NoScriptPreviewsInflationBytes();

}  // namespace params

}  // namespace previews

#endif  // COMPONENTS_PREVIEWS_CORE_PREVIEWS_EXPERIMENTS_H_