-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
types.h
300 lines (259 loc) · 9.83 KB
/
types.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_FEED_CORE_V2_PUBLIC_TYPES_H_
#define COMPONENTS_FEED_CORE_V2_PUBLIC_TYPES_H_
#include <iosfwd>
#include <map>
#include <string>
#include <vector>
#include "base/strings/string_piece.h"
#include "base/time/time.h"
#include "base/types/id_type.h"
#include "base/version.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/version_info/channel.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace feed {
// Information about the user account. Currently, for Feed purposes, we use
// account information only when the user is signed-in with Sync enabled. If
// Sync is disabled, AccountInfo should be empty.
struct AccountInfo {
AccountInfo();
AccountInfo(const std::string& gaia, const std::string& email);
explicit AccountInfo(CoreAccountInfo account_info);
bool operator==(const AccountInfo& rhs) const;
bool operator!=(const AccountInfo& rhs) const { return !(*this == rhs); }
bool IsEmpty() const;
std::string gaia;
std::string email;
};
std::ostream& operator<<(std::ostream& os, const AccountInfo& o);
enum class RefreshTaskId {
kRefreshForYouFeed,
// TODO(1152592): Refresh is not currently used for the Web Feed. Remove
// this code if we don't need it.
kRefreshWebFeed,
};
enum class AccountTokenFetchStatus {
// Token fetch was not attempted, or status is unknown.
kUnspecified = 0,
// Successfully fetch the correct token.
kSuccess = 1,
// The primary account changed before fetching the token completed.
kUnexpectedAccount = 2,
// Timed out while fetching the token.
kTimedOut = 3,
};
// Information about the Chrome build and feature flags.
struct ChromeInfo {
version_info::Channel channel{};
base::Version version;
bool start_surface = false;
};
// Device display metrics.
struct DisplayMetrics {
float density;
uint32_t width_pixels;
uint32_t height_pixels;
};
// A unique ID for an ephemeral change.
using EphemeralChangeId = base::IdTypeU32<class EphemeralChangeIdClass>;
using SurfaceId = base::IdTypeU32<class SurfaceIdClass>;
using ImageFetchId = base::IdTypeU32<class ImageFetchIdClass>;
// A map of trial names (key) and list of group names/IDs (value)
// sent from the server.
typedef std::map<std::string, std::vector<std::string>> Experiments;
struct NetworkResponseInfo {
NetworkResponseInfo();
~NetworkResponseInfo();
NetworkResponseInfo(const NetworkResponseInfo&);
NetworkResponseInfo& operator=(const NetworkResponseInfo&);
// A union of net::Error (if the request failed) and the http
// status code(if the request succeeded in reaching the server).
int32_t status_code = 0;
base::TimeDelta fetch_duration;
base::Time fetch_time;
std::string bless_nonce;
GURL base_request_url;
size_t response_body_bytes = 0;
size_t encoded_size_bytes = 0;
// If it was a signed-in request, this is the associated account info.
AccountInfo account_info;
AccountTokenFetchStatus account_token_fetch_status =
AccountTokenFetchStatus::kUnspecified;
base::TimeTicks fetch_time_ticks;
base::TimeTicks loader_start_time_ticks;
};
std::ostream& operator<<(std::ostream& os, const NetworkResponseInfo& o);
struct NetworkResponse {
// HTTP response body.
std::string response_bytes;
// HTTP status code if available, or net::Error otherwise.
int status_code;
};
// For the snippets-internals page.
struct DebugStreamData {
static const int kVersion = 1; // If a field changes, increment.
DebugStreamData();
~DebugStreamData();
DebugStreamData(const DebugStreamData&);
DebugStreamData& operator=(const DebugStreamData&);
absl::optional<NetworkResponseInfo> fetch_info;
absl::optional<NetworkResponseInfo> upload_info;
std::string load_stream_status;
};
std::string SerializeDebugStreamData(const DebugStreamData& data);
absl::optional<DebugStreamData> DeserializeDebugStreamData(
base::StringPiece base64_encoded);
// Information about a web page which may be used to determine an associated
// web feed.
class WebFeedPageInformation {
public:
WebFeedPageInformation();
~WebFeedPageInformation();
WebFeedPageInformation(const WebFeedPageInformation&);
WebFeedPageInformation(WebFeedPageInformation&&);
WebFeedPageInformation& operator=(const WebFeedPageInformation&);
WebFeedPageInformation& operator=(WebFeedPageInformation&&);
// The URL for the page. `url().has_ref()` is always false.
const GURL& url() const { return url_; }
// The Canonical URL for the page, if one was found. `url().has_ref()` is
// always false
const GURL& canonical_url() const { return canonical_url_; }
// The list of RSS urls embedded in the page with the <link> tag.
const std::vector<GURL>& GetRssUrls() const { return rss_urls_; }
// Set the URL for the page. Trims off the URL ref.
void SetUrl(const GURL& url);
// Set the canonical URL for the page. Trims off the URL ref.
void SetCanonicalUrl(const GURL& url);
void SetRssUrls(const std::vector<GURL>& rss_urls);
private:
GURL url_;
GURL canonical_url_;
std::vector<GURL> rss_urls_;
};
std::ostream& operator<<(std::ostream& os, const WebFeedPageInformation& value);
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed.webfeed
enum class WebFeedSubscriptionStatus {
kUnknown = 0,
kSubscribed = 1,
kNotSubscribed = 2,
kSubscribeInProgress = 3,
kUnsubscribeInProgress = 4,
};
std::ostream& operator<<(std::ostream& out, WebFeedSubscriptionStatus value);
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed.webfeed
enum class WebFeedAvailabilityStatus {
kStateUnspecified = 0,
kInactive = 1,
kActive = 2,
kWaitingForContent = 4,
};
std::ostream& operator<<(std::ostream& out, WebFeedAvailabilityStatus value);
// Information about a web feed.
struct WebFeedMetadata {
WebFeedMetadata();
WebFeedMetadata(const WebFeedMetadata&);
WebFeedMetadata(WebFeedMetadata&&);
~WebFeedMetadata();
WebFeedMetadata& operator=(const WebFeedMetadata&);
WebFeedMetadata& operator=(WebFeedMetadata&&);
// Unique ID of the web feed. Empty if the client knows of no web feed.
std::string web_feed_id;
// Whether the subscribed Web Feed has content available for fetching.
WebFeedAvailabilityStatus availability_status =
WebFeedAvailabilityStatus::kStateUnspecified;
// Whether the Web Feed is recommended by the web feeds service.
bool is_recommended = false;
std::string title;
GURL publisher_url;
WebFeedSubscriptionStatus subscription_status =
WebFeedSubscriptionStatus::kUnknown;
GURL favicon_url;
};
std::ostream& operator<<(std::ostream& out, const WebFeedMetadata& value);
// This must be kept in sync with WebFeedSubscriptionRequestStatus in
// enums.xml. These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed.webfeed
enum class WebFeedSubscriptionRequestStatus {
kUnknown = 0,
kSuccess = 1,
kFailedOffline = 2,
kFailedTooManySubscriptions = 3,
kFailedUnknownError = 4,
kAbortWebFeedSubscriptionPendingClearAll = 5,
kMaxValue = kAbortWebFeedSubscriptionPendingClearAll,
};
std::ostream& operator<<(std::ostream& out,
WebFeedSubscriptionRequestStatus value);
// This must be kept in sync with WebFeedQueryRequestStatus in
// enums.xml. These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed.webfeed
enum class WebFeedQueryRequestStatus {
kUnknown = 0,
kSuccess = 1,
kFailedOffline = 2,
kFailedUnknownError = 3,
kAbortWebFeedQueryPendingClearAll = 4,
kFailedInvalidUrl = 5,
kMaxValue = kFailedInvalidUrl,
};
std::ostream& operator<<(std::ostream& out, WebFeedQueryRequestStatus value);
using NetworkRequestId = base::IdTypeU32<class NetworkRequestIdClass>;
// Values for the UMA
// ContentSuggestions.Feed.WebFeed.PageInformationRequested histogram.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. This must be kept in sync with
// WebFeedPageInformationRequestReason in enums.xml.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed.webfeed
enum class WebFeedPageInformationRequestReason : int {
// The user requested to Follow the current web page.
kUserRequestedFollow = 0,
// A Follow recommendation is being considered the current web page.
kFollowRecommendation = 1,
// The Follow menu item state needs to reflect the current web page.
kMenuItemPresentation = 2,
kMaxValue = kMenuItemPresentation,
};
// Values for feed type
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed
enum class StreamKind : int {
// Stream type is unknown.
kUnknown = 0,
// For you stream.
kForYou = 1,
// Following stream.
kFollowing = 2,
// Single Web Feed (Cormorant) stream.
kSingleWebFeed = 3,
kMaxValue = kSingleWebFeed,
};
// For testing and debugging only.
std::ostream& operator<<(std::ostream& out,
WebFeedPageInformationRequestReason value);
// Used to tell how to open an URL.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed
enum class OpenActionType : int {
// The default open action.
kDefault = 0,
// "Open in new tab" action.
kNewTab = 1,
// "Open in new tab in group" action.
kNewTabInGroup = 2,
};
// Describes how tab group feature is enabled.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.feed
enum class TabGroupEnabledState : int {
// No tab group is enabled.
kNone = 0,
// "Open in new tab in group" replaces "Open in new tab".
kReplaced = 1,
// Both "Open in new tab in group" and "Open in new tab" are shown.
kBoth = 2,
};
} // namespace feed
#endif // COMPONENTS_FEED_CORE_V2_PUBLIC_TYPES_H_