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

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: Address reviewer comments. Rebase Created 4 years, 5 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;
75 72
76 // AppBannerDataFetcher::Delegate overrides. 73 // AppBannerDataFetcher::Delegate overrides.
77 bool HandleNonWebApp(const std::string& platform, 74 bool HandleNonWebApp(const std::string& platform,
78 const GURL& url, 75 const GURL& url,
79 const std::string& id, 76 const std::string& id,
80 bool is_debug_mode) override; 77 bool is_debug_mode) override;
81 78
79 // SiteEngagementObserver overrides.
80 void OnEngagementIncreased(content::WebContents* web_contents,
81 const GURL& url,
82 double score) override;
83
82 // Cancels an active DataFetcher, stopping its banners from appearing. 84 // Cancels an active DataFetcher, stopping its banners from appearing.
83 void CancelActiveFetcher(); 85 void CancelActiveFetcher();
84 86
85 // The type of navigation made to the page 87 // The type of navigation made to the page
86 ui::PageTransition last_transition_type_; 88 ui::PageTransition last_transition_type_;
87 89
88 // Fetches the data required to display a banner for the current page. 90 // Fetches the data required to display a banner for the current page.
89 scoped_refptr<AppBannerDataFetcher> data_fetcher_; 91 scoped_refptr<AppBannerDataFetcher> data_fetcher_;
90 92
93 // We do not want to trigger a banner when the manager is attached to
94 // a WebContents that is playing video. Banners triggering on a site in the
95 // background will appear when the tab is reactivated.
96 std::vector<MediaPlayerId> active_media_players_;
97
98 // If a banner is requested before the page has finished loading, defer
99 // triggering the pipeline until the load is complete.
100 bool banner_request_queued_;
101 bool load_finished_;
102
91 // A weak pointer is used as the lifetime of the ServiceWorkerContext is 103 // A weak pointer is used as the lifetime of the ServiceWorkerContext is
92 // longer than the lifetime of this banner manager. The banner manager 104 // longer than the lifetime of this banner manager. The banner manager
93 // might be gone when calls sent to the ServiceWorkerContext are completed. 105 // might be gone when calls sent to the ServiceWorkerContext are completed.
94 base::WeakPtrFactory<AppBannerManager> weak_factory_; 106 base::WeakPtrFactory<AppBannerManager> weak_factory_;
95 107
96 DISALLOW_COPY_AND_ASSIGN(AppBannerManager); 108 DISALLOW_COPY_AND_ASSIGN(AppBannerManager);
97 }; // class AppBannerManager 109 }; // class AppBannerManager
98 110
99 } // namespace banners 111 } // namespace banners
100 112
101 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_ 113 #endif // CHROME_BROWSER_BANNERS_APP_BANNER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_manager_android.cc ('k') | chrome/browser/banners/app_banner_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698