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

Side by Side Diff: chrome/browser/banners/app_banner_manager.h

Issue 2957063002: Update app banner state machine to use more states. (Closed)
Patch Set: Rebase Created 3 years, 5 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 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 protected: 94 protected:
95 enum class State { 95 enum class State {
96 // The banner pipeline has not yet been triggered for this page load. 96 // The banner pipeline has not yet been triggered for this page load.
97 INACTIVE, 97 INACTIVE,
98 98
99 // The banner pipeline is currently running for this page load. 99 // The banner pipeline is currently running for this page load.
100 ACTIVE, 100 ACTIVE,
101 101
102 // The banner pipeline is currently waiting for the page manifest to be 102 // The banner pipeline is currently waiting for the page manifest to be
103 // fetched. 103 // fetched.
104 PENDING_MANIFEST, 104 FETCHING_MANIFEST,
105 105
106 // The banner pipeline is currently waiting for the installability criteria 106 // The banner pipeline is currently waiting for the installability criteria
107 // to be checked. 107 // to be checked. In this state the pipeline could be paused while waiting
108 // for the site to register a service worker.
108 PENDING_INSTALLABLE_CHECK, 109 PENDING_INSTALLABLE_CHECK,
109 110
110 // The banner pipeline has finished running, but is waiting for sufficient 111 // The banner pipeline has finished running, but is waiting for sufficient
111 // engagement to trigger the banner. 112 // engagement to trigger the banner.
112 PENDING_ENGAGEMENT, 113 PENDING_ENGAGEMENT,
113 114
114 // The banner pipeline has finished running, but is waiting for an event to 115 // The banner has sent the beforeinstallprompt event and is waiting for the
115 // trigger the banner. 116 // response to the event.
116 PENDING_EVENT, 117 SENDING_EVENT,
118
119 // The banner has sent the beforeinstallprompt, and the web page called
120 // prompt on the event while the event was being handled.
121 SENDING_EVENT_GOT_EARLY_PROMPT,
122
123 // The banner pipeline has finished running, but is waiting for the web page
124 // to call prompt on the event.
125 PENDING_PROMPT,
117 126
118 // The banner pipeline has finished running for this page load and no more 127 // The banner pipeline has finished running for this page load and no more
119 // processing is to be done. 128 // processing is to be done.
120 COMPLETE, 129 COMPLETE,
121 }; 130 };
122 131
123 explicit AppBannerManager(content::WebContents* web_contents); 132 explicit AppBannerManager(content::WebContents* web_contents);
124 ~AppBannerManager() override; 133 ~AppBannerManager() override;
125 134
126 // Returns true if the banner should be shown. Returns false if the banner has 135 // Returns true if the banner should be shown. Returns false if the banner has
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void WebContentsDestroyed() override; 217 void WebContentsDestroyed() override;
209 218
210 // SiteEngagementObserver overrides. 219 // SiteEngagementObserver overrides.
211 void OnEngagementIncreased(content::WebContents* web_contents, 220 void OnEngagementIncreased(content::WebContents* web_contents,
212 const GURL& url, 221 const GURL& url,
213 double score) override; 222 double score) override;
214 223
215 // Subclass accessors for private fields which should not be changed outside 224 // Subclass accessors for private fields which should not be changed outside
216 // this class. 225 // this class.
217 InstallableManager* manager() const { return manager_; } 226 InstallableManager* manager() const { return manager_; }
218 bool is_active() const { return state_ == State::ACTIVE; } 227 bool is_inactive() const { return state_ == State::INACTIVE; }
219 bool is_active_or_pending() const {
220 switch (state_) {
221 case State::ACTIVE:
222 case State::PENDING_MANIFEST:
223 case State::PENDING_INSTALLABLE_CHECK:
224 case State::PENDING_ENGAGEMENT:
225 case State::PENDING_EVENT:
226 return true;
227 case State::INACTIVE:
228 case State::COMPLETE:
229 return false;
230 }
231 return false;
232 }
233 bool is_complete() const { return state_ == State::COMPLETE; } 228 bool is_complete() const { return state_ == State::COMPLETE; }
234 bool is_pending_engagement() const { 229 bool is_pending_engagement() const {
235 return state_ == State::PENDING_ENGAGEMENT; 230 return state_ == State::PENDING_ENGAGEMENT;
236 } 231 }
237 bool is_pending_event() const { 232 bool IsRunning() const;
238 return state_ == State::PENDING_EVENT || page_requested_prompt_; 233 bool IsBlockedOnNetwork() const;
dominickn 2017/07/07 06:23:18 Can we call this IsWaitingForData()? We could be b
benwells 2017/07/07 06:29:27 Done.
239 }
240 234
241 // The URL for which the banner check is being conducted. 235 // The URL for which the banner check is being conducted.
242 GURL validated_url_; 236 GURL validated_url_;
243 237
244 // The URL of the manifest. 238 // The URL of the manifest.
245 GURL manifest_url_; 239 GURL manifest_url_;
246 240
247 // The manifest object. 241 // The manifest object.
248 content::Manifest manifest_; 242 content::Manifest manifest_;
249 243
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Mojo bindings and interface pointers. 290 // Mojo bindings and interface pointers.
297 mojo::Binding<blink::mojom::AppBannerService> binding_; 291 mojo::Binding<blink::mojom::AppBannerService> binding_;
298 blink::mojom::AppBannerEventPtr event_; 292 blink::mojom::AppBannerEventPtr event_;
299 blink::mojom::AppBannerControllerPtr controller_; 293 blink::mojom::AppBannerControllerPtr controller_;
300 294
301 // If a banner is requested before the page has finished loading, defer 295 // If a banner is requested before the page has finished loading, defer
302 // triggering the pipeline until the load is complete. 296 // triggering the pipeline until the load is complete.
303 bool has_sufficient_engagement_; 297 bool has_sufficient_engagement_;
304 bool load_finished_; 298 bool load_finished_;
305 299
306 // Record whether the page requests for a banner to be shown later on.
307 bool page_requested_prompt_;
308
309 // Whether the current flow was begun via devtools. 300 // Whether the current flow was begun via devtools.
310 bool triggered_by_devtools_; 301 bool triggered_by_devtools_;
311 302
312 // Whether the installable status has been logged for this run. 303 // Whether the installable status has been logged for this run.
313 bool need_to_log_status_; 304 bool need_to_log_status_;
314 305
315 // The concrete subclasses of this class are expected to have their lifetimes 306 // The concrete subclasses of this class are expected to have their lifetimes
316 // scoped to the WebContents which they are observing. This allows us to use 307 // scoped to the WebContents which they are observing. This allows us to use
317 // weak pointers for callbacks. 308 // weak pointers for callbacks.
318 base::WeakPtrFactory<AppBannerManager> weak_factory_; 309 base::WeakPtrFactory<AppBannerManager> weak_factory_;
319 310
320 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); 311 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
321 }; 312 };
322 313
323 } // namespace banners 314 } // namespace banners
324 315
325 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ 316 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698