1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_
12 #include "base/macros.h"
18 namespace task_management
{
20 // Defines a wrapper of values that will be sent from IO to UI thread upon
21 // reception of bytes read notifications.
22 struct BytesReadParam
{
23 // The PID of the originating process of the URLRequest, if the request is
24 // sent on behalf of another process. Otherwise it's 0.
27 // The unique ID of the host of the child process requestor.
30 // The ID of the IPC route for the URLRequest (this identifies the
31 // RenderView or like-thing in the renderer that the request gets routed
35 // The number of bytes read.
38 BytesReadParam(int origin_pid
,
42 : origin_pid(origin_pid
),
45 byte_count(byte_count
) {
49 // Defines a utility class used to schedule the creation and removal of the
50 // TaskManagerIoThreadHelper on the IO thread.
51 class IoThreadHelperManager
{
53 IoThreadHelperManager();
54 ~IoThreadHelperManager();
57 DISALLOW_COPY_AND_ASSIGN(IoThreadHelperManager
);
60 // Defines a class used by the task manager to receive notifications of the
61 // network bytes read by the various tasks.
62 // This object lives entirely only on the IO thread.
63 class TaskManagerIoThreadHelper
{
65 // Create and delete the instance of this class. They must be called on the IO
67 static void CreateInstance();
68 static void DeleteInstance();
70 // This is used to forward the call to update the network bytes from the
71 // TaskManagerInterface if the new task manager is enabled.
72 static void OnRawBytesRead(const net::URLRequest
& request
,
76 TaskManagerIoThreadHelper();
77 ~TaskManagerIoThreadHelper();
79 // We gather multiple notifications on the IO thread in one second before a
80 // call is made to the following function to start the processing.
81 static void OnMultipleBytesReadIO();
83 // This will update the task manager with the network bytes read.
84 void OnNetworkBytesRead(const net::URLRequest
& request
, int64_t bytes_read
);
86 // This buffer will be filled on IO thread with information about the number
87 // of bytes read from URLRequests.
88 std::vector
<BytesReadParam
> bytes_read_buffer_
;
90 DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper
);
93 } // namespace task_management
95 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_