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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 virtual void OnAppIconFetched(const SkBitmap& bitmap) {} | 94 virtual void OnAppIconFetched(const SkBitmap& bitmap) {} |
95 | 95 |
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 |
| 105 // fetched. |
| 106 PENDING_MANIFEST, |
| 107 |
| 108 // The banner pipeline is currently waiting for the installability criteria |
| 109 // to be checked. |
| 110 PENDING_INSTALLABLE_CHECK, |
| 111 |
104 // The banner pipeline has finished running, but is waiting for sufficient | 112 // The banner pipeline has finished running, but is waiting for sufficient |
105 // engagement to trigger the banner. | 113 // engagement to trigger the banner. |
106 PENDING_ENGAGEMENT, | 114 PENDING_ENGAGEMENT, |
107 | 115 |
108 // The banner pipeline has finished running, but is waiting for an event to | 116 // The banner pipeline has finished running, but is waiting for an event to |
109 // trigger the banner. | 117 // trigger the banner. |
110 PENDING_EVENT, | 118 PENDING_EVENT, |
111 | 119 |
112 // The banner pipeline has finished running for this page load and no more | 120 // The banner pipeline has finished running for this page load and no more |
113 // processing is to be done. | 121 // processing is to be done. |
(...skipping 16 matching lines...) Expand all Loading... |
130 virtual std::string GetBannerType(); | 138 virtual std::string GetBannerType(); |
131 | 139 |
132 // Returns a string parameter for a devtools console message corresponding to | 140 // Returns a string parameter for a devtools console message corresponding to |
133 // |code|. Returns the empty string if |code| requires no parameter. | 141 // |code|. Returns the empty string if |code| requires no parameter. |
134 std::string GetStatusParam(InstallableStatusCode code); | 142 std::string GetStatusParam(InstallableStatusCode code); |
135 | 143 |
136 // Returns the ideal and minimum primary icon size requirements. | 144 // Returns the ideal and minimum primary icon size requirements. |
137 virtual int GetIdealPrimaryIconSizeInPx(); | 145 virtual int GetIdealPrimaryIconSizeInPx(); |
138 virtual int GetMinimumPrimaryIconSizeInPx(); | 146 virtual int GetMinimumPrimaryIconSizeInPx(); |
139 | 147 |
140 // Returns true if |is_debug_mode_| is true or the | 148 // Returns true if |triggered_by_devtools_| is true or the |
141 // kBypassAppBannerEngagementChecks flag is set. | 149 // kBypassAppBannerEngagementChecks flag is set. |
142 virtual bool IsDebugMode() const; | 150 virtual bool IsDebugMode() const; |
143 | 151 |
144 // Returns true if the webapp at |start_url| has already been installed. | 152 // Returns true if the webapp at |start_url| has already been installed. |
145 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, | 153 virtual bool IsWebAppInstalled(content::BrowserContext* browser_context, |
146 const GURL& start_url, | 154 const GURL& start_url, |
147 const GURL& manifest_url); | 155 const GURL& manifest_url); |
148 | 156 |
149 // Callback invoked by the InstallableManager once it has fetched the page's | 157 // Callback invoked by the InstallableManager once it has fetched the page's |
150 // manifest. | 158 // manifest. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 void OnEngagementIncreased(content::WebContents* web_contents, | 213 void OnEngagementIncreased(content::WebContents* web_contents, |
206 const GURL& url, | 214 const GURL& url, |
207 double score) override; | 215 double score) override; |
208 | 216 |
209 // Subclass accessors for private fields which should not be changed outside | 217 // Subclass accessors for private fields which should not be changed outside |
210 // this class. | 218 // this class. |
211 InstallableManager* manager() const { return manager_; } | 219 InstallableManager* manager() const { return manager_; } |
212 int event_request_id() const { return event_request_id_; } | 220 int event_request_id() const { return event_request_id_; } |
213 bool is_active() const { return state_ == State::ACTIVE; } | 221 bool is_active() const { return state_ == State::ACTIVE; } |
214 bool is_active_or_pending() const { | 222 bool is_active_or_pending() const { |
215 return state_ == State::ACTIVE || state_ == State::PENDING_ENGAGEMENT || | 223 switch (state_) { |
216 state_ == State::PENDING_EVENT; | 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; |
217 } | 235 } |
218 bool is_complete() const { return state_ == State::COMPLETE; } | 236 bool is_complete() const { return state_ == State::COMPLETE; } |
219 bool is_pending_engagement() const { | 237 bool is_pending_engagement() const { |
220 return state_ == State::PENDING_ENGAGEMENT; | 238 return state_ == State::PENDING_ENGAGEMENT; |
221 } | 239 } |
222 bool is_pending_event() const { | 240 bool is_pending_event() const { |
223 return state_ == State::PENDING_EVENT || page_requested_prompt_; | 241 return state_ == State::PENDING_EVENT || page_requested_prompt_; |
224 } | 242 } |
225 | 243 |
226 // The title to display in the banner. | 244 // The title to display in the banner. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 blink::mojom::AppBannerControllerPtr controller_; | 306 blink::mojom::AppBannerControllerPtr controller_; |
289 | 307 |
290 // If a banner is requested before the page has finished loading, defer | 308 // If a banner is requested before the page has finished loading, defer |
291 // triggering the pipeline until the load is complete. | 309 // triggering the pipeline until the load is complete. |
292 bool has_sufficient_engagement_; | 310 bool has_sufficient_engagement_; |
293 bool load_finished_; | 311 bool load_finished_; |
294 | 312 |
295 // Record whether the page requests for a banner to be shown later on. | 313 // Record whether the page requests for a banner to be shown later on. |
296 bool page_requested_prompt_; | 314 bool page_requested_prompt_; |
297 | 315 |
298 // Whether we should be logging errors to the console for this request. | 316 // Whether the current flow was begun via devtools. |
299 bool is_debug_mode_; | 317 bool triggered_by_devtools_; |
300 | 318 |
301 // Whether the installable status has been logged for this run. | 319 // Whether the installable status has been logged for this run. |
302 bool need_to_log_status_; | 320 bool need_to_log_status_; |
303 | 321 |
304 // The concrete subclasses of this class are expected to have their lifetimes | 322 // The concrete subclasses of this class are expected to have their lifetimes |
305 // scoped to the WebContents which they are observing. This allows us to use | 323 // scoped to the WebContents which they are observing. This allows us to use |
306 // weak pointers for callbacks. | 324 // weak pointers for callbacks. |
307 base::WeakPtrFactory<AppBannerManager> weak_factory_; | 325 base::WeakPtrFactory<AppBannerManager> weak_factory_; |
308 | 326 |
309 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); | 327 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); |
310 }; | 328 }; |
311 | 329 |
312 } // namespace banners | 330 } // namespace banners |
313 | 331 |
314 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ | 332 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ |
OLD | NEW |