OLD | NEW |
---|---|
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> | 8 #include <list> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | |
11 #include <tuple> | |
10 #include <unordered_map> | 12 #include <unordered_map> |
11 #include <utility> | 13 #include <utility> |
12 | 14 |
13 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
14 #include "base/hash.h" | 16 #include "base/hash.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/supports_user_data.h" | 18 #include "base/supports_user_data.h" |
19 #include "chrome/browser/data_use_measurement/chrome_data_use_recorder.h" | |
17 #include "components/data_use_measurement/core/data_use_ascriber.h" | 20 #include "components/data_use_measurement/core/data_use_ascriber.h" |
18 #include "content/public/browser/global_request_id.h" | 21 #include "content/public/browser/global_request_id.h" |
19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
20 | 23 |
21 namespace content { | 24 namespace content { |
22 class RenderFrameHost; | 25 class RenderFrameHost; |
23 } | 26 } |
24 | 27 |
25 namespace data_use_measurement { | 28 namespace data_use_measurement { |
26 | 29 |
(...skipping 18 matching lines...) Expand all Loading... | |
45 // | 48 // |
46 // This class lives entirely on the IO thread. It maintains a copy of frame and | 49 // This class lives entirely on the IO thread. It maintains a copy of frame and |
47 // navigation information on the IO thread. | 50 // navigation information on the IO thread. |
48 class ChromeDataUseAscriber : public DataUseAscriber { | 51 class ChromeDataUseAscriber : public DataUseAscriber { |
49 public: | 52 public: |
50 ChromeDataUseAscriber(); | 53 ChromeDataUseAscriber(); |
51 | 54 |
52 ~ChromeDataUseAscriber() override; | 55 ~ChromeDataUseAscriber() override; |
53 | 56 |
54 // DataUseAscriber implementation: | 57 // DataUseAscriber implementation: |
55 DataUseRecorder* GetDataUseRecorder(net::URLRequest* request) override; | 58 ChromeDataUseRecorder* GetDataUseRecorder(net::URLRequest* request, |
59 bool can_create_new) override; | |
56 | 60 |
57 // Called before a request is sent. | |
58 void OnBeforeUrlRequest(net::URLRequest* request) override; | 61 void OnBeforeUrlRequest(net::URLRequest* request) override; |
RyanSturm
2016/11/29 20:32:59
Remove vertical whitespace between DataUseAscriber
Not at Google. Contact bengr
2016/11/30 00:21:15
Done.
| |
59 | 62 |
60 // Called when a URLRequest is being destroyed. | |
61 void OnUrlRequestDestroyed(net::URLRequest* request) override; | 63 void OnUrlRequestDestroyed(net::URLRequest* request) override; |
62 | 64 |
63 std::unique_ptr<URLRequestClassifier> CreateURLRequestClassifier() | 65 std::unique_ptr<URLRequestClassifier> CreateURLRequestClassifier() |
64 const override; | 66 const override; |
65 | 67 |
66 // Called when a render frame host is created. | 68 // Called when a render frame host is created. |
67 void RenderFrameCreated(int render_process_id, | 69 void RenderFrameCreated(int render_process_id, |
68 int render_frame_id, | 70 int render_frame_id, |
69 int parent_render_process_id, | 71 int parent_render_process_id, |
70 int parent_render_frame_id); | 72 int parent_render_frame_id); |
(...skipping 13 matching lines...) Expand all Loading... | |
84 // Called when a main frame navigation is ready to be committed in a | 86 // Called when a main frame navigation is ready to be committed in a |
85 // renderer. | 87 // renderer. |
86 void ReadyToCommitMainFrameNavigation( | 88 void ReadyToCommitMainFrameNavigation( |
87 GURL gurl, | 89 GURL gurl, |
88 content::GlobalRequestID global_request_id, | 90 content::GlobalRequestID global_request_id, |
89 int render_process_id, | 91 int render_process_id, |
90 int render_frame_id, | 92 int render_frame_id, |
91 bool is_same_page_navigation, | 93 bool is_same_page_navigation, |
92 void* navigation_handle); | 94 void* navigation_handle); |
93 | 95 |
94 // Called when a main frame navigation is redirected. | |
95 void DidRedirectMainFrameNavigation(GURL gurl, | |
96 int render_process_id, | |
97 int render_frame_id, | |
98 void* navigation_handle); | |
99 | 96 |
100 private: | 97 private: |
101 // Use as a key in the render frame map. Corresponds to a unique | 98 friend class ChromeDataUseAscriberTest; |
102 // RenderFrameHost. | |
103 typedef std::pair<int, int> RenderFrameHostID; | |
104 | 99 |
105 // Entry in the |data_use_recorders_| list which owns all instances of | 100 // Entry in the |data_use_recorders_| list which owns all instances of |
106 // DataUseRecorder. | 101 // DataUseRecorder. |
107 typedef std::list<std::unique_ptr<data_use_measurement::DataUseRecorder>>:: | 102 typedef std::list< |
108 iterator DataUseRecorderEntry; | 103 std::unique_ptr<data_use_measurement::ChromeDataUseRecorder>>::iterator |
104 DataUseRecorderEntry; | |
RyanSturm
2016/11/29 20:32:59
nit: IMO, this would be easier to read if you adde
Not at Google. Contact bengr
2016/11/30 00:21:15
Done.
| |
109 | 105 |
110 struct GlobalRequestIDHash { | 106 struct GlobalRequestIDHash { |
111 public: | 107 public: |
112 std::size_t operator()(const content::GlobalRequestID& x) const { | 108 std::size_t operator()(const content::GlobalRequestID& x) const { |
113 return base::HashInts(x.child_id, x.request_id); | 109 return base::HashInts(x.child_id, x.request_id); |
114 } | 110 } |
115 }; | 111 }; |
116 | 112 |
117 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { | 113 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { |
118 public: | 114 public: |
119 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); | 115 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); |
120 | 116 |
121 ~DataUseRecorderEntryAsUserData() override; | 117 ~DataUseRecorderEntryAsUserData() override; |
122 | 118 |
123 DataUseRecorderEntry recorder_entry() { return entry_; } | 119 DataUseRecorderEntry recorder_entry() { return entry_; } |
124 | 120 |
125 static const void* kUserDataKey; | 121 static const void* kUserDataKey; |
126 | 122 |
127 private: | 123 private: |
128 DataUseRecorderEntry entry_; | 124 DataUseRecorderEntry entry_; |
129 }; | 125 }; |
130 | 126 |
131 void DeletePendingNavigationEntry(content::GlobalRequestID global_request_id); | 127 DataUseRecorderEntry GetDataUseRecorderEntry(net::URLRequest* request, |
128 bool can_create_new); | |
129 | |
130 void OnDataUseCompleted(DataUseRecorderEntry entry); | |
131 | |
132 DataUseRecorderEntry CreateNewDataUseRecorder(net::URLRequest* request); | |
133 | |
134 bool IsRecorderInPendingNavigationMap(net::URLRequest* request); | |
135 | |
136 bool IsRecorderInRenderFrameMap(net::URLRequest* request); | |
132 | 137 |
133 // Owner for all instances of DataUseRecorder. An instance is kept in this | 138 // Owner for all instances of DataUseRecorder. An instance is kept in this |
134 // list if any entity (render frame hosts, URLRequests, pending navigations) | 139 // list if any entity (render frame hosts, URLRequests, pending navigations) |
135 // that ascribe data use to the instance exists, and deleted when all | 140 // that ascribe data use to the instance exists, and deleted when all |
136 // ascribing entities go away. | 141 // ascribing entities go away. |
137 std::list<std::unique_ptr<DataUseRecorder>> data_use_recorders_; | 142 std::list<std::unique_ptr<ChromeDataUseRecorder>> data_use_recorders_; |
RyanSturm
2016/11/29 20:32:59
Is there a reason why this is std::list<std::uniqu
Not at Google. Contact bengr
2016/11/30 00:21:15
Switched to std::list<ChromeDataUseRecorder>.
Usi
RyanSturm
2016/12/01 00:40:46
I think it improves syntax, and if you use emplace
Not at Google. Contact bengr
2016/12/01 01:23:39
Yes, don't see a reason to std::move the unique pt
| |
138 | 143 |
139 // Map from RenderFrameHost to the DataUseRecorderEntry in | 144 // Map from RenderFrameHost to the DataUseRecorderEntry in |
140 // |data_use_recorders_| that the frame ascribe data use to. | 145 // |data_use_recorders_| that the frame ascribe data use to. |
141 base::hash_map<RenderFrameHostID, DataUseRecorderEntry> | 146 base::hash_map<RenderFrameHostID, DataUseRecorderEntry> |
142 render_frame_data_use_map_; | 147 render_frame_data_use_map_; |
143 | 148 |
144 // Map from pending navigations to the DataUseRecorderEntry in | 149 // Map from pending navigations to the DataUseRecorderEntry in |
145 // |data_use_recorders_| that the navigation ascribes data use to. | 150 // |data_use_recorders_| that the navigation ascribes data use to. |
146 std::unordered_map<content::GlobalRequestID, | 151 std::unordered_map<content::GlobalRequestID, |
147 DataUseRecorderEntry, | 152 DataUseRecorderEntry, |
148 GlobalRequestIDHash> | 153 GlobalRequestIDHash> |
149 pending_navigation_data_use_map_; | 154 pending_navigation_data_use_map_; |
150 | 155 |
151 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); | 156 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); |
152 }; | 157 }; |
153 | 158 |
154 } // namespace data_use_measurement | 159 } // namespace data_use_measurement |
155 | 160 |
156 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ | 161 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ |
OLD | NEW |