| 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, |
| 56 | 59 bool can_create_new) override; |
| 57 // Called before a request is sent. | |
| 58 void OnBeforeUrlRequest(net::URLRequest* request) override; | 60 void OnBeforeUrlRequest(net::URLRequest* request) override; |
| 59 | |
| 60 // Called when a URLRequest is being destroyed. | |
| 61 void OnUrlRequestDestroyed(net::URLRequest* request) override; | 61 void OnUrlRequestDestroyed(net::URLRequest* request) override; |
| 62 | |
| 63 std::unique_ptr<URLRequestClassifier> CreateURLRequestClassifier() | 62 std::unique_ptr<URLRequestClassifier> CreateURLRequestClassifier() |
| 64 const override; | 63 const override; |
| 65 | 64 |
| 66 // Called when a render frame host is created. | 65 // Called when a render frame host is created. |
| 67 void RenderFrameCreated(int render_process_id, | 66 void RenderFrameCreated(int render_process_id, |
| 68 int render_frame_id, | 67 int render_frame_id, |
| 69 int parent_render_process_id, | 68 int parent_render_process_id, |
| 70 int parent_render_frame_id); | 69 int parent_render_frame_id); |
| 71 | 70 |
| 72 // Called when a render frame host is deleted. | 71 // Called when a render frame host is deleted. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 84 // Called when a main frame navigation is ready to be committed in a | 83 // Called when a main frame navigation is ready to be committed in a |
| 85 // renderer. | 84 // renderer. |
| 86 void ReadyToCommitMainFrameNavigation( | 85 void ReadyToCommitMainFrameNavigation( |
| 87 GURL gurl, | 86 GURL gurl, |
| 88 content::GlobalRequestID global_request_id, | 87 content::GlobalRequestID global_request_id, |
| 89 int render_process_id, | 88 int render_process_id, |
| 90 int render_frame_id, | 89 int render_frame_id, |
| 91 bool is_same_page_navigation, | 90 bool is_same_page_navigation, |
| 92 void* navigation_handle); | 91 void* navigation_handle); |
| 93 | 92 |
| 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 | 93 |
| 100 private: | 94 private: |
| 101 // Use as a key in the render frame map. Corresponds to a unique | 95 friend class ChromeDataUseAscriberTest; |
| 102 // RenderFrameHost. | |
| 103 typedef std::pair<int, int> RenderFrameHostID; | |
| 104 | 96 |
| 105 // Entry in the |data_use_recorders_| list which owns all instances of | 97 // Entry in the |data_use_recorders_| list which owns all instances of |
| 106 // DataUseRecorder. | 98 // DataUseRecorder. |
| 107 typedef std::list<std::unique_ptr<data_use_measurement::DataUseRecorder>>:: | 99 typedef std::list<ChromeDataUseRecorder> DataUseRecorderList; |
| 108 iterator DataUseRecorderEntry; | 100 typedef DataUseRecorderList::iterator DataUseRecorderEntry; |
| 109 | 101 |
| 110 struct GlobalRequestIDHash { | 102 struct GlobalRequestIDHash { |
| 111 public: | 103 public: |
| 112 std::size_t operator()(const content::GlobalRequestID& x) const { | 104 std::size_t operator()(const content::GlobalRequestID& x) const { |
| 113 return base::HashInts(x.child_id, x.request_id); | 105 return base::HashInts(x.child_id, x.request_id); |
| 114 } | 106 } |
| 115 }; | 107 }; |
| 116 | 108 |
| 117 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { | 109 class DataUseRecorderEntryAsUserData : public base::SupportsUserData::Data { |
| 118 public: | 110 public: |
| 119 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); | 111 explicit DataUseRecorderEntryAsUserData(DataUseRecorderEntry entry); |
| 120 | 112 |
| 121 ~DataUseRecorderEntryAsUserData() override; | 113 ~DataUseRecorderEntryAsUserData() override; |
| 122 | 114 |
| 123 DataUseRecorderEntry recorder_entry() { return entry_; } | 115 DataUseRecorderEntry recorder_entry() { return entry_; } |
| 124 | 116 |
| 125 static const void* kUserDataKey; | 117 static const void* kUserDataKey; |
| 126 | 118 |
| 127 private: | 119 private: |
| 128 DataUseRecorderEntry entry_; | 120 DataUseRecorderEntry entry_; |
| 129 }; | 121 }; |
| 130 | 122 |
| 131 void DeletePendingNavigationEntry(content::GlobalRequestID global_request_id); | 123 DataUseRecorderEntry GetDataUseRecorderEntry(net::URLRequest* request, |
| 124 bool can_create_new); |
| 125 |
| 126 void OnDataUseCompleted(DataUseRecorderEntry entry); |
| 127 |
| 128 DataUseRecorderEntry CreateNewDataUseRecorder(net::URLRequest* request); |
| 129 |
| 130 bool IsRecorderInPendingNavigationMap(net::URLRequest* request); |
| 131 |
| 132 bool IsRecorderInRenderFrameMap(net::URLRequest* request); |
| 132 | 133 |
| 133 // Owner for all instances of DataUseRecorder. An instance is kept in this | 134 // Owner for all instances of DataUseRecorder. An instance is kept in this |
| 134 // list if any entity (render frame hosts, URLRequests, pending navigations) | 135 // list if any entity (render frame hosts, URLRequests, pending navigations) |
| 135 // that ascribe data use to the instance exists, and deleted when all | 136 // that ascribe data use to the instance exists, and deleted when all |
| 136 // ascribing entities go away. | 137 // ascribing entities go away. |
| 137 std::list<std::unique_ptr<DataUseRecorder>> data_use_recorders_; | 138 DataUseRecorderList data_use_recorders_; |
| 138 | 139 |
| 139 // Map from RenderFrameHost to the DataUseRecorderEntry in | 140 // Map from RenderFrameHost to the DataUseRecorderEntry in |
| 140 // |data_use_recorders_| that the frame ascribe data use to. | 141 // |data_use_recorders_| that the frame ascribe data use to. |
| 141 base::hash_map<RenderFrameHostID, DataUseRecorderEntry> | 142 base::hash_map<RenderFrameHostID, DataUseRecorderEntry> |
| 142 render_frame_data_use_map_; | 143 render_frame_data_use_map_; |
| 143 | 144 |
| 144 // Map from pending navigations to the DataUseRecorderEntry in | 145 // Map from pending navigations to the DataUseRecorderEntry in |
| 145 // |data_use_recorders_| that the navigation ascribes data use to. | 146 // |data_use_recorders_| that the navigation ascribes data use to. |
| 146 std::unordered_map<content::GlobalRequestID, | 147 std::unordered_map<content::GlobalRequestID, |
| 147 DataUseRecorderEntry, | 148 DataUseRecorderEntry, |
| 148 GlobalRequestIDHash> | 149 GlobalRequestIDHash> |
| 149 pending_navigation_data_use_map_; | 150 pending_navigation_data_use_map_; |
| 150 | 151 |
| 151 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); | 152 DISALLOW_COPY_AND_ASSIGN(ChromeDataUseAscriber); |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 } // namespace data_use_measurement | 155 } // namespace data_use_measurement |
| 155 | 156 |
| 156 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ | 157 #endif // CHROME_BROWSER_DATA_USE_MEASUREMENT_CHROME_DATA_USE_ASCRIBER_H_ |
| OLD | NEW |