-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
ntp_background_data.h
142 lines (110 loc) · 4.45 KB
/
ntp_background_data.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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SEARCH_BACKGROUND_NTP_BACKGROUND_DATA_H_
#define CHROME_BROWSER_SEARCH_BACKGROUND_NTP_BACKGROUND_DATA_H_
#include <string>
#include "chrome/browser/search/background/ntp_background.pb.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h"
enum class ErrorType {
// Data retrieved successfully.
NONE,
// Network error occurred.
NET_ERROR,
// Response from backend couldn't be read.
SERVICE_ERROR,
};
std::string GetThumbnailImageOptionsForTesting();
// Background images are organized into collections, according to a theme. This
// struct contains the data required to display information about a collection,
// including a representative image. The complete set of CollectionImages must
// be requested separately, by referencing the identifier for this collection.
struct CollectionInfo {
CollectionInfo();
CollectionInfo(const CollectionInfo&);
CollectionInfo(CollectionInfo&&);
~CollectionInfo();
CollectionInfo& operator=(const CollectionInfo&);
CollectionInfo& operator=(CollectionInfo&&);
static CollectionInfo CreateFromProto(
const ntp::background::Collection& collection);
// A unique identifier for the collection.
std::string collection_id;
// A human-readable name for the collection.
std::string collection_name;
// A representative image from the collection.
GURL preview_image_url;
};
bool operator==(const CollectionInfo& lhs, const CollectionInfo& rhs);
bool operator!=(const CollectionInfo& lhs, const CollectionInfo& rhs);
// Represents an image within a collection. The associated collection_id may be
// used to get CollectionInfo.
struct CollectionImage {
CollectionImage();
CollectionImage(const CollectionImage&);
CollectionImage(CollectionImage&&);
~CollectionImage();
CollectionImage& operator=(const CollectionImage&);
CollectionImage& operator=(CollectionImage&&);
// default_image_options are applied to the image.image_url() if options
// (specifying resolution, cropping, etc) are not already present.
static CollectionImage CreateFromProto(
const std::string& collection_id,
const ntp::background::Image& image,
const std::string& default_image_options);
// A unique identifier for the collection the image is in.
std::string collection_id;
// A unique identifier for the image.
uint64_t asset_id;
// The thumbnail image URL, typically lower resolution than the image_url.
GURL thumbnail_image_url;
// The image URL.
GURL image_url;
// The attribution list for the image.
std::vector<std::string> attribution;
// A URL that can be accessed to find out more information about the image.
GURL attribution_action_url;
};
bool operator==(const CollectionImage& lhs, const CollectionImage& rhs);
bool operator!=(const CollectionImage& lhs, const CollectionImage& rhs);
// Represents errors that occur when communicating with the Backdrop service and
// Google Photos.
struct ErrorInfo {
ErrorInfo();
ErrorInfo(const ErrorInfo&);
ErrorInfo(ErrorInfo&&);
~ErrorInfo();
ErrorInfo& operator=(const ErrorInfo&);
ErrorInfo& operator=(ErrorInfo&&);
void ClearError();
// Network error number, listed at chrome://network-errors.
int net_error;
// Category of error that occured.
ErrorType error_type;
};
// Represents a custom background on the new tab page.
struct CustomBackground {
CustomBackground();
CustomBackground(const CustomBackground&);
CustomBackground(CustomBackground&&);
~CustomBackground();
CustomBackground& operator=(const CustomBackground&);
CustomBackground& operator=(CustomBackground&&);
// Url of the custom background selected by the user.
GURL custom_background_url;
// Whether the image is a local resource.
bool is_uploaded_image;
// First attribution string for custom background.
std::string custom_background_attribution_line_1;
// Second attribution string for custom background.
std::string custom_background_attribution_line_2;
// Url to learn more info about the custom background.
GURL custom_background_attribution_action_url;
// Id of the collection being used for "daily refresh".
std::string collection_id;
// Main color of the image.
absl::optional<SkColor> custom_background_main_color;
};
#endif // CHROME_BROWSER_SEARCH_BACKGROUND_NTP_BACKGROUND_DATA_H_