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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 return base::Time::Now() + | 64 return base::Time::Now() + |
| 65 base::TimeDelta::FromDays(gTimeDeltaInDaysForTesting); | 65 base::TimeDelta::FromDays(gTimeDeltaInDaysForTesting); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // static | 68 // static |
| 69 void AppBannerManager::SetTimeDeltaForTesting(int days) { | 69 void AppBannerManager::SetTimeDeltaForTesting(int days) { |
| 70 gTimeDeltaInDaysForTesting = days; | 70 gTimeDeltaInDaysForTesting = days; |
| 71 } | 71 } |
| 72 | 72 |
| 73 // static | 73 // static |
| 74 void AppBannerManager::SetEngagementWeights(double direct_engagement, | 74 void AppBannerManager::SetTotalEngagementToTrigger(double engagement) { |
| 75 double indirect_engagement) { | 75 AppBannerSettingsHelper::SetTotalEngagementToTrigger(engagement); |
| 76 AppBannerSettingsHelper::SetEngagementWeights(direct_engagement, | |
| 77 indirect_engagement); | |
| 78 } | 76 } |
| 79 | 77 |
| 80 // static | 78 // static |
| 81 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, | 79 bool AppBannerManager::URLsAreForTheSamePage(const GURL& first, |
| 82 const GURL& second) { | 80 const GURL& second) { |
| 83 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && | 81 return first.GetWithEmptyPath() == second.GetWithEmptyPath() && |
| 84 first.path_piece() == second.path_piece() && | 82 first.path_piece() == second.path_piece() && |
| 85 first.query_piece() == second.query_piece(); | 83 first.query_piece() == second.query_piece(); |
| 86 } | 84 } |
| 87 | 85 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 binding_.CreateInterfacePtrAndBind(), mojo::GetProxy(&event_), | 353 binding_.CreateInterfacePtrAndBind(), mojo::GetProxy(&event_), |
| 356 {GetBannerType()}, | 354 {GetBannerType()}, |
| 357 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); | 355 base::Bind(&AppBannerManager::OnBannerPromptReply, GetWeakPtr())); |
| 358 } | 356 } |
| 359 | 357 |
| 360 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { | 358 void AppBannerManager::DidStartNavigation(content::NavigationHandle* handle) { |
| 361 if (!handle->IsInMainFrame() || handle->IsSamePage()) | 359 if (!handle->IsInMainFrame() || handle->IsSamePage()) |
| 362 return; | 360 return; |
| 363 | 361 |
| 364 load_finished_ = false; | 362 load_finished_ = false; |
| 365 if (AppBannerSettingsHelper::ShouldUseSiteEngagementScore() && | 363 if (GetSiteEngagementService() == nullptr) { |
| 366 GetSiteEngagementService() == nullptr) { | |
| 367 // Ensure that we are observing the site engagement service on navigation | 364 // Ensure that we are observing the site engagement service on navigation |
| 368 // start. This may be the first navigation, or we may have stopped | 365 // start. This may be the first navigation, or we may have stopped |
| 369 // observing if the banner flow was triggered on the previous page. | 366 // observing if the banner flow was triggered on the previous page. |
| 370 SiteEngagementObserver::Observe(SiteEngagementService::Get( | 367 SiteEngagementObserver::Observe(SiteEngagementService::Get( |
| 371 Profile::FromBrowserContext(web_contents()->GetBrowserContext()))); | 368 Profile::FromBrowserContext(web_contents()->GetBrowserContext()))); |
| 372 } | 369 } |
| 373 } | 370 } |
| 374 | 371 |
| 375 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { | 372 void AppBannerManager::DidFinishNavigation(content::NavigationHandle* handle) { |
| 376 if (handle->IsInMainFrame() && handle->HasCommitted() && | 373 if (handle->IsInMainFrame() && handle->HasCommitted() && |
| 377 !handle->IsSamePage()) { | 374 !handle->IsSamePage()) { |
| 378 last_transition_type_ = handle->GetPageTransition(); | 375 last_transition_type_ = handle->GetPageTransition(); |
|
pkotwicz
2016/12/07 14:48:15
Drive by: It looks like |last_transition_type_| ca
dominickn
2016/12/08 02:41:50
Nice catch, done.
| |
| 379 active_media_players_.clear(); | 376 active_media_players_.clear(); |
| 380 if (is_active_) | 377 if (is_active_) |
| 381 Stop(); | 378 Stop(); |
| 382 } | 379 } |
| 383 } | 380 } |
| 384 | 381 |
| 385 void AppBannerManager::DidFinishLoad( | 382 void AppBannerManager::DidFinishLoad( |
| 386 content::RenderFrameHost* render_frame_host, | 383 content::RenderFrameHost* render_frame_host, |
| 387 const GURL& validated_url) { | 384 const GURL& validated_url) { |
| 388 // Don't start the banner flow unless the main frame has finished loading. | 385 // Don't start the banner flow unless the main frame has finished loading. |
| 389 if (render_frame_host->GetParent()) | 386 if (render_frame_host->GetParent()) |
| 390 return; | 387 return; |
| 391 | 388 |
| 392 load_finished_ = true; | 389 load_finished_ = true; |
| 393 validated_url_ = validated_url; | 390 validated_url_ = validated_url; |
| 394 // Start the pipeline immediately if we aren't using engagement, or if 0 | 391 // Start the pipeline immediately if 0 engagement is required or if we've |
| 395 // engagement is required. | 392 // queued a banner request. |
| 396 if (!AppBannerSettingsHelper::ShouldUseSiteEngagementScore() || | 393 if (banner_request_queued_ || |
| 397 banner_request_queued_ || | |
| 398 AppBannerSettingsHelper::HasSufficientEngagement(0)) { | 394 AppBannerSettingsHelper::HasSufficientEngagement(0)) { |
| 399 SiteEngagementObserver::Observe(nullptr); | 395 SiteEngagementObserver::Observe(nullptr); |
| 400 banner_request_queued_ = false; | 396 banner_request_queued_ = false; |
| 401 | 397 |
| 402 RequestAppBanner(validated_url, false /* is_debug_mode */); | 398 RequestAppBanner(validated_url, false /* is_debug_mode */); |
| 403 } | 399 } |
| 404 } | 400 } |
| 405 | 401 |
| 406 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info, | 402 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info, |
| 407 const MediaPlayerId& id) { | 403 const MediaPlayerId& id) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 // be safe to start this in response to user input. | 436 // be safe to start this in response to user input. |
| 441 RequestAppBanner(url, false /* is_debug_mode */); | 437 RequestAppBanner(url, false /* is_debug_mode */); |
| 442 } | 438 } |
| 443 } | 439 } |
| 444 } | 440 } |
| 445 | 441 |
| 446 void AppBannerManager::RecordCouldShowBanner() { | 442 void AppBannerManager::RecordCouldShowBanner() { |
| 447 content::WebContents* contents = web_contents(); | 443 content::WebContents* contents = web_contents(); |
| 448 DCHECK(contents); | 444 DCHECK(contents); |
| 449 | 445 |
| 450 AppBannerSettingsHelper::RecordBannerCouldShowEvent( | 446 AppBannerSettingsHelper::RecordBannerEvent( |
| 451 contents, validated_url_, GetAppIdentifier(), | 447 contents, validated_url_, GetAppIdentifier(), |
| 452 GetCurrentTime(), last_transition_type_); | 448 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); |
| 453 } | 449 } |
| 454 | 450 |
| 455 bool AppBannerManager::CheckIfShouldShowBanner() { | 451 bool AppBannerManager::CheckIfShouldShowBanner() { |
| 456 content::WebContents* contents = web_contents(); | 452 content::WebContents* contents = web_contents(); |
| 457 DCHECK(contents); | 453 DCHECK(contents); |
| 458 | 454 |
| 459 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( | 455 InstallableStatusCode code = AppBannerSettingsHelper::ShouldShowBanner( |
| 460 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); | 456 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); |
| 461 if (code == NO_ERROR_DETECTED) | 457 if (code == NO_ERROR_DETECTED) |
| 462 return true; | 458 return true; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. | 535 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. |
| 540 // Don't reset |was_canceled_by_page_| yet for metrics purposes. | 536 // Don't reset |was_canceled_by_page_| yet for metrics purposes. |
| 541 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); | 537 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); |
| 542 } else { | 538 } else { |
| 543 // Log that the prompt request was made for when we get the prompt reply. | 539 // Log that the prompt request was made for when we get the prompt reply. |
| 544 page_requested_prompt_ = true; | 540 page_requested_prompt_ = true; |
| 545 } | 541 } |
| 546 } | 542 } |
| 547 | 543 |
| 548 } // namespace banners | 544 } // namespace banners |
| OLD | NEW |