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

Side by Side Diff: components/data_use_measurement/core/data_use_recorder.h

Issue 2947973002: Support moving pending requests from one DataUseRecorder to another (Closed)
Patch Set: Created 3 years, 6 months 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
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 COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_ 5 #ifndef COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_
6 #define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_ 6 #define COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <map>
tbansal1 2017/06/23 22:11:21 nit: line break before #include <map>
Raj 2017/06/26 21:40:22 Done
9 10
10 #include "base/containers/hash_tables.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/supports_user_data.h" 12 #include "base/supports_user_data.h"
13 #include "components/data_use_measurement/core/data_use.h" 13 #include "components/data_use_measurement/core/data_use.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 15
16 namespace net { 16 namespace net {
17 class URLRequest; 17 class URLRequest;
18 } 18 }
19 19
20 namespace data_use_measurement { 20 namespace data_use_measurement {
21 21
22 // Tracks all network data used by a single high level entity. An entity 22 // Tracks all network data used by a single high level entity. An entity
23 // can make multiple URLRequests, so there is a one:many relationship between 23 // can make multiple URLRequests, so there is a one:many relationship between
24 // DataUseRecorders and URLRequests. Data used by each URLRequest will be 24 // DataUseRecorders and URLRequests. Data used by each URLRequest will be
25 // tracked by exactly one DataUseRecorder. 25 // tracked by exactly one DataUseRecorder.
26 class DataUseRecorder { 26 class DataUseRecorder {
27 public: 27 public:
28 // Stores network data used by a URLRequest.
29 struct URLRequestDataUse {
30 URLRequestDataUse() : bytes_sent(0), bytes_received(0) {}
31
rajendrant 2017/06/20 21:34:00 base::TimeTicks start_time will be added in a late
tbansal1 2017/06/26 21:44:28 Acknowledged.
32 int64_t bytes_sent;
33 int64_t bytes_received;
tbansal1 2017/06/23 22:11:22 For consistency, it would be better to have bytes_
Raj 2017/06/26 21:40:22 Done
34
35 private:
36 DISALLOW_COPY_AND_ASSIGN(URLRequestDataUse);
37 };
38
28 explicit DataUseRecorder(DataUse::TrafficType traffic_type); 39 explicit DataUseRecorder(DataUse::TrafficType traffic_type);
29 virtual ~DataUseRecorder(); 40 virtual ~DataUseRecorder();
30 41
31 // Returns the actual data used by the entity being tracked. 42 // Returns the actual data used by the entity being tracked.
32 DataUse& data_use() { return data_use_; } 43 DataUse& data_use() { return data_use_; }
33 const base::hash_set<net::URLRequest*>& pending_url_requests() const { 44 const std::map<net::URLRequest*, URLRequestDataUse>& pending_url_requests()
45 const {
34 return pending_url_requests_; 46 return pending_url_requests_;
35 } 47 }
36 const net::URLRequest* main_url_request() const { return main_url_request_; } 48 const net::URLRequest* main_url_request() const { return main_url_request_; }
37 49
38 void set_main_url_request(const net::URLRequest* request) { 50 void set_main_url_request(const net::URLRequest* request) {
39 main_url_request_ = request; 51 main_url_request_ = request;
40 } 52 }
41 53
42 bool is_visible() const { return is_visible_; } 54 bool is_visible() const { return is_visible_; }
43 55
44 void set_is_visible(bool is_visible) { is_visible_ = is_visible; } 56 void set_is_visible(bool is_visible) { is_visible_ = is_visible; }
45 57
46 uint64_t page_transition() const { return page_transition_; } 58 uint64_t page_transition() const { return page_transition_; }
47 59
48 void set_page_transition(uint64_t page_transition) { 60 void set_page_transition(uint64_t page_transition) {
49 page_transition_ = page_transition; 61 page_transition_ = page_transition;
50 } 62 }
51 63
52 // Returns whether data use is complete and no additional data can be used 64 // Returns whether data use is complete and no additional data can be used
53 // by the entity tracked by this recorder. For example, 65 // by the entity tracked by this recorder. For example,
54 bool IsDataUseComplete(); 66 bool IsDataUseComplete();
55 67
56 // Adds |request| to the list of pending URLRequests that ascribe data use to 68 // Adds |request| to the list of pending URLRequests that ascribe data use to
57 // this recorder. 69 // this recorder.
58 void AddPendingURLRequest(net::URLRequest* request); 70 void AddPendingURLRequest(net::URLRequest* request);
59 71
72 // Moves pending |request| from |this| recorder to |other| recorder, and
73 // updates the data use for the recorders.
74 void MovePendingURLRequest(DataUseRecorder* other, net::URLRequest* request);
75
60 // Clears the list of pending URLRequests that ascribe data use to this 76 // Clears the list of pending URLRequests that ascribe data use to this
61 // recorder. 77 // recorder.
62 void RemoveAllPendingURLRequests(); 78 void RemoveAllPendingURLRequests();
63 79
64 // Merge another DataUseRecorder to this instance. 80 // Merge another DataUseRecorder to this instance.
65 void MergeFrom(DataUseRecorder* other); 81 void MergeFrom(DataUseRecorder* other);
66 82
67 // Network Delegate methods: 83 // Network Delegate methods:
68 void OnBeforeUrlRequest(net::URLRequest* request); 84 void OnBeforeUrlRequest(net::URLRequest* request);
69 void OnUrlRequestDestroyed(net::URLRequest* request); 85 void OnUrlRequestDestroyed(net::URLRequest* request);
70 void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent); 86 void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent);
71 void OnNetworkBytesReceived(net::URLRequest* request, int64_t bytes_received); 87 void OnNetworkBytesReceived(net::URLRequest* request, int64_t bytes_received);
72 88
73 private: 89 private:
90 // Updates the network data use for the url request.
91 void UpdateNetworkByteCounts(net::URLRequest* request,
92 int64_t bytes_received,
93 int64_t bytes_sent);
94
74 // Pending URLRequests whose data is being tracked by this DataUseRecorder. 95 // Pending URLRequests whose data is being tracked by this DataUseRecorder.
75 base::hash_set<net::URLRequest*> pending_url_requests_; 96 std::map<net::URLRequest*, URLRequestDataUse> pending_url_requests_;
76
77 // Data sources other than URLRequests, whose data is being tracked by this
78 // DataUseRecorder.
79 base::hash_set<const void*> pending_data_sources_;
80 97
81 // The main frame URLRequest for page loads. Null if this is not tracking a 98 // The main frame URLRequest for page loads. Null if this is not tracking a
82 // page load. 99 // page load.
83 const net::URLRequest* main_url_request_; 100 const net::URLRequest* main_url_request_;
84 101
85 // The network data use measured by this DataUseRecorder. 102 // The network data use measured by this DataUseRecorder.
86 DataUse data_use_; 103 DataUse data_use_;
87 104
88 // Whether the entity that owns this data use is currently visible. 105 // Whether the entity that owns this data use is currently visible.
89 bool is_visible_; 106 bool is_visible_;
90 107
91 // ui::PageTransition casted as a uint64_t. 108 // ui::PageTransition casted as a uint64_t.
92 uint64_t page_transition_; 109 uint64_t page_transition_;
93 110
94 DISALLOW_COPY_AND_ASSIGN(DataUseRecorder); 111 DISALLOW_COPY_AND_ASSIGN(DataUseRecorder);
95 }; 112 };
96 113
97 } // namespace data_use_measurement 114 } // namespace data_use_measurement
98 115
99 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_ 116 #endif // COMPONENTS_DATA_USE_MEASUREMENT_CORE_DATA_USE_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698