| OLD | NEW |
| 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 <tuple> |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread | 130 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread |
| 131 // when the data is ready; the synchronous execution ensures that the | 131 // when the data is ready; the synchronous execution ensures that the |
| 132 // references |callback| receives in its InstallableData argument are valid. | 132 // references |callback| receives in its InstallableData argument are valid. |
| 133 // | 133 // |
| 134 // Clients must be prepared for |callback| to not ever be invoked. For | 134 // Clients must be prepared for |callback| to not ever be invoked. For |
| 135 // instance, if installability checking is requested, this method will wait | 135 // instance, if installability checking is requested, this method will wait |
| 136 // until the site registers a service worker (and hence not invoke |callback| | 136 // until the site registers a service worker (and hence not invoke |callback| |
| 137 // at all if a service worker is never registered). | 137 // at all if a service worker is never registered). |
| 138 // | 138 // |
| 139 // Calls requesting data that is already fetched will return the cached data. | 139 // Calls requesting data that is already fetched will return the cached data. |
| 140 void GetData(const InstallableParams& params, | 140 virtual void GetData(const InstallableParams& params, |
| 141 const InstallableCallback& callback); | 141 const InstallableCallback& callback); |
| 142 | 142 |
| 143 // Called via AppBannerManagerAndroid to record metrics on how often the | 143 // Called via AppBannerManagerAndroid to record metrics on how often the |
| 144 // installable check is completed when the menu or add to homescreen menu item | 144 // installable check is completed when the menu or add to homescreen menu item |
| 145 // is opened on Android. | 145 // is opened on Android. |
| 146 void RecordMenuOpenHistogram(); | 146 void RecordMenuOpenHistogram(); |
| 147 void RecordMenuItemAddToHomescreenHistogram(); | 147 void RecordMenuItemAddToHomescreenHistogram(); |
| 148 void RecordQueuedMetricsOnTaskCompletion(const InstallableParams& params, | 148 void RecordQueuedMetricsOnTaskCompletion(const InstallableParams& params, |
| 149 bool check_passed); | 149 bool check_passed); |
| 150 | 150 |
| 151 protected: | 151 protected: |
| 152 // For mocking in tests. | 152 // For mocking in tests. |
| 153 virtual void OnWaitingForServiceWorker() {} | 153 virtual void OnWaitingForServiceWorker() {} |
| 154 | 154 |
| 155 private: | 155 private: |
| 156 friend class AddToHomescreenDataFetcherTest; |
| 156 friend class InstallableManagerBrowserTest; | 157 friend class InstallableManagerBrowserTest; |
| 157 friend class InstallableManagerUnitTest; | 158 friend class InstallableManagerUnitTest; |
| 159 friend class TestInstallableManager; |
| 158 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, | 160 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, |
| 159 ManagerBeginsInEmptyState); | 161 ManagerBeginsInEmptyState); |
| 160 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); | 162 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); |
| 161 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, | 163 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, |
| 162 CheckLazyServiceWorkerPassesWhenWaiting); | 164 CheckLazyServiceWorkerPassesWhenWaiting); |
| 163 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, | 165 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, |
| 164 CheckLazyServiceWorkerNoFetchHandlerFails); | 166 CheckLazyServiceWorkerNoFetchHandlerFails); |
| 165 | 167 |
| 166 using Task = std::pair<InstallableParams, InstallableCallback>; | 168 using Task = std::pair<InstallableParams, InstallableCallback>; |
| 167 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; | 169 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; |
| 168 | 170 |
| 169 struct ManifestProperty; | 171 struct ManifestProperty { |
| 170 struct ValidManifestProperty; | 172 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 171 struct ServiceWorkerProperty; | 173 GURL url; |
| 172 struct IconProperty; | 174 content::Manifest manifest; |
| 175 bool fetched = false; |
| 176 }; |
| 177 |
| 178 struct ValidManifestProperty { |
| 179 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 180 bool is_valid = false; |
| 181 bool fetched = false; |
| 182 }; |
| 183 |
| 184 struct ServiceWorkerProperty { |
| 185 InstallableStatusCode error = NO_ERROR_DETECTED; |
| 186 bool has_worker = false; |
| 187 bool is_waiting = false; |
| 188 bool fetched = false; |
| 189 }; |
| 190 |
| 191 struct IconProperty { |
| 192 IconProperty(); |
| 193 IconProperty(IconProperty&& other); |
| 194 ~IconProperty(); |
| 195 IconProperty& operator=(IconProperty&& other); |
| 196 |
| 197 InstallableStatusCode error; |
| 198 GURL url; |
| 199 std::unique_ptr<SkBitmap> icon; |
| 200 bool fetched; |
| 201 |
| 202 private: |
| 203 // This class contains a std::unique_ptr and therefore must be move-only. |
| 204 DISALLOW_COPY_AND_ASSIGN(IconProperty); |
| 205 }; |
| 173 | 206 |
| 174 // Returns an IconParams object that queries for a primary icon conforming to | 207 // Returns an IconParams object that queries for a primary icon conforming to |
| 175 // the primary icon size parameters in |params|. | 208 // the primary icon size parameters in |params|. |
| 176 IconParams ParamsForPrimaryIcon(const InstallableParams& params) const; | 209 IconParams ParamsForPrimaryIcon(const InstallableParams& params) const; |
| 177 // Returns an IconParams object that queries for a badge icon conforming to | 210 // Returns an IconParams object that queries for a badge icon conforming to |
| 178 // the badge icon size parameters in |params|. | 211 // the badge icon size parameters in |params|. |
| 179 IconParams ParamsForBadgeIcon(const InstallableParams& params) const; | 212 IconParams ParamsForBadgeIcon(const InstallableParams& params) const; |
| 180 | 213 |
| 181 // Returns true if |params| matches any fetched icon, or false if no icon has | 214 // Returns true if |params| matches any fetched icon, or false if no icon has |
| 182 // been requested yet or there is no match. | 215 // been requested yet or there is no match. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 307 |
| 275 bool is_active_; | 308 bool is_active_; |
| 276 bool is_pwa_check_complete_; | 309 bool is_pwa_check_complete_; |
| 277 | 310 |
| 278 base::WeakPtrFactory<InstallableManager> weak_factory_; | 311 base::WeakPtrFactory<InstallableManager> weak_factory_; |
| 279 | 312 |
| 280 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 313 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
| 281 }; | 314 }; |
| 282 | 315 |
| 283 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 316 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
| OLD | NEW |