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

Side by Side Diff: chrome/browser/task_management/sampling/task_manager_io_thread_helper.cc

Issue 1918423002: Fix TaskmanagerIoThreadHelper bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « chrome/browser/task_management/sampling/task_manager_io_thread_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/task_management/sampling/task_manager_io_thread_helper. h" 5 #include "chrome/browser/task_management/sampling/task_manager_io_thread_helper. h"
6 6
7 #include "chrome/browser/task_management/sampling/task_manager_impl.h" 7 #include "chrome/browser/task_management/sampling/task_manager_impl.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/resource_request_info.h" 9 #include "content/public/browser/resource_request_info.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 // static 53 // static
54 void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request, 54 void TaskManagerIoThreadHelper::OnRawBytesRead(const net::URLRequest& request,
55 int64_t bytes_read) { 55 int64_t bytes_read) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 56 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
57 57
58 if (g_io_thread_helper) 58 if (g_io_thread_helper)
59 g_io_thread_helper->OnNetworkBytesRead(request, bytes_read); 59 g_io_thread_helper->OnNetworkBytesRead(request, bytes_read);
60 } 60 }
61 61
62 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() { 62 TaskManagerIoThreadHelper::TaskManagerIoThreadHelper() : weak_factory_(this) {
63 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 63 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
64 } 64 }
65 65
66 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() { 66 TaskManagerIoThreadHelper::~TaskManagerIoThreadHelper() {
67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
68 } 68 }
69 69
70 // static
71 void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() { 70 void TaskManagerIoThreadHelper::OnMultipleBytesReadIO() {
72 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 71 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
73 72
74 if (!g_io_thread_helper) 73 DCHECK(!bytes_read_buffer_.empty());
75 return;
76
77 DCHECK(!g_io_thread_helper->bytes_read_buffer_.empty());
78 74
79 std::vector<BytesReadParam>* bytes_read_buffer = 75 std::vector<BytesReadParam>* bytes_read_buffer =
80 new std::vector<BytesReadParam>(); 76 new std::vector<BytesReadParam>();
81 g_io_thread_helper->bytes_read_buffer_.swap(*bytes_read_buffer); 77 bytes_read_buffer_.swap(*bytes_read_buffer);
82 78
83 content::BrowserThread::PostTask( 79 content::BrowserThread::PostTask(
84 content::BrowserThread::UI, 80 content::BrowserThread::UI,
85 FROM_HERE, 81 FROM_HERE,
86 base::Bind(&TaskManagerImpl::OnMultipleBytesReadUI, 82 base::Bind(&TaskManagerImpl::OnMultipleBytesReadUI,
87 base::Owned(bytes_read_buffer))); 83 base::Owned(bytes_read_buffer)));
88 } 84 }
89 85
90 void TaskManagerIoThreadHelper::OnNetworkBytesRead( 86 void TaskManagerIoThreadHelper::OnNetworkBytesRead(
91 const net::URLRequest& request, int64_t bytes_read) { 87 const net::URLRequest& request, int64_t bytes_read) {
(...skipping 15 matching lines...) Expand all
107 // plugins - for renderer or browser initiated requests it will be zero. 103 // plugins - for renderer or browser initiated requests it will be zero.
108 int origin_pid = info ? info->GetOriginPID() : 0; 104 int origin_pid = info ? info->GetOriginPID() : 0;
109 105
110 if (bytes_read_buffer_.empty()) { 106 if (bytes_read_buffer_.empty()) {
111 // Schedule a task to process the received bytes requests a second from now. 107 // Schedule a task to process the received bytes requests a second from now.
112 // We're trying to calculate the tasks' network usage speed as bytes per 108 // We're trying to calculate the tasks' network usage speed as bytes per
113 // second so we collect as many requests during one seconds before the below 109 // second so we collect as many requests during one seconds before the below
114 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them 110 // delayed TaskManagerIoThreadHelper::OnMultipleBytesReadIO() process them
115 // after one second from now. 111 // after one second from now.
116 content::BrowserThread::PostDelayedTask( 112 content::BrowserThread::PostDelayedTask(
117 content::BrowserThread::IO, 113 content::BrowserThread::IO, FROM_HERE,
118 FROM_HERE, 114 base::Bind(&TaskManagerIoThreadHelper::OnMultipleBytesReadIO,
119 base::Bind(TaskManagerIoThreadHelper::OnMultipleBytesReadIO), 115 weak_factory_.GetWeakPtr()),
120 base::TimeDelta::FromSeconds(1)); 116 base::TimeDelta::FromSeconds(1));
121 } 117 }
122 118
123 bytes_read_buffer_.push_back( 119 bytes_read_buffer_.push_back(
124 BytesReadParam(origin_pid, child_id, route_id, bytes_read)); 120 BytesReadParam(origin_pid, child_id, route_id, bytes_read));
125 } 121 }
126 122
127 } // namespace task_management 123 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/sampling/task_manager_io_thread_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698