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 <map> |
9 #include <memory> | 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 #include <tuple> | 12 #include <tuple> |
12 #include <unordered_map> | |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/containers/hash_tables.h" | |
16 #include "base/hash.h" | 15 #include "base/hash.h" |
17 #include "base/macros.h" | 16 #include "base/macros.h" |
18 #include "base/supports_user_data.h" | 17 #include "base/supports_user_data.h" |
19 #include "chrome/browser/data_use_measurement/chrome_data_use_recorder.h" | 18 #include "chrome/browser/data_use_measurement/chrome_data_use_recorder.h" |
20 #include "components/data_use_measurement/core/data_use_ascriber.h" | 19 #include "components/data_use_measurement/core/data_use_ascriber.h" |
21 #include "content/public/browser/global_request_id.h" | 20 #include "content/public/browser/global_request_id.h" |
22 #include "url/gurl.h" | 21 #include "url/gurl.h" |
23 | 22 |
24 namespace content { | 23 namespace content { |
25 class RenderFrameHost; | 24 class RenderFrameHost; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 private: | 111 private: |
113 friend class ChromeDataUseAscriberTest; | 112 friend class ChromeDataUseAscriberTest; |
114 | 113 |
115 // Entry in the |data_use_recorders_| list which owns all instances of | 114 // Entry in the |data_use_recorders_| list which owns all instances of |
116 // DataUseRecorder. std::list is used so that iterators remain valid until the | 115 // DataUseRecorder. std::list is used so that iterators remain valid until the |
117 // lifetime of the container, and will not be invalidated when container is | 116 // lifetime of the container, and will not be invalidated when container is |
118 // modified. | 117 // modified. |
119 typedef std::list<ChromeDataUseRecorder> DataUseRecorderList; | 118 typedef std::list<ChromeDataUseRecorder> DataUseRecorderList; |
120 typedef DataUseRecorderList::iterator DataUseRecorderEntry; | 119 typedef DataUseRecorderList::iterator DataUseRecorderEntry; |
121 | 120 |
122 struct GlobalRequestIDHash { | |
123 public: | |
124 std::size_t operator()(const content::GlobalRequestID& x) const { | |
125 return base::HashInts(x.child_id, x.request_id); | |
126 } | |
127 }; | |
128 | |
129 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { | 121 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { |
130 public: | 122 public: |
131 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); | 123 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); |
132 | 124 |
133 ~DataUseRecorderEntryAsUserData() override; | 125 ~DataUseRecorderEntryAsUserData() override; |
134 | 126 |
135 DataUseRecorderEntry recorder_entry() { return entry_; } | 127 DataUseRecorderEntry recorder_entry() { return entry_; } |
136 | 128 |
137 static const void* kUserDataKey; | 129 static const void* kUserDataKey; |
138 | 130 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 177 |
186 // Owner for all instances of DataUseRecorder. An instance is kept in this | 178 // Owner for all instances of DataUseRecorder. An instance is kept in this |
187 // list if any entity (render frame hosts, URLRequests, pending navigations) | 179 // list if any entity (render frame hosts, URLRequests, pending navigations) |
188 // that ascribe data use to the instance exists, and deleted when all | 180 // that ascribe data use to the instance exists, and deleted when all |
189 // ascribing entities go away. | 181 // ascribing entities go away. |
190 DataUseRecorderList data_use_recorders_; | 182 DataUseRecorderList data_use_recorders_; |
191 | 183 |
192 // Map from RenderFrameHost to the MainRenderFrameEntry which contains all | 184 // Map from RenderFrameHost to the MainRenderFrameEntry which contains all |
193 // details of the main frame. New entry is added on main render frame creation | 185 // details of the main frame. New entry is added on main render frame creation |
194 // and removed on its deletion. | 186 // and removed on its deletion. |
195 base::hash_map<RenderFrameHostID, MainRenderFrameEntry> | 187 std::map<RenderFrameHostID, MainRenderFrameEntry> |
196 main_render_frame_entry_map_; | 188 main_render_frame_entry_map_; |
197 | 189 |
198 // Maps subframe IDs to the mainframe ID, so the mainframe lifetime can have | 190 // Maps subframe IDs to the mainframe ID, so the mainframe lifetime can have |
199 // ownership over the lifetime of entries in |data_use_recorders_|. Mainframes | 191 // ownership over the lifetime of entries in |data_use_recorders_|. Mainframes |
200 // are mapped to themselves. | 192 // are mapped to themselves. |
201 base::hash_map<RenderFrameHostID, RenderFrameHostID> | 193 std::map<RenderFrameHostID, RenderFrameHostID> subframe_to_mainframe_map_; |
202 subframe_to_mainframe_map_; | |
203 | 194 |
204 // Map from pending navigations to the DataUseRecorderEntry in | 195 // Map from pending navigations to the DataUseRecorderEntry in |
205 // |data_use_recorders_| that the navigation ascribes data use to. | 196 // |data_use_recorders_| that the navigation ascribes data use to. |
206 std::unordered_map<content::GlobalRequestID, | 197 std::map<content::GlobalRequestID, DataUseRecorderEntry> |
207 DataUseRecorderEntry, | |
208 GlobalRequestIDHash> | |
209 pending_navigation_data_use_map_; | 198 pending_navigation_data_use_map_; |
210 | 199 |
211 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); | 200 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); |
212 }; | 201 }; |
213 | 202 |
214 } // namespace data_use_measurement | 203 } // namespace data_use_measurement |
215 | 204 |
216 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ | 205 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ |
OLD | NEW |