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

Side by Side Diff: chrome/browser/data_use_measurement/data_use_web_contents_observer.cc

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 comments from thestig@ 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 unified diff | Download patch
OLDNEW
(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 #include "chrome/browser/data_use_measurement/data_use_web_contents_observer.h"
6
7 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber_service.h "
8 #include "content/public/browser/navigation_handle.h"
9 #include "content/public/browser/render_frame_host.h"
10
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
12 data_use_measurement::DataUseWebContentsObserver);
13
14 namespace data_use_measurement {
15
16 // static
17 void DataUseWebContentsObserver::CreateForWebContents(
18 content::WebContents* web_contents,
19 ChromeDataUseAscriberService* service) {
20 DCHECK(web_contents);
21 // Nothing to do if there is no service (Incognito), or if instance already
22 // exists.
23 if (!service || FromWebContents(web_contents))
24 return;
25
26 // |DataUseWebContentsObserver| is a |WebContentsUserData| so its lifetime
27 // is scoped to |web_contents|.
28 // |ChromeDataUseAscriberService| is a |KeyedService| and its lifetime is
29 // tied to a profile. Since profiles outlive |WebContents|, |service| will
30 // outlive |DataUseWebContentsObserver|.
31 web_contents->SetUserData(
32 UserDataKey(), new DataUseWebContentsObserver(web_contents, service));
33 }
34
35 DataUseWebContentsObserver::DataUseWebContentsObserver(
36 content::WebContents* web_contents,
37 ChromeDataUseAscriberService* service)
38 : content::WebContentsObserver(web_contents), service_(service) {}
39
40 DataUseWebContentsObserver::~DataUseWebContentsObserver() {}
41
42 void DataUseWebContentsObserver::RenderFrameCreated(
43 content::RenderFrameHost* render_frame_host) {
44 service_->RenderFrameCreated(render_frame_host);
45 }
46
47 void DataUseWebContentsObserver::RenderFrameDeleted(
48 content::RenderFrameHost* render_frame_host) {
49 service_->RenderFrameDeleted(render_frame_host);
50 }
51
52 void DataUseWebContentsObserver::DidStartNavigation(
53 content::NavigationHandle* navigation_handle) {
54 service_->DidStartNavigation(navigation_handle);
55 }
56
57 void DataUseWebContentsObserver::DidFinishNavigation(
58 content::NavigationHandle* navigation_handle) {
59 service_->DidFinishNavigation(navigation_handle);
60 }
61
62 void DataUseWebContentsObserver::DidRedirectNavigation(
63 content::NavigationHandle* navigation_handle) {
64 service_->DidRedirectNavigation(navigation_handle);
65 }
66
67 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698