Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: chrome/browser/installable/installable_manager.h

Issue 2641413002: Allow InstallableManager to fetch optional badge icon (Closed)
Patch Set: format Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 5 #ifndef CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 6 #define CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <tuple>
10 #include <utility> 11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
14 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
17 #include "chrome/browser/installable/installable_logging.h" 18 #include "chrome/browser/installable/installable_logging.h"
18 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_contents_user_data.h" 20 #include "content/public/browser/web_contents_user_data.h"
20 #include "content/public/common/manifest.h" 21 #include "content/public/common/manifest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 // This struct specifies the work to be done by the InstallableManager. 25 // This struct specifies the work to be done by the InstallableManager.
25 // Data is cached and fetched in the order specified in this struct. A web app 26 // Data is cached and fetched in the order specified in this struct. A web app
26 // manifest will always be fetched first. 27 // manifest will always be fetched first.
27 struct InstallableParams { 28 struct InstallableParams {
29 // Check whether the site is installable. That is, it has a manifest valid for
30 // a web app and a service worker controlling the manifest start URL and the
31 // current URL.
dominickn 2017/01/27 06:40:43 The bools are last so that this struct will be lai
F 2017/01/27 20:11:17 Done. Thanks for the explanation.
32 bool check_installable = false;
33
28 // The ideal primary icon size to fetch. Used only if 34 // The ideal primary icon size to fetch. Used only if
29 // |fetch_valid_primary_icon| is true. 35 // |fetch_valid_primary_icon| is true.
30 int ideal_primary_icon_size_in_px = -1; 36 int ideal_primary_icon_size_in_px = -1;
31 37
32 // The minimum primary icon size to fetch. Used only if 38 // The minimum primary icon size to fetch. Used only if
33 // |fetch_valid_primary_icon| is true. 39 // |fetch_valid_primary_icon| is true.
34 int minimum_primary_icon_size_in_px = -1; 40 int minimum_primary_icon_size_in_px = -1;
35 41
36 // Check whether the site is installable. That is, it has a manifest valid for
37 // a web app and a service worker controlling the manifest start URL and the
38 // current URL.
39 bool check_installable = false;
40
41 // Check whether there is a fetchable, non-empty icon in the manifest 42 // Check whether there is a fetchable, non-empty icon in the manifest
42 // conforming to the primary icon size parameters. 43 // conforming to the primary icon size parameters.
43 bool fetch_valid_primary_icon = false; 44 bool fetch_valid_primary_icon = false;
45
46 // The ideal badge icon size to fetch. Used only if
47 // |fetch_valid_badge_icon| is true.
48 int ideal_badge_icon_size_in_px = -1;
49
50 // The minimum badge icon size to fetch. Used only if
51 // |fetch_valid_badge_icon| is true.
52 int minimum_badge_icon_size_in_px = -1;
53
54 // Check whether there is a fetchable, non-empty icon in the manifest
55 // conforming to the badge icon size parameters.
56 bool fetch_valid_badge_icon = false;
44 }; 57 };
45 58
46 // This struct is passed to an InstallableCallback when the InstallableManager 59 // This struct is passed to an InstallableCallback when the InstallableManager
47 // has finished working. Each reference is owned by InstallableManager, and 60 // has finished working. Each reference is owned by InstallableManager, and
48 // callers should copy any objects which they wish to use later. Non-requested 61 // callers should copy any objects which they wish to use later. Non-requested
49 // fields will be set to null, empty, or false. 62 // fields will be set to null, empty, or false.
50 struct InstallableData { 63 struct InstallableData {
51 // NO_ERROR_DETECTED if there were no issues. 64 // NO_ERROR_DETECTED if there were no issues.
52 const InstallableStatusCode error_code; 65 const InstallableStatusCode error_code;
53 66
54 // Empty if the site has no <link rel="manifest"> tag. 67 // Empty if the site has no <link rel="manifest"> tag.
55 const GURL& manifest_url; 68 const GURL& manifest_url;
56 69
57 // Empty if the site has an unparseable manifest. 70 // Empty if the site has an unparseable manifest.
58 const content::Manifest& manifest; 71 const content::Manifest& manifest;
59 72
60 // Empty if no primary_icon was requested. 73 // Empty if no primary_icon was requested.
61 const GURL& primary_icon_url; 74 const GURL& primary_icon_url;
62 75
63 // nullptr if the most appropriate primary icon couldn't be determined or 76 // nullptr if the most appropriate primary icon couldn't be determined or
64 // downloaded. The underlying primary icon is owned by the InstallableManager; 77 // downloaded. The underlying primary icon is owned by the InstallableManager;
65 // clients must copy the bitmap if they want to to use it. If 78 // clients must copy the bitmap if they want to to use it. If
66 // fetch_valid_primary_icon was true and a primary icon could not be 79 // fetch_valid_primary_icon was true and a primary icon could not be
67 // retrieved, the reason will be in error_code. 80 // retrieved, the reason will be in error_code.
68 const SkBitmap* primary_icon; 81 const SkBitmap* primary_icon;
69 82
83 // Empty if no badge_icon was requested.
84 const GURL& badge_icon_url;
85
86 // nullptr if the most appropriate badge icon couldn't be determined or
87 // downloaded. The underlying badge icon is owned by the InstallableManager;
88 // clients must copy the bitmap if they want to to use it. If
89 // fetch_valid_badge_icon was true and a badge icon could not be retrieved,
dominickn 2017/01/27 06:40:42 I don't think this comment is accurate - the badge
F 2017/01/27 20:11:17 Done.
90 // the reason will be in error_code.
91 const SkBitmap* badge_icon;
92
70 // true if the site has a service worker and a viable web app manifest. If 93 // true if the site has a service worker and a viable web app manifest. If
71 // check_installable was true and the site isn't installable, the reason will 94 // check_installable was true and the site isn't installable, the reason will
72 // be in error_code. 95 // be in error_code.
73 const bool is_installable; 96 const bool is_installable;
74 }; 97 };
75 98
76 using InstallableCallback = base::Callback<void(const InstallableData&)>; 99 using InstallableCallback = base::Callback<void(const InstallableData&)>;
77 100
78 // This class is responsible for fetching the resources required to check and 101 // This class is responsible for fetching the resources required to check and
79 // install a site. 102 // install a site.
(...skipping 23 matching lines...) Expand all
103 virtual void GetData(const InstallableParams& params, 126 virtual void GetData(const InstallableParams& params,
104 const InstallableCallback& callback); 127 const InstallableCallback& callback);
105 128
106 private: 129 private:
107 friend class InstallableManagerUnitTest; 130 friend class InstallableManagerUnitTest;
108 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, 131 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest,
109 ManagerBeginsInEmptyState); 132 ManagerBeginsInEmptyState);
110 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); 133 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp);
111 134
112 using Task = std::pair<InstallableParams, InstallableCallback>; 135 using Task = std::pair<InstallableParams, InstallableCallback>;
113 using IconParams = std::pair<int, int>; 136 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>;
114 137
115 struct ManifestProperty; 138 struct ManifestProperty;
116 struct InstallableProperty; 139 struct InstallableProperty;
117 struct IconProperty; 140 struct IconProperty;
118 141
119 // Returns the IconProperty matching |params|. Creates if it doesn't exist. 142 // Returns an IconParams object that queries for a primary icon conforming to
120 IconProperty& GetIcon(const InstallableParams& params); 143 // the primary icon size parameters in |params|.
144 IconParams ParamsForPrimaryIcon(const InstallableParams& params) const;
145 // Returns an IconParams object that queries for a badge icon conforming to
146 // the badge icon size parameters in |params|.
147 IconParams ParamsForBadgeIcon(const InstallableParams& params) const;
121 148
122 // Returns true if the icon sizes in |params| matches any fetched icon. false 149 // Returns true if |params| matches any fetched icon, or false if no icon has
123 // if no icon has been requested yet or there is no match. 150 // been requested yet or there is no match.
124 bool IsIconFetched(const InstallableParams& params) const; 151 bool IsIconFetched(const IconParams& params) const;
125 152
126 // Sets the icon parameters in |params| as being fetched. 153 // Sets the icon matching |params| as fetched.
127 void SetIconFetched(const InstallableParams& params); 154 void SetIconFetched(const IconParams& params);
128 155
129 // Returns the error code associated with the resources requested in |params|, 156 // Returns the error code associated with the resources requested in |params|,
130 // or NO_ERROR_DETECTED if there is no error. 157 // or NO_ERROR_DETECTED if there is no error.
131 InstallableStatusCode GetErrorCode(const InstallableParams& params); 158 InstallableStatusCode GetErrorCode(const InstallableParams& params);
132 159
133 // Gets/sets parts of particular properties. Exposed for testing. 160 // Gets/sets parts of particular properties. Exposed for testing.
134 InstallableStatusCode manifest_error() const; 161 InstallableStatusCode manifest_error() const;
135 InstallableStatusCode installable_error() const; 162 InstallableStatusCode installable_error() const;
136 void set_installable_error(InstallableStatusCode error_code); 163 void set_installable_error(InstallableStatusCode error_code);
137 InstallableStatusCode icon_error(const IconParams& icon_params); 164 InstallableStatusCode icon_error(const IconParams& icon_params);
(...skipping 24 matching lines...) Expand all
162 // Data retrieval methods. 189 // Data retrieval methods.
163 void FetchManifest(); 190 void FetchManifest();
164 void OnDidGetManifest(const GURL& manifest_url, 191 void OnDidGetManifest(const GURL& manifest_url,
165 const content::Manifest& manifest); 192 const content::Manifest& manifest);
166 193
167 void CheckInstallable(); 194 void CheckInstallable();
168 bool IsManifestValidForWebApp(const content::Manifest& manifest); 195 bool IsManifestValidForWebApp(const content::Manifest& manifest);
169 void CheckServiceWorker(); 196 void CheckServiceWorker();
170 void OnDidCheckHasServiceWorker(bool has_service_worker); 197 void OnDidCheckHasServiceWorker(bool has_service_worker);
171 198
172 void CheckAndFetchBestIcon(); 199 void CheckAndFetchBestIcon(const IconParams& params);
173 void OnAppIconFetched(const GURL icon_url, const SkBitmap& bitmap); 200 void OnAppIconFetched(
dominickn 2017/01/27 06:40:43 Rename to OnIconFetched.
F 2017/01/27 20:11:17 Done.
201 const GURL icon_url, const IconParams& params, const SkBitmap& bitmap);
174 202
175 // content::WebContentsObserver overrides 203 // content::WebContentsObserver overrides
176 void DidFinishNavigation(content::NavigationHandle* handle) override; 204 void DidFinishNavigation(content::NavigationHandle* handle) override;
177 void WebContentsDestroyed() override; 205 void WebContentsDestroyed() override;
178 206
179 const GURL& manifest_url() const; 207 const GURL& manifest_url() const;
180 const content::Manifest& manifest() const; 208 const content::Manifest& manifest() const;
181 bool is_installable() const; 209 bool is_installable() const;
182 210
183 // The list of <params, callback> pairs that have come from a call to GetData. 211 // The list of <params, callback> pairs that have come from a call to GetData.
184 std::vector<Task> tasks_; 212 std::vector<Task> tasks_;
185 213
186 // Installable properties cached on this object. 214 // Installable properties cached on this object.
187 std::unique_ptr<ManifestProperty> manifest_; 215 std::unique_ptr<ManifestProperty> manifest_;
188 std::unique_ptr<InstallableProperty> installable_; 216 std::unique_ptr<InstallableProperty> installable_;
189 std::map<IconParams, IconProperty> icons_; 217 std::map<IconParams, IconProperty> icons_;
190 218
191 bool is_active_; 219 bool is_active_;
192 220
193 base::WeakPtrFactory<InstallableManager> weak_factory_; 221 base::WeakPtrFactory<InstallableManager> weak_factory_;
194 222
195 DISALLOW_COPY_AND_ASSIGN(InstallableManager); 223 DISALLOW_COPY_AND_ASSIGN(InstallableManager);
196 }; 224 };
197 225
198 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ 226 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/installable/installable_manager.cc » ('j') | chrome/browser/installable/installable_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698