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

Side by Side 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 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 #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 <memory> 8 #include <memory>
9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/banners/app_banner_data_fetcher.h" 14 #include "chrome/browser/banners/app_banner_data_fetcher.h"
15 #include "chrome/browser/engagement/site_engagement_observer.h"
14 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
15 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" 17 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h"
16 18
17 namespace content {
18 struct FrameNavigateParams;
19 struct LoadCommittedDetails;
20 } // namespace content
21
22 namespace banners { 19 namespace banners {
23 class AppBannerDataFetcher; 20 class AppBannerDataFetcher;
24 21
25 /** 22 /**
26 * Creates an app banner. 23 * Creates an app banner.
27 * 24 *
28 * Hooks the wiring together for getting the data for a particular app. 25 * Hooks the wiring together for getting the data for a particular app.
29 * Monitors at most one app at a time, tracking the info for the most recently 26 * Monitors at most one app at a time, tracking the info for the most recently
30 * requested app. Any work in progress for other apps is discarded. 27 * requested app. Any work in progress for other apps is discarded.
31 */ 28 */
32 class AppBannerManager : public content::WebContentsObserver, 29 class AppBannerManager : public content::WebContentsObserver,
33 public AppBannerDataFetcher::Delegate { 30 public AppBannerDataFetcher::Delegate,
31 public SiteEngagementObserver {
34 public: 32 public:
35 static void DisableSecureSchemeCheckForTesting(); 33 static void DisableSecureSchemeCheckForTesting();
36 34
37 static void SetEngagementWeights(double direct_engagement, 35 static void SetEngagementWeights(double direct_engagement,
38 double indirect_engagement); 36 double indirect_engagement);
39 37
40 // Returns whether or not the URLs match for everything except for the ref. 38 // Returns whether or not the URLs match for everything except for the ref.
41 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second); 39 static bool URLsAreForTheSamePage(const GURL& first, const GURL& second);
42 40
43 // Requests an app banner. Set |is_debug_mode| when it is triggered by the 41 // Requests an app banner. Set |is_debug_mode| when it is triggered by the
44 // developer's action in DevTools. 42 // developer's action in DevTools.
45 void RequestAppBanner(content::RenderFrameHost* render_frame_host, 43 void RequestAppBanner(const GURL& validated_url, bool is_debug_mode);
46 const GURL& validated_url,
47 bool is_debug_mode);
48 44
49 AppBannerManager();
50 ~AppBannerManager() override; 45 ~AppBannerManager() override;
51 46
52 protected: 47 protected:
53 explicit AppBannerManager(content::WebContents* web_contents); 48 explicit AppBannerManager(content::WebContents* web_contents);
54 49
55 void ReplaceWebContents(content::WebContents* web_contents); 50 void ReplaceWebContents(content::WebContents* web_contents);
56 51
57 // Creates an AppBannerDataFetcher, which constructs an app banner. 52 // Creates an AppBannerDataFetcher, which constructs an app banner.
58 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher( 53 virtual AppBannerDataFetcher* CreateAppBannerDataFetcher(
59 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate, 54 base::WeakPtr<AppBannerDataFetcher::Delegate> weak_delegate,
60 bool is_debug_mode) = 0; 55 bool is_debug_mode) = 0;
61 56
62 // Return whether the AppBannerDataFetcher is active. 57 // Return whether the AppBannerDataFetcher is active.
63 bool IsFetcherActive(); 58 bool IsFetcherActive();
64 59
65 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; } 60 scoped_refptr<AppBannerDataFetcher> data_fetcher() { return data_fetcher_; }
66 61
67 private: 62 private:
68 // WebContentsObserver overrides. 63 // WebContentsObserver overrides.
69 void DidNavigateMainFrame( 64 void DidStartNavigation(
70 const content::LoadCommittedDetails& details, 65 content::NavigationHandle* navigation_handle) override;
71 const content::FrameNavigateParams& params) override; 66 void DidFinishNavigation(
72 67 content::NavigationHandle* navigation_handle) override;
73 void DidFinishLoad(content::RenderFrameHost* render_frame_host, 68 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
74 const GURL& validated_url) override; 69 const GURL& validated_url) override;
70 void MediaStartedPlaying(const MediaPlayerId& id) override;
71 void MediaStoppedPlaying(const MediaPlayerId& id) override;
72 void WasShown() override;
73 void WasHidden() override;
75 74
76 // AppBannerDataFetcher::Delegate overrides. 75 // AppBannerDataFetcher::Delegate overrides.
77 bool HandleNonWebApp(const std::string& platform, 76 bool HandleNonWebApp(const std::string& platform,
78 const GURL& url, 77 const GURL& url,
79 const std::string& id, 78 const std::string& id,
80 bool is_debug_mode) override; 79 bool is_debug_mode) override;
81 80
81 // SiteEngagementObserver overrides.
82 void OnEngagementIncreased(content::WebContents* web_contents,
83 const GURL& url,
84 double score) override;
85
82 // Cancels an active DataFetcher, stopping its banners from appearing. 86 // Cancels an active DataFetcher, stopping its banners from appearing.
83 void CancelActiveFetcher(); 87 void CancelActiveFetcher();
84 88
85 // The type of navigation made to the page 89 // The type of navigation made to the page
86 ui::PageTransition last_transition_type_; 90 ui::PageTransition last_transition_type_;
87 91
88 // Fetches the data required to display a banner for the current page. 92 // Fetches the data required to display a banner for the current page.
89 scoped_refptr<AppBannerDataFetcher> data_fetcher_; 93 scoped_refptr<AppBannerDataFetcher> data_fetcher_;
90 94
95 // We do not want to trigger a banner when the manager is attached to
96 // a WebContents that is playing video or in the background.
97 std::vector<MediaPlayerId> active_media_players_;
98 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
99
100 // If a banner is requested before the page has finished loading, defer
101 // triggering the pipeline until the load is complete.
102 bool load_finished_;
103 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
104
91 // A weak pointer is used as the lifetime of the ServiceWorkerContext is 105 // A weak pointer is used as the lifetime of the ServiceWorkerContext is
92 // longer than the lifetime of this banner manager. The banner manager 106 // longer than the lifetime of this banner manager. The banner manager
93 // might be gone when calls sent to the ServiceWorkerContext are completed. 107 // might be gone when calls sent to the ServiceWorkerContext are completed.
94 base::WeakPtrFactory<AppBannerManager> weak_factory_; 108 base::WeakPtrFactory<AppBannerManager> weak_factory_;
95 109
96 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); 110 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
97 }; // class AppBannerManager 111 }; // class AppBannerManager
98 112
99 } // namespace banners 113 } // namespace banners
100 114
101 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ 115 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698