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

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

Issue 2951763003: Implement experimental app banner flow.
Patch Set: Browser test compile Created 3 years, 6 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 #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/command_line.h" 10 #include "base/command_line.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 load_finished_ = true; 398 load_finished_ = true;
399 validated_url_ = validated_url; 399 validated_url_ = validated_url;
400 400
401 // If the bypass flag is on, or if we require no engagement to trigger the 401 // If the bypass flag is on, or if we require no engagement to trigger the
402 // banner, the rest of the banner pipeline should operate as if the engagement 402 // banner, the rest of the banner pipeline should operate as if the engagement
403 // threshold has been met. 403 // threshold has been met.
404 if (AppBannerSettingsHelper::HasSufficientEngagement(0)) 404 if (AppBannerSettingsHelper::HasSufficientEngagement(0))
405 has_sufficient_engagement_ = true; 405 has_sufficient_engagement_ = true;
406 406
407 // Start the pipeline immediately if we pass (or bypass) the engagement check, 407 // Start the pipeline immediately if we pass (or bypass) the engagement check,
408 // or if the feature to run the installability check on page load is enabled. 408 // or if the feature to run the installability check on page load is enabled,
409 // or if the experimental banner flow is enabled.
409 if (has_sufficient_engagement_ || 410 if (has_sufficient_engagement_ ||
410 base::FeatureList::IsEnabled( 411 base::FeatureList::IsEnabled(
411 features::kCheckInstallabilityForBannerOnLoad)) { 412 features::kCheckInstallabilityForBannerOnLoad) ||
413 IsExperimentalAppBannersEnabled()) {
412 RequestAppBanner(validated_url, false /* is_debug_mode */); 414 RequestAppBanner(validated_url, false /* is_debug_mode */);
413 } 415 }
414 } 416 }
415 417
416 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info, 418 void AppBannerManager::MediaStartedPlaying(const MediaPlayerInfo& media_info,
417 const MediaPlayerId& id) { 419 const MediaPlayerId& id) {
418 active_media_players_.push_back(id); 420 active_media_players_.push_back(id);
419 } 421 }
420 422
421 void AppBannerManager::MediaStoppedPlaying(const MediaPlayerInfo& media_info, 423 void AppBannerManager::MediaStoppedPlaying(const MediaPlayerInfo& media_info,
(...skipping 30 matching lines...) Expand all
452 UpdateState(State::ACTIVE); 454 UpdateState(State::ACTIVE);
453 SendBannerPromptRequest(); 455 SendBannerPromptRequest();
454 } else if (load_finished_) { 456 } else if (load_finished_) {
455 // This performs some simple tests and starts async checks to test 457 // This performs some simple tests and starts async checks to test
456 // installability. It should be safe to start in response to user input. 458 // installability. It should be safe to start in response to user input.
457 RequestAppBanner(url, false /* is_debug_mode */); 459 RequestAppBanner(url, false /* is_debug_mode */);
458 } 460 }
459 } 461 }
460 } 462 }
461 463
464 // static
465 bool AppBannerManager::IsExperimentalAppBannersEnabled() {
466 return base::FeatureList::IsEnabled(features::kExperimentalAppBanners);
467 }
468
462 void AppBannerManager::RecordCouldShowBanner() { 469 void AppBannerManager::RecordCouldShowBanner() {
463 content::WebContents* contents = web_contents(); 470 content::WebContents* contents = web_contents();
464 DCHECK(contents); 471 DCHECK(contents);
465 472
466 AppBannerSettingsHelper::RecordBannerEvent( 473 AppBannerSettingsHelper::RecordBannerEvent(
467 contents, validated_url_, GetAppIdentifier(), 474 contents, validated_url_, GetAppIdentifier(),
468 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime()); 475 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, GetCurrentTime());
469 } 476 }
470 477
471 bool AppBannerManager::CheckIfShouldShowBanner() { 478 bool AppBannerManager::CheckIfShouldShowBanner() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 514 }
508 return true; 515 return true;
509 } 516 }
510 517
511 void AppBannerManager::OnBannerPromptReply( 518 void AppBannerManager::OnBannerPromptReply(
512 blink::mojom::AppBannerPromptReply reply, 519 blink::mojom::AppBannerPromptReply reply,
513 const std::string& referrer) { 520 const std::string& referrer) {
514 // We don't need the controller any more, so reset it so the Blink-side object 521 // We don't need the controller any more, so reset it so the Blink-side object
515 // is destroyed. 522 // is destroyed.
516 controller_.reset(); 523 controller_.reset();
517 content::WebContents* contents = web_contents();
518 524
519 // The renderer might have requested the prompt to be canceled. They may 525 // The renderer might have requested the prompt to be canceled. They may
520 // request that it is redisplayed later, so don't Stop() here. However, log 526 // request that it is redisplayed later, so don't Stop() here. However, log
521 // that the cancelation was requested, so Stop() can be called if a redisplay 527 // that the cancelation was requested, so Stop() can be called if a redisplay
522 // isn't asked for. 528 // isn't asked for.
523 // 529 //
524 // We use the additional page_requested_prompt_ variable because the redisplay 530 // We use the additional page_requested_prompt_ variable because the redisplay
525 // request may be received *before* the Cancel prompt reply (e.g. if redisplay 531 // request may be received *before* the Cancel prompt reply (e.g. if redisplay
526 // is requested in the beforeinstallprompt event handler). 532 // is requested in the beforeinstallprompt event handler).
527 referrer_ = referrer; 533 referrer_ = referrer;
528 if (reply == blink::mojom::AppBannerPromptReply::CANCEL) { 534 if (IsExperimentalAppBannersEnabled() ||
535 reply == blink::mojom::AppBannerPromptReply::CANCEL) {
529 UpdateState(State::PENDING_EVENT); 536 UpdateState(State::PENDING_EVENT);
530 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED); 537 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_PREVENT_DEFAULT_CALLED);
531 if (!page_requested_prompt_) 538 if (!page_requested_prompt_)
532 return; 539 return;
533 } 540 }
534 541
542 if (!IsExperimentalAppBannersEnabled())
543 ShowBanner();
544 }
545
546 void AppBannerManager::ShowBanner() {
535 // If we haven't yet returned, but we're in the PENDING_EVENT state or 547 // If we haven't yet returned, but we're in the PENDING_EVENT state or
536 // |page_requested_prompt_| is true, the page has requested a delayed showing 548 // |page_requested_prompt_| is true, the page has requested a delayed showing
537 // of the prompt. Otherwise, the prompt was never canceled by the page. 549 // of the prompt. Otherwise, the prompt was never canceled by the page.
538 if (is_pending_event()) { 550 if (is_pending_event()) {
539 TrackBeforeInstallEvent( 551 TrackBeforeInstallEvent(
540 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT); 552 BEFORE_INSTALL_EVENT_PROMPT_CALLED_AFTER_PREVENT_DEFAULT);
541 UpdateState(State::ACTIVE); 553 UpdateState(State::ACTIVE);
542 } else { 554 } else {
543 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION); 555 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_NO_ACTION);
556 // In the experimental flow, the banner is only shown if the site explicitly
557 // requests it to be shown.
558 DCHECK(!IsExperimentalAppBannersEnabled());
544 } 559 }
545 560
561 content::WebContents* contents = web_contents();
546 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( 562 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow(
547 contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 563 contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
548 564
549 DCHECK(!manifest_url_.is_empty()); 565 DCHECK(!manifest_url_.is_empty());
550 DCHECK(!manifest_.IsEmpty()); 566 DCHECK(!manifest_.IsEmpty());
551 DCHECK(!primary_icon_url_.is_empty()); 567 DCHECK(!primary_icon_url_.is_empty());
552 DCHECK(!primary_icon_.drawsNothing()); 568 DCHECK(!primary_icon_.drawsNothing());
553 569
554 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE); 570 TrackBeforeInstallEvent(BEFORE_INSTALL_EVENT_COMPLETE);
555 ShowBanner(); 571 ShowBannerUI();
556 UpdateState(State::COMPLETE); 572 UpdateState(State::COMPLETE);
557 } 573 }
558 574
559 void AppBannerManager::DisplayAppBanner(bool user_gesture) { 575 void AppBannerManager::DisplayAppBanner(bool user_gesture) {
576 // In the experimental flow, a user gesture is required for the prompt to be
577 // shown.
578 if (IsExperimentalAppBannersEnabled() && !user_gesture) {
579 // TODO: do some logging / error here
580 return;
581 }
582
560 if (is_pending_event()) { 583 if (is_pending_event()) {
561 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner. 584 // Simulate a non-canceled OnBannerPromptReply to show the delayed banner.
562 OnBannerPromptReply(blink::mojom::AppBannerPromptReply::NONE, referrer_); 585 ShowBanner();
563 } else { 586 } else {
564 // Log that the prompt request was made for when we get the prompt reply. 587 // Log that the prompt request was made for when we get the prompt reply.
565 page_requested_prompt_ = true; 588 page_requested_prompt_ = true;
566 } 589 }
567 } 590 }
568 591
569 } // namespace banners 592 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_manager.h ('k') | chrome/browser/banners/app_banner_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698