Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / task_management / sampling / task_manager_io_thread_helper.h
blobba301b2e8d62712d7d78f8d23aa3c8d1eb658dd7
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_
8 #include <stdint.h>
10 #include <vector>
12 #include "base/macros.h"
14 namespace net {
15 class URLRequest;
16 } // namespace net
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.
25 int origin_pid;
27 // The unique ID of the host of the child process requestor.
28 int child_id;
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
32 // to).
33 int route_id;
35 // The number of bytes read.
36 int64_t byte_count;
38 BytesReadParam(int origin_pid,
39 int child_id,
40 int route_id,
41 int64_t byte_count)
42 : origin_pid(origin_pid),
43 child_id(child_id),
44 route_id(route_id),
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 {
52 public:
53 IoThreadHelperManager();
54 ~IoThreadHelperManager();
56 private:
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 {
64 public:
65 // Create and delete the instance of this class. They must be called on the IO
66 // thread.
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,
73 int64_t bytes_read);
75 private:
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_