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

Unified Diff: chrome/browser/task_manager/sampling/task_manager_impl.cc

Issue 2964543002: TaskManager: use an unordered_map for tracking network usage (Closed)
Patch Set: fixed nits from lgtm Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/task_manager/sampling/task_manager_impl.cc
diff --git a/chrome/browser/task_manager/sampling/task_manager_impl.cc b/chrome/browser/task_manager/sampling/task_manager_impl.cc
index 9cae9908ef87860914bc22bc088d21052aab0ee8..9885a76284c4de0d12be92c6caddc5a1f37a90aa 100644
--- a/chrome/browser/task_manager/sampling/task_manager_impl.cc
+++ b/chrome/browser/task_manager/sampling/task_manager_impl.cc
@@ -455,22 +455,29 @@ void TaskManagerImpl::TaskUnresponsive(Task* task) {
}
// static
-void TaskManagerImpl::OnMultipleBytesTransferredUI(
- std::vector<BytesTransferredParam>* params) {
+void TaskManagerImpl::OnMultipleBytesTransferredUI(BytesTransferredMap params) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(params);
+ for (const auto& entry : params) {
+ const BytesTransferredKey& process_info = entry.first;
+ const BytesTransferredParam& bytes_transferred = entry.second;
- for (BytesTransferredParam& param : *params) {
- if (!GetInstance()->UpdateTasksWithBytesTransferred(param)) {
+ if (!GetInstance()->UpdateTasksWithBytesTransferred(process_info,
+ bytes_transferred)) {
// We can't match a task to the notification. That might mean the
// tab that started a download was closed, or the request may have had
// no originating task associated with it in the first place.
// We attribute orphaned/unaccounted activity to the Browser process.
- DCHECK(param.origin_pid || (param.child_id != -1));
-
- param.origin_pid = 0;
- param.child_id = param.route_id = -1;
- GetInstance()->UpdateTasksWithBytesTransferred(param);
+ DCHECK(process_info.origin_pid || (process_info.child_id != -1));
+ // Since the key is meant to be immutable we create a fake key for the
+ // purpose of attributing the orphaned/unaccounted activity to the Browser
+ // process.
+ int dummy_origin_pid = 0;
+ int dummy_child_id = -1;
+ int dummy_route_id = -1;
+ BytesTransferredKey dummy_key = {dummy_origin_pid, dummy_child_id,
+ dummy_route_id};
+ GetInstance()->UpdateTasksWithBytesTransferred(dummy_key,
+ bytes_transferred);
}
}
}
@@ -507,7 +514,8 @@ void TaskManagerImpl::StartUpdating() {
for (const auto& provider : task_providers_)
provider->SetObserver(this);
- io_thread_helper_manager_.reset(new IoThreadHelperManager);
+ io_thread_helper_manager_.reset(new IoThreadHelperManager(
+ base::BindRepeating(&TaskManagerImpl::OnMultipleBytesTransferredUI)));
}
void TaskManagerImpl::StopUpdating() {
@@ -539,11 +547,11 @@ Task* TaskManagerImpl::GetTaskByPidOrRoute(int origin_pid,
}
bool TaskManagerImpl::UpdateTasksWithBytesTransferred(
+ const BytesTransferredKey& key,
const BytesTransferredParam& param) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- Task* task =
- GetTaskByPidOrRoute(param.origin_pid, param.child_id, param.route_id);
+ Task* task = GetTaskByPidOrRoute(key.origin_pid, key.child_id, key.route_id);
if (task) {
task->OnNetworkBytesRead(param.byte_read_count);
task->OnNetworkBytesSent(param.byte_sent_count);

Powered by Google App Engine
This is Rietveld 408576698