| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BANNERS_APP_BANNER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 6 #define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 protected: | 96 protected: |
| 97 enum class State { | 97 enum class State { |
| 98 // The banner pipeline has not yet been triggered for this page load. | 98 // The banner pipeline has not yet been triggered for this page load. |
| 99 INACTIVE, | 99 INACTIVE, |
| 100 | 100 |
| 101 // The banner pipeline is currently running for this page load. | 101 // The banner pipeline is currently running for this page load. |
| 102 ACTIVE, | 102 ACTIVE, |
| 103 | 103 |
| 104 // The banner pipeline is currently waiting for the page manifest to be | 104 // The banner pipeline is currently waiting for the page manifest to be |
| 105 // fetched. | 105 // fetched. |
| 106 PENDING_MANIFEST, | 106 FETCHING_MANIFEST, |
| 107 | 107 |
| 108 // The banner pipeline is currently waiting for the installability criteria | 108 // The banner pipeline is currently waiting for the installability criteria |
| 109 // to be checked. | 109 // to be checked. This could be paused while waiting for the site to |
| 110 // register a service worker. |
| 110 PENDING_INSTALLABLE_CHECK, | 111 PENDING_INSTALLABLE_CHECK, |
| 111 | 112 |
| 112 // The banner pipeline has finished running, but is waiting for sufficient | 113 // The banner pipeline has finished running, but is waiting for sufficient |
| 113 // engagement to trigger the banner. | 114 // engagement to trigger the banner. |
| 114 PENDING_ENGAGEMENT, | 115 PENDING_ENGAGEMENT, |
| 115 | 116 |
| 116 // The banner pipeline has finished running, but is waiting for an event to | 117 // The banner has sent the beforeinstallprompt event and is waiting for the |
| 117 // trigger the banner. | 118 // resposne to the event. |
| 118 PENDING_EVENT, | 119 SENDING_EVENT, |
| 120 |
| 121 // The banner has sent the beforeinstallprompt, and the web page called |
| 122 // prompt on the event while the event was being handled. |
| 123 SENDING_EVENT_GOT_EARLY_PROMPT, |
| 124 |
| 125 // The banner pipeline has finished running, but is waiting for the web page |
| 126 // to call prompt on the event. |
| 127 PENDING_PROMPT, |
| 119 | 128 |
| 120 // The banner pipeline has finished running for this page load and no more | 129 // The banner pipeline has finished running for this page load and no more |
| 121 // processing is to be done. | 130 // processing is to be done. |
| 122 COMPLETE, | 131 COMPLETE, |
| 123 }; | 132 }; |
| 124 | 133 |
| 125 explicit AppBannerManager(content::WebContents* web_contents); | 134 explicit AppBannerManager(content::WebContents* web_contents); |
| 126 ~AppBannerManager() override; | 135 ~AppBannerManager() override; |
| 127 | 136 |
| 128 // Returns true if the banner should be shown. Returns false if the banner has | 137 // Returns true if the banner should be shown. Returns false if the banner has |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 220 |
| 212 // SiteEngagementObserver overrides. | 221 // SiteEngagementObserver overrides. |
| 213 void OnEngagementIncreased(content::WebContents* web_contents, | 222 void OnEngagementIncreased(content::WebContents* web_contents, |
| 214 const GURL& url, | 223 const GURL& url, |
| 215 double score) override; | 224 double score) override; |
| 216 | 225 |
| 217 // Subclass accessors for private fields which should not be changed outside | 226 // Subclass accessors for private fields which should not be changed outside |
| 218 // this class. | 227 // this class. |
| 219 InstallableManager* manager() const { return manager_; } | 228 InstallableManager* manager() const { return manager_; } |
| 220 int event_request_id() const { return event_request_id_; } | 229 int event_request_id() const { return event_request_id_; } |
| 230 bool is_inactive() const { return state_ == State::INACTIVE; } |
| 221 bool is_active() const { return state_ == State::ACTIVE; } | 231 bool is_active() const { return state_ == State::ACTIVE; } |
| 222 bool is_active_or_pending() const { | |
| 223 switch (state_) { | |
| 224 case State::ACTIVE: | |
| 225 case State::PENDING_MANIFEST: | |
| 226 case State::PENDING_INSTALLABLE_CHECK: | |
| 227 case State::PENDING_ENGAGEMENT: | |
| 228 case State::PENDING_EVENT: | |
| 229 return true; | |
| 230 case State::INACTIVE: | |
| 231 case State::COMPLETE: | |
| 232 return false; | |
| 233 } | |
| 234 return false; | |
| 235 } | |
| 236 bool is_complete() const { return state_ == State::COMPLETE; } | 232 bool is_complete() const { return state_ == State::COMPLETE; } |
| 237 bool is_pending_engagement() const { | 233 bool is_pending_engagement() const { |
| 238 return state_ == State::PENDING_ENGAGEMENT; | 234 return state_ == State::PENDING_ENGAGEMENT; |
| 239 } | 235 } |
| 240 bool is_pending_event() const { | |
| 241 return state_ == State::PENDING_EVENT || page_requested_prompt_; | |
| 242 } | |
| 243 | 236 |
| 244 // The title to display in the banner. | 237 // The title to display in the banner. |
| 245 base::string16 app_title_; | 238 base::string16 app_title_; |
| 246 | 239 |
| 247 // The URL for which the banner check is being conducted. | 240 // The URL for which the banner check is being conducted. |
| 248 GURL validated_url_; | 241 GURL validated_url_; |
| 249 | 242 |
| 250 // The URL of the manifest. | 243 // The URL of the manifest. |
| 251 GURL manifest_url_; | 244 GURL manifest_url_; |
| 252 | 245 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 // Mojo bindings and interface pointers. | 296 // Mojo bindings and interface pointers. |
| 304 mojo::Binding<blink::mojom::AppBannerService> binding_; | 297 mojo::Binding<blink::mojom::AppBannerService> binding_; |
| 305 blink::mojom::AppBannerEventPtr event_; | 298 blink::mojom::AppBannerEventPtr event_; |
| 306 blink::mojom::AppBannerControllerPtr controller_; | 299 blink::mojom::AppBannerControllerPtr controller_; |
| 307 | 300 |
| 308 // If a banner is requested before the page has finished loading, defer | 301 // If a banner is requested before the page has finished loading, defer |
| 309 // triggering the pipeline until the load is complete. | 302 // triggering the pipeline until the load is complete. |
| 310 bool has_sufficient_engagement_; | 303 bool has_sufficient_engagement_; |
| 311 bool load_finished_; | 304 bool load_finished_; |
| 312 | 305 |
| 313 // Record whether the page requests for a banner to be shown later on. | |
| 314 bool page_requested_prompt_; | |
| 315 | |
| 316 // Whether the current flow was begun via devtools. | 306 // Whether the current flow was begun via devtools. |
| 317 bool triggered_by_devtools_; | 307 bool triggered_by_devtools_; |
| 318 | 308 |
| 319 // Whether the installable status has been logged for this run. | 309 // Whether the installable status has been logged for this run. |
| 320 bool need_to_log_status_; | 310 bool need_to_log_status_; |
| 321 | 311 |
| 322 // The concrete subclasses of this class are expected to have their lifetimes | 312 // The concrete subclasses of this class are expected to have their lifetimes |
| 323 // scoped to the WebContents which they are observing. This allows us to use | 313 // scoped to the WebContents which they are observing. This allows us to use |
| 324 // weak pointers for callbacks. | 314 // weak pointers for callbacks. |
| 325 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 315 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
| 326 | 316 |
| 327 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 317 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
| 328 }; | 318 }; |
| 329 | 319 |
| 330 } // namespace banners | 320 } // namespace banners |
| 331 | 321 |
| 332 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 322 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
| OLD | NEW |