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

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: Move ascriber to chrome/browser 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)) {
bengr 2016/09/01 00:16:55 Remove curly braces.
Not at Google. Contact bengr 2016/09/07 23:38:38 Done.
24 return;
25 }
26
27 // |DataUseWebContentsObserver| is a |WebContentsUserData| so its lifetime
28 // is scoped to |web_contents|.
29 // |ChromeDataUseAscriberService| is a |KeyedService| and its lifetime is
30 // tied to a profile. Since profiles outlive |WebContents|, |service| will
31 // outlive |DataUseWebContentsObserver|.
32 web_contents->SetUserData(
33 UserDataKey(), new DataUseWebContentsObserver(web_contents, service));
34 }
35
36 DataUseWebContentsObserver::DataUseWebContentsObserver(
37 content::WebContents* web_contents,
38 ChromeDataUseAscriberService* service)
39 : content::WebContentsObserver(web_contents), service_(service) {}
40
41 DataUseWebContentsObserver::~DataUseWebContentsObserver() {}
42
43 void DataUseWebContentsObserver::RenderFrameCreated(
44 content::RenderFrameHost* render_frame_host) {
45 service_->RenderFrameCreated(render_frame_host);
46 }
47
48 void DataUseWebContentsObserver::RenderFrameDeleted(
49 content::RenderFrameHost* render_frame_host) {
50 service_->RenderFrameDeleted(render_frame_host);
51 }
52
53 void DataUseWebContentsObserver::DidStartNavigation(
54 content::NavigationHandle* navigation_handle) {
55 service_->DidStartNavigation(navigation_handle);
56 }
57
58 void DataUseWebContentsObserver::DidFinishNavigation(
59 content::NavigationHandle* navigation_handle) {
60 service_->DidFinishNavigation(navigation_handle);
61 }
62
63 void DataUseWebContentsObserver::DidRedirectNavigation(
64 content::NavigationHandle* navigation_handle) {
65 service_->DidRedirectNavigation(navigation_handle);
66 }
67
68 } // namespace data_use_measurement
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698