1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_
6 #define COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_
12 #include "base/containers/flat_set.h"
13 #include "base/memory/ref_counted_memory.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/image/image.h"
18 namespace favicon_base {
20 struct FallbackIconStyle;
22 typedef int64_t FaviconID;
24 // Defines the icon types.
26 // IMPORTANT: these values must stay in sync with the FaviconType enum in
27 // tools/metrics/histograms/enum.xml.
29 // The values of the IconTypes are used to select the priority in which favicon
30 // data is returned in HistoryBackend and ThumbnailDatabase.
32 // A Java counterpart will be generated for this enum.
33 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.favicon
38 kTouchPrecomposedIcon,
40 kMax = kWebManifestIcon,
44 using IconTypeSet = base::flat_set<IconType>;
46 // Defines a gfx::Image of size desired_size_in_dip composed of image
47 // representations for each of the desired scale factors.
48 struct FaviconImageResult {
50 ~FaviconImageResult();
52 // The resulting image.
55 // The URL of the favicon which contains all of the image representations of
57 // TODO(pkotwicz): Return multiple |icon_urls| to allow |image| to have
58 // representations from several favicons once content::FaviconStatus supports
63 // Defines a favicon bitmap which best matches the desired DIP size and one of
64 // the desired scale factors.
65 struct FaviconRawBitmapResult {
66 FaviconRawBitmapResult();
67 FaviconRawBitmapResult(const FaviconRawBitmapResult& other);
68 ~FaviconRawBitmapResult();
70 // Returns true if |bitmap_data| contains a valid bitmap.
71 bool is_valid() const { return bitmap_data.get() && bitmap_data->size(); }
73 // Indicates whether |bitmap_data| is expired.
76 // The bits of the bitmap.
77 scoped_refptr<base::RefCountedMemory> bitmap_data;
79 // The pixel dimensions of |bitmap_data|.
82 // The URL of the containing favicon.
85 // The icon type of the containing favicon.
88 // Indicates whether the bitmap was fetched upon visiting a page. Value
89 // false means that it was fetched on-demand by the UI of chrome, without
91 bool fetched_because_of_page_visit;
94 // Define type with same structure as FaviconRawBitmapResult for passing data to
95 // HistoryBackend::SetFavicons().
96 typedef FaviconRawBitmapResult FaviconRawBitmapData;
98 // Result returned by LargeIconService::GetLargeIconOrFallbackStyle(). Contains
99 // either the bitmap data if the favicon database has a sufficiently large
100 // favicon bitmap and the style of the fallback icon otherwise.
101 struct LargeIconResult {
102 explicit LargeIconResult(const FaviconRawBitmapResult& bitmap_in);
104 // Takes ownership of |fallback_icon_style_in|.
105 explicit LargeIconResult(FallbackIconStyle* fallback_icon_style_in);
109 // The bitmap from the favicon database if the database has a sufficiently
111 FaviconRawBitmapResult bitmap;
113 // The fallback icon style if a sufficiently large icon isn't available. This
114 // uses the dominant color of a smaller icon as the background if available.
115 std::unique_ptr<FallbackIconStyle> fallback_icon_style;
118 // Result returned by LargeIconService::GetLargeIconImageOrFallbackStyle().
119 // Contains either the gfx::Image if the favicon database has a sufficiently
120 // large favicon bitmap and the style of the fallback icon otherwise.
121 struct LargeIconImageResult {
122 explicit LargeIconImageResult(const gfx::Image& image_in,
123 const GURL& icon_url_in);
125 // Takes ownership of |fallback_icon_style_in|.
126 explicit LargeIconImageResult(FallbackIconStyle* fallback_icon_style_in);
128 ~LargeIconImageResult();
130 // The image from the favicon database if the database has a sufficiently
134 // The URL of the containing favicon. Specified only if |image| is not empty.
137 // The fallback icon style if a sufficiently large icon isn't available. This
138 // uses the dominant color of a smaller icon as the background if available.
139 std::unique_ptr<FallbackIconStyle> fallback_icon_style;
142 // Enumeration listing all possible outcomes for fetch attempts from Google
143 // favicon server. Used for UMA enum GoogleFaviconServerRequestStatus, so do not
144 // change existing values. Insert new values at the end, and update the
145 // histogram definition.
146 enum class GoogleFaviconServerRequestStatus {
147 // Request sent out and the favicon successfully fetched.
149 // Request sent out and a connection error occurred (no valid HTTP response
151 FAILURE_CONNECTION_ERROR = 1,
152 // Request sent out and a HTTP error received.
153 FAILURE_HTTP_ERROR = 2,
154 // Request not sent out (previous HTTP error in cache).
155 FAILURE_HTTP_ERROR_CACHED = 3,
156 // Request sent out and favicon fetched but writing to database failed.
157 FAILURE_ON_WRITE = 4,
158 // Request not sent out (the request or the fetcher was invalid).
159 DEPRECATED_FAILURE_INVALID = 5,
160 // Request not sent out (the target URL was an IP address or its scheme was
162 FAILURE_TARGET_URL_SKIPPED = 6,
163 // Request not sent out (the target URL was not valid).
164 FAILURE_TARGET_URL_INVALID = 7,
165 // Request not sent out (the server URL was not valid).
166 FAILURE_SERVER_URL_INVALID = 8,
167 // Request not sent out (as there already is an icon in the local favicon
168 // database that prevents a new one to be stored).
169 FAILURE_ICON_EXISTS_IN_DB = 9,
170 // Insert new values here.
174 } // namespace favicon_base
176 #endif // COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_