Chromium Code Reviews| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "chrome/browser/installable/installable_logging.h" | 18 #include "chrome/browser/installable/installable_logging.h" |
| 19 #include "chrome/browser/installable/installable_metrics.h" | |
| 19 #include "content/public/browser/service_worker_context.h" | 20 #include "content/public/browser/service_worker_context.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/browser/web_contents_user_data.h" | 22 #include "content/public/browser/web_contents_user_data.h" |
| 22 #include "content/public/common/manifest.h" | 23 #include "content/public/common/manifest.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 // This struct specifies the work to be done by the InstallableManager. | 27 // This struct specifies the work to be done by the InstallableManager. |
| 27 // Data is cached and fetched in the order specified in this struct. A web app | 28 // Data is cached and fetched in the order specified in this struct. A web app |
| 28 // manifest will always be fetched first. | 29 // manifest will always be fetched first. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 // Get the installable data, fetching the resources specified in |params|. | 122 // Get the installable data, fetching the resources specified in |params|. |
| 122 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread | 123 // |callback| is invoked synchronously (i.e. no via PostTask on the UI thread |
| 123 // when the data is ready; the synchronous execution ensures that the | 124 // when the data is ready; the synchronous execution ensures that the |
| 124 // references |callback| receives in its InstallableData argument are valid. | 125 // references |callback| receives in its InstallableData argument are valid. |
| 125 // | 126 // |
| 126 // Calls requesting data that is already fetched will return the cached data. | 127 // Calls requesting data that is already fetched will return the cached data. |
| 127 // This method is marked virtual so clients may mock this object in tests. | 128 // This method is marked virtual so clients may mock this object in tests. |
| 128 virtual void GetData(const InstallableParams& params, | 129 virtual void GetData(const InstallableParams& params, |
| 129 const InstallableCallback& callback); | 130 const InstallableCallback& callback); |
| 130 | 131 |
| 132 // Called via AppBannerManagerAndroid to record metrics on how often the | |
| 133 // installable check is completed when the menu or add to homescreen menu item | |
| 134 // is opened on Android. | |
| 135 void RecordMenuOpenHistogram(); | |
| 136 void RecordMenuItemAddToHomescreenHistogram(); | |
| 137 | |
| 131 private: | 138 private: |
| 139 friend class InstallableManagerBrowserTest; | |
| 132 friend class InstallableManagerUnitTest; | 140 friend class InstallableManagerUnitTest; |
| 133 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, | 141 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, |
| 134 ManagerBeginsInEmptyState); | 142 ManagerBeginsInEmptyState); |
| 135 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); | 143 FRIEND_TEST_ALL_PREFIXES(InstallableManagerBrowserTest, CheckWebapp); |
| 136 | 144 |
| 137 using Task = std::pair<InstallableParams, InstallableCallback>; | 145 using Task = std::pair<InstallableParams, InstallableCallback>; |
| 138 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; | 146 using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; |
| 139 | 147 |
| 140 struct ManifestProperty; | 148 struct ManifestProperty; |
| 141 struct InstallableProperty; | 149 struct InstallableProperty; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 bool is_installable() const; | 219 bool is_installable() const; |
| 212 | 220 |
| 213 // The list of <params, callback> pairs that have come from a call to GetData. | 221 // The list of <params, callback> pairs that have come from a call to GetData. |
| 214 std::vector<Task> tasks_; | 222 std::vector<Task> tasks_; |
| 215 | 223 |
| 216 // Installable properties cached on this object. | 224 // Installable properties cached on this object. |
| 217 std::unique_ptr<ManifestProperty> manifest_; | 225 std::unique_ptr<ManifestProperty> manifest_; |
| 218 std::unique_ptr<InstallableProperty> installable_; | 226 std::unique_ptr<InstallableProperty> installable_; |
| 219 std::map<IconParams, IconProperty> icons_; | 227 std::map<IconParams, IconProperty> icons_; |
| 220 | 228 |
| 229 // A representation of the progress of the PWA check. This is reset per | |
| 230 // navigation and is independent of the caching mechanism, i.e. if a PWA check | |
| 231 // is run multiple times, this will be set on the first run. | |
| 232 InstallableMetrics::InstallabilityCheckStatus status_; | |
|
benwells
2017/03/30 08:22:37
This variable is kinda subtle (e.g. you need to co
dominickn
2017/03/30 23:42:53
Done.
| |
| 233 | |
| 234 // Counts for the number of queued requests of the menu and add to homescreen | |
| 235 // menu item there have been whilst the installable check is awaiting | |
| 236 // completion. Used for metrics recording. | |
| 237 int menu_opened_count_; | |
| 238 int menu_item_add_to_homescreen_count_; | |
| 239 | |
| 221 bool is_active_; | 240 bool is_active_; |
| 222 | 241 |
| 223 base::WeakPtrFactory<InstallableManager> weak_factory_; | 242 base::WeakPtrFactory<InstallableManager> weak_factory_; |
| 224 | 243 |
| 225 DISALLOW_COPY_AND_ASSIGN(InstallableManager); | 244 DISALLOW_COPY_AND_ASSIGN(InstallableManager); |
| 226 }; | 245 }; |
| 227 | 246 |
| 228 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ | 247 #endif // CHROME_BROWSER_INSTALLABLE_INSTALLABLE_MANAGER_H_ |
| OLD | NEW |