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

Side by Side Diff: chrome/browser/data_use_measurement/chrome_data_use_ascriber.h

Issue 2413663003: Expose GlobalRequestID in NavigationHandle and ResourceRequestInfo. (Closed)
Patch Set: Use OnURLRequestDestroyed Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ 5 #ifndef CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_
6 #define CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ 6 #define CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_
7 7
8 #include <list>
9 #include <memory>
10 #include <unordered_map>
11 #include <utility>
12
13 #include "base/containers/hash_tables.h"
14 #include "base/hash.h"
8 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/supports_user_data.h"
9 #include "components/data_use_measurement/core/data_use_ascriber.h" 17 #include "components/data_use_measurement/core/data_use_ascriber.h"
18 #include "content/public/browser/global_request_id.h"
10 #include "url/gurl.h" 19 #include "url/gurl.h"
11 20
12 namespace content { 21 namespace content {
13 class NavigationHandle; 22 class NavigationHandle;
14 class RenderFrameHost; 23 class RenderFrameHost;
15 } 24 }
16 25
17 namespace data_use_measurement { 26 namespace data_use_measurement {
18 27
19 // Browser implementation of DataUseAscriber. Maintains a list of 28 // Browser implementation of DataUseAscriber. Maintains a list of
(...skipping 14 matching lines...) Expand all
34 // the DataUseRecorder instance for page load. 43 // the DataUseRecorder instance for page load.
35 // 44 //
36 // This class lives entirely on the IO thread. It maintains a copy of frame and 45 // This class lives entirely on the IO thread. It maintains a copy of frame and
37 // navigation information on the IO thread. 46 // navigation information on the IO thread.
38 class ChromeDataUseAscriber : public DataUseAscriber { 47 class ChromeDataUseAscriber : public DataUseAscriber {
39 public: 48 public:
40 ChromeDataUseAscriber(); 49 ChromeDataUseAscriber();
41 50
42 ~ChromeDataUseAscriber() override; 51 ~ChromeDataUseAscriber() override;
43 52
44 // DataUseAscriber: 53 // DataUseAscriber implementation:
45 DataUseRecorder* GetDataUseRecorder(net::URLRequest* request) override; 54 DataUseRecorder* GetDataUseRecorder(net::URLRequest* request) override;
46 55
56 // Called before a request is sent.
57 void OnBeforeUrlRequest(net::URLRequest* request) override;
58
59 // Called when a URLRequest is being destroyed.
60 void OnUrlRequestDestroyed(net::URLRequest* request) override;
61
47 // Called when a render frame host is created. 62 // Called when a render frame host is created.
48 void RenderFrameCreated(int render_process_id, 63 void RenderFrameCreated(int render_process_id,
49 int render_frame_id, 64 int render_frame_id,
50 int parent_render_process_id, 65 int parent_render_process_id,
51 int parent_render_frame_id); 66 int parent_render_frame_id);
52 67
53 // Called when a render frame host is deleted. 68 // Called when a render frame host is deleted.
54 void RenderFrameDeleted(int render_process_id, 69 void RenderFrameDeleted(int render_process_id,
55 int render_frame_id, 70 int render_frame_id,
56 int parent_render_process_id, 71 int parent_render_process_id,
57 int parent_render_frame_id); 72 int parent_render_frame_id);
58 73
59 // Called when a main frame navigation is started. 74 // Called when a main frame navigation is started.
60 void DidStartMainFrameNavigation(GURL gurl, 75 void DidStartMainFrameNavigation(GURL gurl,
61 int render_process_id, 76 int render_process_id,
62 int render_frame_id, 77 int render_frame_id,
63 void* navigation_handle); 78 void* navigation_handle);
64 79
65 // Called when a main frame navigation is completed. 80 // Called when a main frame navigation is ready to be committed in a
66 void DidFinishMainFrameNavigation(GURL gurl, 81 // renderer.
67 int render_process_id, 82 void ReadyToCommitMainFrameNavigation(
68 int render_frame_id, 83 GURL gurl,
69 bool is_same_page_navigation, 84 content::GlobalRequestID global_request_id,
70 void* navigation_handle); 85 int render_process_id,
86 int render_frame_id,
87 bool is_same_page_navigation,
88 void* navigation_handle);
71 89
72 // Called when a main frame navigation is redirected. 90 // Called when a main frame navigation is redirected.
73 void DidRedirectMainFrameNavigation(GURL gurl, 91 void DidRedirectMainFrameNavigation(GURL gurl,
74 int render_process_id, 92 int render_process_id,
75 int render_frame_id, 93 int render_frame_id,
76 void* navigation_handle); 94 void* navigation_handle);
77 95
78 private: 96 private:
97 // Use as a key in the render frame map. Corresponds to a unique
98 // RenderFrameHost.
99 typedef std::pair<int, int> RenderFrameHostID;
100
101 // Entry in the |data_use_recorders_| list which owns all instances of
102 // DataUseRecorder.
103 typedef std::list<std::unique_ptr<data_use_measurement::DataUseRecorder>>::
104 iterator DataUseRecorderEntry;
105
106 struct GlobalRequestIDHash {
107 public:
108 std::size_t operator()(const content::GlobalRequestID& x) const {
109 return base::HashInts(x.child_id, x.request_id);
110 }
111 };
112
113 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data {
114 public:
115 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry);
116
117 ~DataUseRecorderEntryAsUserData() override;
118
119 DataUseRecorderEntry recorder_entry() { return entry_; }
120
121 static const void* kUserDataKey;
122
123 private:
124 DataUseRecorderEntry entry_;
125 };
126
127 void DeletePendingNavigationEntry(content::GlobalRequestID global_request_id);
128
129 // Owner for all instances of DataUseRecorder. An instance is kept in this
130 // list if any entity (render frame hosts, URLRequests, pending navigations)
131 // that ascribe data use to the instance exists, and deleted when all
132 // ascribing entities go away.
133 std::list<std::unique_ptr<DataUseRecorder>> data_use_recorders_;
134
135 // Map from RenderFrameHost to the DataUseRecorderEntry in
136 // |data_use_recorders_| that the frame ascribe data use to.
137 base::hash_map<RenderFrameHostID, DataUseRecorderEntry>
138 render_frame_data_use_map_;
139
140 // Map from pending navigations to the DataUseRecorderEntry in
141 // |data_use_recorders_| that the navigation ascribes data use to.
142 std::unordered_map<content::GlobalRequestID,
143 DataUseRecorderEntry,
144 GlobalRequestIDHash>
145 pending_navigation_data_use_map_;
146
79 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); 147 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber);
80 }; 148 };
81 149
82 } // namespace data_use_measurement 150 } // namespace data_use_measurement
83 151
84 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ 152 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698