Index: chrome/browser/installable/installable_manager.h |
diff --git a/chrome/browser/installable/installable_manager.h b/chrome/browser/installable/installable_manager.h |
index 6f9204374150287a5b6ec8964a87d575f8b8d5e1..fe7492d2141bac6101a5b2b6e2496732bb601833 100644 |
--- a/chrome/browser/installable/installable_manager.h |
+++ b/chrome/browser/installable/installable_manager.h |
@@ -18,6 +18,7 @@ |
#include "chrome/browser/installable/installable_logging.h" |
#include "chrome/browser/installable/installable_metrics.h" |
#include "content/public/browser/service_worker_context.h" |
+#include "content/public/browser/service_worker_context_observer.h" |
#include "content/public/browser/web_contents_observer.h" |
#include "content/public/browser/web_contents_user_data.h" |
#include "content/public/common/manifest.h" |
@@ -49,6 +50,9 @@ struct InstallableParams { |
// current URL. |
bool check_installable = false; |
+ // Whether or not to wait indefinitely for a service worker. |
+ bool wait_for_worker = true; |
+ |
// Check whether there is a fetchable, non-empty icon in the manifest |
// conforming to the primary icon size parameters. |
bool fetch_valid_primary_icon = false; |
@@ -104,7 +108,8 @@ using InstallableCallback = base::Callback<void(const InstallableData&)>; |
// This class is responsible for fetching the resources required to check and |
// install a site. |
class InstallableManager |
- : public content::WebContentsObserver, |
+ : public content::ServiceWorkerContextObserver, |
+ public content::WebContentsObserver, |
public content::WebContentsUserData<InstallableManager> { |
public: |
explicit InstallableManager(content::WebContents* web_contents); |
@@ -124,10 +129,14 @@ class InstallableManager |
// when the data is ready; the synchronous execution ensures that the |
// references |callback| receives in its InstallableData argument are valid. |
// |
+ // Clients must be prepared for |callback| to not ever be invoked. For |
+ // instance, if installability checking is requested, this method will wait |
+ // until the site registers a service worker (and hence not invoke |callback| |
+ // at all if a service worker is never registered). |
+ // |
// Calls requesting data that is already fetched will return the cached data. |
- // This method is marked virtual so clients may mock this object in tests. |
- virtual void GetData(const InstallableParams& params, |
- const InstallableCallback& callback); |
+ void GetData(const InstallableParams& params, |
+ const InstallableCallback& callback); |
// Called via AppBannerManagerAndroid to record metrics on how often the |
// installable check is completed when the menu or add to homescreen menu item |
@@ -148,7 +157,8 @@ class InstallableManager |
using IconParams = std::tuple<int, int, content::Manifest::Icon::IconPurpose>; |
struct ManifestProperty; |
- struct InstallableProperty; |
+ struct ValidManifestProperty; |
+ struct ServiceWorkerProperty; |
struct IconProperty; |
// Returns an IconParams object that queries for a primary icon conforming to |
@@ -171,8 +181,9 @@ class InstallableManager |
// Gets/sets parts of particular properties. Exposed for testing. |
InstallableStatusCode manifest_error() const; |
- InstallableStatusCode installable_error() const; |
- void set_installable_error(InstallableStatusCode error_code); |
+ InstallableStatusCode valid_manifest_error() const; |
+ void set_valid_manifest_error(InstallableStatusCode error_code); |
+ InstallableStatusCode worker_error() const; |
InstallableStatusCode icon_error(const IconParams& icon_params); |
GURL& icon_url(const IconParams& icon_params); |
const SkBitmap* icon(const IconParams& icon); |
@@ -209,8 +220,12 @@ class InstallableManager |
void OnDidCheckHasServiceWorker(content::ServiceWorkerCapability capability); |
void CheckAndFetchBestIcon(const IconParams& params); |
- void OnIconFetched( |
- const GURL icon_url, const IconParams& params, const SkBitmap& bitmap); |
+ void OnIconFetched(const GURL icon_url, |
+ const IconParams& params, |
+ const SkBitmap& bitmap); |
+ |
+ // content::ServiceWorkerContextObserver overrides |
+ void OnRegistrationStored(const GURL& pattern) override; |
// content::WebContentsObserver overrides |
void DidFinishNavigation(content::NavigationHandle* handle) override; |
@@ -225,9 +240,14 @@ class InstallableManager |
// Installable properties cached on this object. |
std::unique_ptr<ManifestProperty> manifest_; |
- std::unique_ptr<InstallableProperty> installable_; |
+ std::unique_ptr<ValidManifestProperty> valid_manifest_; |
+ std::unique_ptr<ServiceWorkerProperty> worker_; |
std::map<IconParams, IconProperty> icons_; |
+ // Owned by the storage partition attached to the content::WebContents which |
+ // this object is scoped to. |
+ content::ServiceWorkerContext* service_worker_context_; |
+ |
// Whether or not the current page is a PWA. This is reset per navigation and |
// is independent of the caching mechanism, i.e. if a PWA check is run |
// multiple times for one page, this will be set on the first check. |