Chromium Code Reviews| 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 #include "chrome/browser/banners/app_banner_manager.h" | 5 #include "chrome/browser/banners/app_banner_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (IsDebugMode()) { | 297 if (IsDebugMode()) { |
| 298 LogErrorToConsole(web_contents, code, GetStatusParam(code)); | 298 LogErrorToConsole(web_contents, code, GetStatusParam(code)); |
| 299 } else { | 299 } else { |
| 300 // Ensure that we haven't yet logged a status code for this page. | 300 // Ensure that we haven't yet logged a status code for this page. |
| 301 DCHECK(need_to_log_status_); | 301 DCHECK(need_to_log_status_); |
| 302 TrackInstallableStatusCode(code); | 302 TrackInstallableStatusCode(code); |
| 303 need_to_log_status_ = false; | 303 need_to_log_status_ = false; |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 void AppBannerManager::Stop() { | 307 void AppBannerManager::ResetData() { |
| 308 if (was_canceled_by_page_ && !page_requested_prompt_) { | 308 if (was_canceled_by_page_ && !page_requested_prompt_) { |
|
dominickn
2017/02/06 02:16:53
ResetData() should not be recording metrics. It sh
pkotwicz
2017/02/06 03:00:11
Good point
| |
| 309 TrackBeforeInstallEvent( | 309 TrackBeforeInstallEvent( |
| 310 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); | 310 BEFORE_INSTALL_EVENT_PROMPT_NOT_CALLED_AFTER_PREVENT_DEFAULT); |
| 311 ReportStatus(web_contents(), RENDERER_CANCELLED); | 311 ReportStatus(web_contents(), RENDERER_CANCELLED); |
| 312 } | 312 } |
| 313 | 313 |
| 314 active_media_players_.clear(); | |
| 315 manifest_ = content::Manifest(); | |
| 316 manifest_url_ = GURL(); | |
| 317 validated_url_ = GURL(); | |
| 318 referrer_.erase(); | |
| 319 was_canceled_by_page_ = false; | |
| 320 page_requested_prompt_ = false; | |
|
dominickn
2017/02/06 02:16:53
Good catch on these flag variables, but I think pa
pkotwicz
2017/02/06 03:00:11
I will do this in a follow up CL. It is good to ke
| |
| 321 } | |
| 322 | |
| 323 void AppBannerManager::Stop() { | |
| 314 // In every non-debug run through the banner pipeline, we should have called | 324 // In every non-debug run through the banner pipeline, we should have called |
| 315 // ReportStatus() and set need_to_log_status_ to false. The only case where | 325 // ReportStatus() and set need_to_log_status_ to false. The only case where |
| 316 // we don't is if we're still active and waiting for a callback from the | 326 // we don't is if we're still active and waiting for a callback from the |
| 317 // InstallableManager (e.g. the renderer crashes or the browser is shutting | 327 // InstallableManager (e.g. the renderer crashes or the browser is shutting |
| 318 // down). These situations are explicitly not logged. | 328 // down). These situations are explicitly not logged. |
| 319 DCHECK(!need_to_log_status_ || is_active_); | 329 DCHECK(!need_to_log_status_ || is_active_); |
| 320 | 330 |
| 321 weak_factory_.InvalidateWeakPtrs(); | 331 weak_factory_.InvalidateWeakPtrs(); |
| 322 binding_.Close(); | 332 binding_.Close(); |
| 323 controller_.reset(); | 333 controller_.reset(); |
| 324 event_.reset(); | 334 event_.reset(); |
| 325 | 335 |
| 326 is_active_ = false; | 336 is_active_ = false; |
| 327 was_canceled_by_page_ = false; | |
| 328 page_requested_prompt_ = false; | |
| 329 need_to_log_status_ = false; | 337 need_to_log_status_ = false; |
| 330 validated_url_ = GURL(); | |
| 331 referrer_.erase(); | |
| 332 } | 338 } |
| 333 | 339 |
| 334 void AppBannerManager::SendBannerPromptRequest() { | 340 void AppBannerManager::SendBannerPromptRequest() { |
| 335 RecordCouldShowBanner(); | 341 RecordCouldShowBanner(); |
| 336 | 342 |
| 337 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); | 343 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_CREATED); |
| 338 event_request_id_ = ++gCurrentRequestID; | 344 event_request_id_ = ++gCurrentRequestID; |
| 339 | 345 |
| 340 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( | 346 web_contents()->GetMainFrame()->GetRemoteInterfaces()->GetInterface( |
| 341 mojo::MakeRequest(&controller_)); | 347 mojo::MakeRequest(&controller_)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 356 // start. This may be the first navigation, or we may have stopped | 362 // start. This may be the first navigation, or we may have stopped |
| 357 // observing if the banner flow was triggered on the previous page. | 363 // observing if the banner flow was triggered on the previous page. |
| 358 SiteEngagementObserver::Observe(SiteEngagementService::Get( | 364 SiteEngagementObserver::Observe(SiteEngagementService::Get( |
| 359 Profile::FromBrowserContext(web_contents()->GetBrowserContext()))); | 365 Profile::FromBrowserContext(web_contents()->GetBrowserContext()))); |
| 360 } | 366 } |
| 361 } | 367 } |
| 362 | 368 |
| 363 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { | 369 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { |
| 364 if (handle->IsInMainFrame() && handle->HasCommitted() && | 370 if (handle->IsInMainFrame() && handle->HasCommitted() && |
| 365 !handle->IsSamePage()) { | 371 !handle->IsSamePage()) { |
| 366 active_media_players_.clear(); | 372 ResetData(); |
| 367 if (is_active_) | 373 if (is_active_) |
| 368 Stop(); | 374 Stop(); |
| 369 } | 375 } |
| 370 } | 376 } |
| 371 | 377 |
| 372 void AppBannerManager::DidFinishLoad( | 378 void AppBannerManager::DidFinishLoad( |
| 373 content::RenderFrameHost* render_frame_host, | 379 content::RenderFrameHost* render_frame_host, |
| 374 const GURL& validated_url) { | 380 const GURL& validated_url) { |
| 375 // Don't start the banner flow unless the main frame has finished loading. | 381 // Don't start the banner flow unless the main frame has finished loading. |
| 376 if (render_frame_host->GetParent()) | 382 if (render_frame_host->GetParent()) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 537 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 532 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 538 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 533 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 539 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 534 } else { | 540 } else { |
| 535 // Log that the prompt request was made for when we get the prompt reply. | 541 // Log that the prompt request was made for when we get the prompt reply. |
| 536 page_requested_prompt_ = true; | 542 page_requested_prompt_ = true; |
| 537 } | 543 } |
| 538 } | 544 } |
| 539 | 545 |
| 540 } // namespace banners | 546 } // namespace banners |
| OLD | NEW |