Chromium Code Reviews| Index: chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h |
| diff --git a/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h b/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h |
| index 321025fa5f4d781bc2c6e88919824e0aa9b51215..cc83d271998ee393bfcf92dabec6454e73172ff6 100644 |
| --- a/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h |
| +++ b/chrome/browser/task_manager/sampling/task_manager_io_thread_helper.h |
| @@ -7,8 +7,10 @@ |
| #include <stdint.h> |
| -#include <vector> |
| +#include <unordered_map> |
| +#include "base/callback.h" |
| +#include "base/hash.h" |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| @@ -18,9 +20,10 @@ class URLRequest; |
| namespace task_manager { |
| -// Defines a wrapper of values that will be sent from IO to UI thread upon |
| -// reception and transmission of bytes notifications. |
| -struct BytesTransferredParam { |
| +// Identifies the initiator of a network request, either by a (child_id, |
| +// route_id) tuple, and/or via an OS process id. |
| +// BytesTransferredKey supports hashing and may be used as an unordered_map key. |
| +struct BytesTransferredKey { |
| // The PID of the originating process of the URLRequest, if the request is |
| // sent on behalf of another process. Otherwise it's 0. |
| int origin_pid; |
| @@ -33,29 +36,34 @@ struct BytesTransferredParam { |
| // to). |
| int route_id; |
| + struct Hasher { |
| + size_t operator()(const BytesTransferredKey& key) const; |
| + }; |
| + |
| + bool operator==(const BytesTransferredKey& other) const; |
| +}; |
| + |
| +// This is the entry of the unordered map that tracks bytes transfered by task. |
| +struct BytesTransferredParam { |
| // The number of bytes read. |
| - int64_t byte_read_count; |
| + int64_t byte_read_count = 0; |
| // The number of bytes sent. |
| - int64_t byte_sent_count; |
| - |
| - BytesTransferredParam(int origin_pid, |
| - int child_id, |
| - int route_id, |
| - int64_t byte_read_count, |
| - int64_t byte_sent_count) |
| - : origin_pid(origin_pid), |
| - child_id(child_id), |
| - route_id(route_id), |
| - byte_read_count(byte_read_count), |
| - byte_sent_count(byte_sent_count) {} |
| + int64_t byte_sent_count = 0; |
| }; |
| +using BytesTransferredMap = std::unordered_map<BytesTransferredKey, |
| + BytesTransferredParam, |
| + BytesTransferredKey::Hasher>; |
| + |
| +using BytesTransferredCallback = |
| + base::RepeatingCallback<void(BytesTransferredMap)>; |
| + |
| // Defines a utility class used to schedule the creation and removal of the |
| // TaskManagerIoThreadHelper on the IO thread. |
| class IoThreadHelperManager { |
| public: |
| - IoThreadHelperManager(); |
| + explicit IoThreadHelperManager(BytesTransferredCallback result_callback); |
|
afakhry
2017/07/05 19:01:21
Nit: Please document when this callback will be in
cburn
2017/07/06 17:30:41
Done.
|
| ~IoThreadHelperManager(); |
| private: |
| @@ -69,21 +77,17 @@ class TaskManagerIoThreadHelper { |
| public: |
| // Create and delete the instance of this class. They must be called on the IO |
| // thread. |
| - static void CreateInstance(); |
| + static void CreateInstance(BytesTransferredCallback result_callback); |
| static void DeleteInstance(); |
| - // This is used to forward the call to update the network bytes with read |
| - // bytes from the TaskManagerInterface if the new task manager is enabled. |
| - static void OnRawBytesRead(const net::URLRequest& request, |
| - int64_t bytes_read); |
| - |
| - // This is used to forward the call to update the network bytes with sent |
| - // bytes from the TaskManagerInterface if the new task manager is enabled. |
| - static void OnRawBytesSent(const net::URLRequest& request, |
| - int64_t bytes_sent); |
| + // This is used to forward the call to update the network bytes with |
| + // transferred bytes from the TaskManagerInterface. |
| + static void OnRawBytesTransferred(BytesTransferredKey key, |
| + int64_t bytes_read, |
| + int64_t bytes_sent); |
| private: |
| - TaskManagerIoThreadHelper(); |
| + explicit TaskManagerIoThreadHelper(BytesTransferredCallback result_callback); |
| ~TaskManagerIoThreadHelper(); |
| // We gather multiple notifications on the IO thread in one second before a |
| @@ -92,13 +96,15 @@ class TaskManagerIoThreadHelper { |
| void OnMultipleBytesTransferredIO(); |
| // This will update the task manager with the network bytes read. |
| - void OnNetworkBytesTransferred(const net::URLRequest& request, |
| + void OnNetworkBytesTransferred(BytesTransferredKey key, |
| int64_t bytes_read, |
| int64_t bytes_sent); |
| - // This buffer will be filled on IO thread with information about the number |
| - // of bytes transferred from URLRequests. |
| - std::vector<BytesTransferredParam> bytes_transferred_buffer_; |
| + // This unordered_map will be filled on IO thread with information about the |
| + // number of bytes transferred from URLRequests. |
| + BytesTransferredMap bytes_transferred_unordered_map_; |
| + |
| + BytesTransferredCallback result_callback_; |
| base::WeakPtrFactory<TaskManagerIoThreadHelper> weak_factory_; |