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

Unified Diff: chrome/browser/banners/app_banner_manager.h

Issue 2024953005: Allow app banners to be triggered by increases in site engagement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@site-engagement-callback
Patch Set: Remove obsolete test Created 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/banners/app_banner_manager.h
diff --git a/chrome/browser/banners/app_banner_manager.h b/chrome/browser/banners/app_banner_manager.h
index f29c0bdbe89d583143d4ae604529d2f111d7d3e8..531bbef5e5ce7d4511e57a17073242aa4ca6121e 100644
--- a/chrome/browser/banners/app_banner_manager.h
+++ b/chrome/browser/banners/app_banner_manager.h
@@ -6,19 +6,16 @@
#define CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
#include <memory>
+#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/banners/app_banner_data_fetcher.h"
+#include "chrome/browser/engagement/site_engagement_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h"
-namespace content {
-struct FrameNavigateParams;
-struct LoadCommittedDetails;
-} // namespace content
-
namespace banners {
class AppBannerDataFetcher;
@@ -30,7 +27,8 @@ class AppBannerDataFetcher;
* requested app. Any work in progress for other apps is discarded.
*/
class AppBannerManager : public content::WebContentsObserver,
- public AppBannerDataFetcher::Delegate {
+ public AppBannerDataFetcher::Delegate,
+ public SiteEngagementObserver {
public:
static void DisableSecureSchemeCheckForTesting();
@@ -42,11 +40,8 @@ class AppBannerManager : public content::WebContentsObserver,
// Requests an app banner. Set |is_debug_mode| when it is triggered by the
// developer's action in DevTools.
- void RequestAppBanner(content::RenderFrameHost* render_frame_host,
- const GURL& validated_url,
- bool is_debug_mode);
+ void RequestAppBanner(const GURL& validated_url, bool is_debug_mode);
- AppBannerManager();
~AppBannerManager() override;
protected:
@@ -66,12 +61,16 @@ class AppBannerManager : public content::WebContentsObserver,
private:
// WebContentsObserver overrides.
- void DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& params) override;
-
+ void DidStartNavigation(
+ content::NavigationHandle* navigation_handle) override;
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
+ void MediaStartedPlaying(const MediaPlayerId& id) override;
+ void MediaStoppedPlaying(const MediaPlayerId& id) override;
+ void WasShown() override;
+ void WasHidden() override;
// AppBannerDataFetcher::Delegate overrides.
bool HandleNonWebApp(const std::string& platform,
@@ -79,6 +78,11 @@ class AppBannerManager : public content::WebContentsObserver,
const std::string& id,
bool is_debug_mode) override;
+ // SiteEngagementObserver overrides.
+ void OnEngagementIncreased(content::WebContents* web_contents,
+ const GURL& url,
+ double score) override;
+
// Cancels an active DataFetcher, stopping its banners from appearing.
void CancelActiveFetcher();
@@ -88,6 +92,16 @@ class AppBannerManager : public content::WebContentsObserver,
// Fetches the data required to display a banner for the current page.
scoped_refptr<AppBannerDataFetcher> data_fetcher_;
+ // We do not want to trigger a banner when the manager is attached to
+ // a WebContents that is playing video or in the background.
+ std::vector<MediaPlayerId> active_media_players_;
+ bool is_hidden_;
benwells 2016/06/28 00:57:50 I recall we chatted about this, and you were going
dominickn 2016/06/28 03:52:29 Thanks for reminding me about this. The right thin
+
+ // If a banner is requested before the page has finished loading, defer
+ // triggering the pipeline until the load is complete.
+ bool load_finished_;
+ bool banner_requested_;
benwells 2016/06/28 00:57:50 Instead of these two bools, did you consider using
dominickn 2016/06/28 03:52:29 We need to know BANNER_REQUESTED independently of
benwells 2016/06/29 03:38:24 I was finding the logic hard to follow and thought
+
// A weak pointer is used as the lifetime of the ServiceWorkerContext is
// longer than the lifetime of this banner manager. The banner manager
// might be gone when calls sent to the ServiceWorkerContext are completed.

Powered by Google App Engine
This is Rietveld 408576698