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

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: Updated from first CR Created 3 years, 6 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..963e177665cc898c6061e1b152b8093d53acb62a 100644
--- a/chrome/browser/task_manager/sampling/task_manager_impl.cc
+++ b/chrome/browser/task_manager/sampling/task_manager_impl.cc
@@ -455,22 +455,24 @@ void TaskManagerImpl::TaskUnresponsive(Task* task) {
}
// static
-void TaskManagerImpl::OnMultipleBytesTransferredUI(
- std::vector<BytesTransferredParam>* params) {
+void TaskManagerImpl::OnMultipleBytesTransferredUI(BytesTransferredMap params) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
ncarter (slow) 2017/06/30 20:08:28 Inside the for loop below, prefer "const auto&" to
cburn 2017/07/05 16:30:05 Done.
- DCHECK(params);
-
- for (BytesTransferredParam& param : *params) {
- if (!GetInstance()->UpdateTasksWithBytesTransferred(param)) {
+ for (auto it : params) {
ncarter (slow) 2017/06/30 20:08:28 The name |it|, by convention, suggests that this i
cburn 2017/07/05 16:30:05 I went with entry. I may try to go through and cha
+ if (!GetInstance()->UpdateTasksWithBytesTransferred(it.first, it.second)) {
ncarter (slow) 2017/06/30 20:08:28 The loop body might get more readable if you creat
cburn 2017/07/05 16:30:05 Done. I am all for making loops more readable.
// 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(it.first.origin_pid || (it.first.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, it.second);
}
}
}
@@ -507,7 +509,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 +542,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