| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 uint32_t page_transition); | 110 uint32_t page_transition); |
| 112 | 111 |
| 113 private: | 112 private: |
| 114 friend class ChromeDataUseAscriberTest; | 113 friend class ChromeDataUseAscriberTest; |
| 115 | 114 |
| 116 // Entry in the |data_use_recorders_| list which owns all instances of | 115 // Entry in the |data_use_recorders_| list which owns all instances of |
| 117 // DataUseRecorder. | 116 // DataUseRecorder. |
| 118 typedef std::list<ChromeDataUseRecorder> DataUseRecorderList; | 117 typedef std::list<ChromeDataUseRecorder> DataUseRecorderList; |
| 119 typedef DataUseRecorderList::iterator DataUseRecorderEntry; | 118 typedef DataUseRecorderList::iterator DataUseRecorderEntry; |
| 120 | 119 |
| 121 struct GlobalRequestIDHash { | |
| 122 public: | |
| 123 std::size_t operator()(const content::GlobalRequestID& x) const { | |
| 124 return base::HashInts(x.child_id, x.request_id); | |
| 125 } | |
| 126 }; | |
| 127 | |
| 128 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { | 120 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { |
| 129 public: | 121 public: |
| 130 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); | 122 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); |
| 131 | 123 |
| 132 ~DataUseRecorderEntryAsUserData() override; | 124 ~DataUseRecorderEntryAsUserData() override; |
| 133 | 125 |
| 134 DataUseRecorderEntry recorder_entry() { return entry_; } | 126 DataUseRecorderEntry recorder_entry() { return entry_; } |
| 135 | 127 |
| 136 static const void* kUserDataKey; | 128 static const void* kUserDataKey; |
| 137 | 129 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 bool IsRecorderInRenderFrameMap(net::URLRequest* request); | 145 bool IsRecorderInRenderFrameMap(net::URLRequest* request); |
| 154 | 146 |
| 155 // Owner for all instances of DataUseRecorder. An instance is kept in this | 147 // Owner for all instances of DataUseRecorder. An instance is kept in this |
| 156 // list if any entity (render frame hosts, URLRequests, pending navigations) | 148 // list if any entity (render frame hosts, URLRequests, pending navigations) |
| 157 // that ascribe data use to the instance exists, and deleted when all | 149 // that ascribe data use to the instance exists, and deleted when all |
| 158 // ascribing entities go away. | 150 // ascribing entities go away. |
| 159 DataUseRecorderList data_use_recorders_; | 151 DataUseRecorderList data_use_recorders_; |
| 160 | 152 |
| 161 // Map from RenderFrameHost to the DataUseRecorderEntry in | 153 // Map from RenderFrameHost to the DataUseRecorderEntry in |
| 162 // |data_use_recorders_| that the main frame ascribes data use to. | 154 // |data_use_recorders_| that the main frame ascribes data use to. |
| 163 base::hash_map<RenderFrameHostID, DataUseRecorderEntry> | 155 std::map<RenderFrameHostID, DataUseRecorderEntry> |
| 164 main_render_frame_data_use_map_; | 156 main_render_frame_data_use_map_; |
| 165 | 157 |
| 166 // Maps subframe IDs to the mainframe ID, so the mainframe lifetime can have | 158 // Maps subframe IDs to the mainframe ID, so the mainframe lifetime can have |
| 167 // ownership over the lifetime of entries in |data_use_recorders_|. Mainframes | 159 // ownership over the lifetime of entries in |data_use_recorders_|. Mainframes |
| 168 // are mapped to themselves. | 160 // are mapped to themselves. |
| 169 base::hash_map<RenderFrameHostID, RenderFrameHostID> | 161 std::map<RenderFrameHostID, RenderFrameHostID> subframe_to_mainframe_map_; |
| 170 subframe_to_mainframe_map_; | |
| 171 | 162 |
| 172 // Map from pending navigations to the DataUseRecorderEntry in | 163 // Map from pending navigations to the DataUseRecorderEntry in |
| 173 // |data_use_recorders_| that the navigation ascribes data use to. | 164 // |data_use_recorders_| that the navigation ascribes data use to. |
| 174 std::unordered_map<content::GlobalRequestID, | 165 std::map<content::GlobalRequestID, DataUseRecorderEntry> |
| 175 DataUseRecorderEntry, | |
| 176 GlobalRequestIDHash> | |
| 177 pending_navigation_data_use_map_; | 166 pending_navigation_data_use_map_; |
| 178 | 167 |
| 179 // Contains the mainframe IDs that are currently visible. | 168 // Contains the mainframe IDs that are currently visible. |
| 180 base::hash_set<RenderFrameHostID> visible_main_render_frames_; | 169 std::set<RenderFrameHostID> visible_main_render_frames_; |
| 181 | 170 |
| 182 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); | 171 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); |
| 183 }; | 172 }; |
| 184 | 173 |
| 185 } // namespace data_use_measurement | 174 } // namespace data_use_measurement |
| 186 | 175 |
| 187 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ | 176 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ |
| OLD | NEW |