OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_ |
| 6 #define CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "content/public/browser/web_contents_observer.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" |
| 11 |
| 12 namespace content { |
| 13 class NavigationHandle; |
| 14 class RenderFrameHost; |
| 15 } |
| 16 |
| 17 namespace data_use_measurement { |
| 18 |
| 19 class ChromeDataUseAscriberService; |
| 20 |
| 21 // Propagates navigation and frame events to ChromeDataUseAscriberService. |
| 22 // We use this class instead of having ChromeDataUseAscriberService derive from |
| 23 // WebContentsObserver because each instance of WebContents needs its own |
| 24 // instance of WebContentsObserver, and ChromeDataUseAscriberService needs to |
| 25 // observe all WebContents. |
| 26 class DataUseWebContentsObserver |
| 27 : public content::WebContentsObserver, |
| 28 public content::WebContentsUserData<DataUseWebContentsObserver> { |
| 29 public: |
| 30 // Creates a DataUseWebContentsObserver for the given WebContents and |
| 31 // ChromeDataUseAscriberService. |
| 32 static void CreateForWebContents(content::WebContents* web_contents, |
| 33 ChromeDataUseAscriberService* service); |
| 34 |
| 35 ~DataUseWebContentsObserver() override; |
| 36 |
| 37 // WebContentsObserver: |
| 38 // Called when a render frame host is created. |
| 39 void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; |
| 40 |
| 41 // Called when a render frame host is deleted. |
| 42 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 43 |
| 44 // Called when a navigation is started. |
| 45 void DidStartNavigation( |
| 46 content::NavigationHandle* navigation_handle) override; |
| 47 |
| 48 // Called when a navigation is completed. |
| 49 void DidFinishNavigation( |
| 50 content::NavigationHandle* navigation_handle) override; |
| 51 |
| 52 // Called when a navigation is redirected. |
| 53 void DidRedirectNavigation( |
| 54 content::NavigationHandle* navigation_handle) override; |
| 55 |
| 56 private: |
| 57 friend class content::WebContentsUserData<DataUseWebContentsObserver>; |
| 58 |
| 59 DataUseWebContentsObserver(content::WebContents* web_contents, |
| 60 ChromeDataUseAscriberService* service); |
| 61 ChromeDataUseAscriberService* const service_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(DataUseWebContentsObserver); |
| 64 }; |
| 65 |
| 66 } // namespace data_use_measurement |
| 67 |
| 68 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_ |
OLD | NEW |