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

Unified Diff: chrome/browser/data_use_measurement/data_use_web_contents_observer.h

Issue 2285903002: Framework to ascribe all network data use to a source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 4 years, 3 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/data_use_measurement/data_use_web_contents_observer.h
diff --git a/chrome/browser/data_use_measurement/data_use_web_contents_observer.h b/chrome/browser/data_use_measurement/data_use_web_contents_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..b9ded25d4fdba8a399a8052179659d6e7217ba05
--- /dev/null
+++ b/chrome/browser/data_use_measurement/data_use_web_contents_observer.h
@@ -0,0 +1,68 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_
+#define CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_
+
+#include "base/macros.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+namespace content {
+class NavigationHandle;
+class RenderFrameHost;
+}
+
+namespace data_use_measurement {
+
+class ChromeDataUseAscriberService;
+
+// Propagates navigation and frame events to ChromeDataUseAscriberService.
+// We use this class instead of having ChromeDataUseAscriberService derive from
+// WebContentsObserver because each instance of WebContents needs its own
+// instance of WebContentsObserver, and ChromeDataUseAscriberService needs to
+// observe all WebContents.
+class DataUseWebContentsObserver
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<DataUseWebContentsObserver> {
+ public:
+ // Creates a DataUseWebContentsObserver for the given WebContents and
+ // ChromeDataUseAscriberService.
+ static void CreateForWebContents(content::WebContents* web_contents,
+ ChromeDataUseAscriberService* service);
+
+ ~DataUseWebContentsObserver() override;
+
+ // WebContentsObserver:
+ // Called when a render frame host is created.
+ void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
+
+ // Called when a render frame host is deleted.
+ void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
+
+ // Called when a navigation is started.
+ void DidStartNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ // Called when a navigation is completed.
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ // Called when a navigation is redirected.
+ void DidRedirectNavigation(
+ content::NavigationHandle* navigation_handle) override;
+
+ private:
+ friend class content::WebContentsUserData<DataUseWebContentsObserver>;
+
+ DataUseWebContentsObserver(content::WebContents* web_contents,
+ ChromeDataUseAscriberService* service);
+ ChromeDataUseAscriberService* const service_;
+
+ DISALLOW_COPY_AND_ASSIGN(DataUseWebContentsObserver);
+};
+
+} // namespace data_use_measurement
+
+#endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_DATA_USE_WEB_CONTENTS_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698