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_
10 #include "base/macros.h"
16 namespace task_management
{
18 // Defines a wrapper of values that will be sent from IO to UI thread upon
19 // reception of bytes read notifications.
20 struct BytesReadParam
{
21 // The PID of the originating process of the URLRequest, if the request is
22 // sent on behalf of another process. Otherwise it's 0.
25 // The unique ID of the host of the child process requestor.
28 // The ID of the IPC route for the URLRequest (this identifies the
29 // RenderView or like-thing in the renderer that the request gets routed
33 // The number of bytes read.
36 BytesReadParam(int origin_pid
,
40 : origin_pid(origin_pid
),
43 byte_count(byte_count
) {
47 // Defines a utility class used to schedule the creation and removal of the
48 // TaskManagerIoThreadHelper on the IO thread.
49 class IoThreadHelperManager
{
51 IoThreadHelperManager();
52 ~IoThreadHelperManager();
55 DISALLOW_COPY_AND_ASSIGN(IoThreadHelperManager
);
58 // Defines a class used by the task manager to receive notifications of the
59 // network bytes read by the various tasks.
60 // This object lives entirely only on the IO thread.
61 class TaskManagerIoThreadHelper
{
63 // Create and delete the instance of this class. They must be called on the IO
65 static void CreateInstance();
66 static void DeleteInstance();
68 // This is used to forward the call to update the network bytes from the
69 // TaskManagerInterface if the new task manager is enabled.
70 static void OnRawBytesRead(const net::URLRequest
& request
, int bytes_read
);
73 TaskManagerIoThreadHelper();
74 ~TaskManagerIoThreadHelper();
76 // We gather multiple notifications on the IO thread in one second before a
77 // call is made to the following function to start the processing.
78 static void OnMultipleBytesReadIO();
80 // This will update the task manager with the network bytes read.
81 void OnNetworkBytesRead(const net::URLRequest
& request
, int bytes_read
);
83 // This buffer will be filled on IO thread with information about the number
84 // of bytes read from URLRequests.
85 std::vector
<BytesReadParam
> bytes_read_buffer_
;
87 DISALLOW_COPY_AND_ASSIGN(TaskManagerIoThreadHelper
);
90 } // namespace task_management
92 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_MANAGER_IO_THREAD_HELPER_H_