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

Side by Side Diff: chrome/browser/task_management/providers/child_process_task.cc

Issue 1439213004: Fix various TaskManager bugs and add new enhancements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: auto*& --> auto* Created 5 years, 1 month 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
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/providers/child_process_task.h" 5 #include "chrome/browser/task_management/providers/child_process_task.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/numerics/safe_conversions.h" 8 #include "base/numerics/safe_conversions.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/process_resource_usage.h" 11 #include "chrome/browser/process_resource_usage.h"
12 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/task_management/task_manager_observer.h" 13 #include "chrome/browser/task_management/task_manager_observer.h"
11 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
12 #include "components/nacl/common/nacl_process_type.h" 15 #include "components/nacl/common/nacl_process_type.h"
13 #include "content/public/browser/browser_child_process_host.h" 16 #include "content/public/browser/browser_child_process_host.h"
14 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/child_process_data.h" 18 #include "content/public/browser/child_process_data.h"
16 #include "content/public/common/process_type.h" 19 #include "content/public/common/process_type.h"
17 #include "content/public/common/service_registry.h" 20 #include "content/public/common/service_registry.h"
21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/common/extension_set.h"
18 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
21 26
22 namespace task_management { 27 namespace task_management {
23 28
24 namespace { 29 namespace {
25 30
26 gfx::ImageSkia* g_default_icon = nullptr; 31 gfx::ImageSkia* g_default_icon = nullptr;
27 32
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_GPU_PREFIX); 70 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_GPU_PREFIX);
66 case content::PROCESS_TYPE_PLUGIN: 71 case content::PROCESS_TYPE_PLUGIN:
67 case content::PROCESS_TYPE_PPAPI_PLUGIN: 72 case content::PROCESS_TYPE_PPAPI_PLUGIN:
68 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_PREFIX, 73 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_PREFIX,
69 result_title); 74 result_title);
70 case content::PROCESS_TYPE_PPAPI_BROKER: 75 case content::PROCESS_TYPE_PPAPI_BROKER:
71 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_BROKER_PREFIX, 76 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PLUGIN_BROKER_PREFIX,
72 result_title); 77 result_title);
73 case PROCESS_TYPE_NACL_BROKER: 78 case PROCESS_TYPE_NACL_BROKER:
74 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NACL_BROKER_PREFIX); 79 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NACL_BROKER_PREFIX);
75 case PROCESS_TYPE_NACL_LOADER: 80 case PROCESS_TYPE_NACL_LOADER: {
81 auto* profile_manager = g_browser_process->profile_manager();
82 if (profile_manager) {
83 // TODO(afakhry): Fix the below looping by plumbing a way to get the
84 // profile or the profile path from the child process host if any.
85 auto loaded_profiles = profile_manager->GetLoadedProfiles();
86 for (auto* profile : loaded_profiles) {
87 auto& enabled_extensions =
88 extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
89 auto extension =
90 enabled_extensions.GetExtensionOrAppByURL(GURL(result_title));
91 if (extension) {
92 result_title = base::UTF8ToUTF16(extension->name());
93 break;
94 }
95 }
96 }
76 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, 97 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX,
77 result_title); 98 result_title);
99 }
78 // These types don't need display names or get them from elsewhere. 100 // These types don't need display names or get them from elsewhere.
79 case content::PROCESS_TYPE_BROWSER: 101 case content::PROCESS_TYPE_BROWSER:
80 case content::PROCESS_TYPE_RENDERER: 102 case content::PROCESS_TYPE_RENDERER:
81 case content::PROCESS_TYPE_ZYGOTE: 103 case content::PROCESS_TYPE_ZYGOTE:
82 case content::PROCESS_TYPE_SANDBOX_HELPER: 104 case content::PROCESS_TYPE_SANDBOX_HELPER:
83 case content::PROCESS_TYPE_MAX: 105 case content::PROCESS_TYPE_MAX:
84 break; 106 break;
85 case content::PROCESS_TYPE_UNKNOWN: 107 case content::PROCESS_TYPE_UNKNOWN:
86 NOTREACHED() << "Need localized name for child process type."; 108 NOTREACHED() << "Need localized name for child process type.";
87 } 109 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 content::BrowserThread::PostTask( 142 content::BrowserThread::PostTask(
121 content::BrowserThread::IO, 143 content::BrowserThread::IO,
122 FROM_HERE, 144 FROM_HERE,
123 base::Bind(&ConnectResourceReporterOnIOThread, 145 base::Bind(&ConnectResourceReporterOnIOThread,
124 unique_child_process_id, 146 unique_child_process_id,
125 base::Passed(&usage_reporter))); 147 base::Passed(&usage_reporter)));
126 148
127 return new ProcessResourceUsage(service.Pass()); 149 return new ProcessResourceUsage(service.Pass());
128 } 150 }
129 151
152 bool UsesV8Memory(int process_type) {
153 switch (process_type) {
154 case content::PROCESS_TYPE_UTILITY:
155 case content::PROCESS_TYPE_BROWSER:
156 case content::PROCESS_TYPE_RENDERER:
157 return true;
158
159 default:
160 return false;
161 }
162 }
163
130 } // namespace 164 } // namespace
131 165
132 ChildProcessTask::ChildProcessTask(const content::ChildProcessData& data) 166 ChildProcessTask::ChildProcessTask(const content::ChildProcessData& data)
133 : Task(GetLocalizedTitle(data.name, data.process_type), 167 : Task(GetLocalizedTitle(data.name, data.process_type),
134 GetDefaultIcon(), 168 GetDefaultIcon(),
135 data.handle), 169 data.handle),
136 process_resources_sampler_(CreateProcessResourcesSampler(data.id)), 170 process_resources_sampler_(CreateProcessResourcesSampler(data.id)),
137 v8_memory_allocated_(-1), 171 v8_memory_allocated_(-1),
138 v8_memory_used_(-1), 172 v8_memory_used_(-1),
139 unique_child_process_id_(data.id), 173 unique_child_process_id_(data.id),
140 process_type_(data.process_type) { 174 process_type_(data.process_type),
175 uses_v8_memory_(UsesV8Memory(process_type_)) {
141 } 176 }
142 177
143 ChildProcessTask::~ChildProcessTask() { 178 ChildProcessTask::~ChildProcessTask() {
144 } 179 }
145 180
146 void ChildProcessTask::Refresh(const base::TimeDelta& update_interval, 181 void ChildProcessTask::Refresh(const base::TimeDelta& update_interval,
147 int64 refresh_flags) { 182 int64 refresh_flags) {
148 Task::Refresh(update_interval, refresh_flags); 183 Task::Refresh(update_interval, refresh_flags);
149 184
150 if ((refresh_flags & REFRESH_TYPE_V8_MEMORY) == 0) 185 if ((refresh_flags & REFRESH_TYPE_V8_MEMORY) == 0)
151 return; 186 return;
152 187
188 if (!uses_v8_memory_)
189 return;
190
153 // The child process resources refresh is performed asynchronously, we will 191 // The child process resources refresh is performed asynchronously, we will
154 // invoke it and record the current values (which might be invalid at the 192 // invoke it and record the current values (which might be invalid at the
155 // moment. We can safely ignore that and count on future refresh cycles 193 // moment. We can safely ignore that and count on future refresh cycles
156 // potentially having valid values). 194 // potentially having valid values).
157 process_resources_sampler_->Refresh(base::Closure()); 195 process_resources_sampler_->Refresh(base::Closure());
158 196
159 v8_memory_allocated_ = base::saturated_cast<int64>( 197 v8_memory_allocated_ = base::saturated_cast<int64>(
160 process_resources_sampler_->GetV8MemoryAllocated()); 198 process_resources_sampler_->GetV8MemoryAllocated());
161 v8_memory_used_ = base::saturated_cast<int64>( 199 v8_memory_used_ = base::saturated_cast<int64>(
162 process_resources_sampler_->GetV8MemoryUsed()); 200 process_resources_sampler_->GetV8MemoryUsed());
(...skipping 20 matching lines...) Expand all
183 default: 221 default:
184 return Task::UNKNOWN; 222 return Task::UNKNOWN;
185 } 223 }
186 } 224 }
187 225
188 int ChildProcessTask::GetChildProcessUniqueID() const { 226 int ChildProcessTask::GetChildProcessUniqueID() const {
189 return unique_child_process_id_; 227 return unique_child_process_id_;
190 } 228 }
191 229
192 bool ChildProcessTask::ReportsV8Memory() const { 230 bool ChildProcessTask::ReportsV8Memory() const {
193 return process_resources_sampler_->ReportsV8MemoryStats(); 231 return uses_v8_memory_ && process_resources_sampler_->ReportsV8MemoryStats();
194 } 232 }
195 233
196 int64 ChildProcessTask::GetV8MemoryAllocated() const { 234 int64 ChildProcessTask::GetV8MemoryAllocated() const {
197 return v8_memory_allocated_; 235 return v8_memory_allocated_;
198 } 236 }
199 237
200 int64 ChildProcessTask::GetV8MemoryUsed() const { 238 int64 ChildProcessTask::GetV8MemoryUsed() const {
201 return v8_memory_used_; 239 return v8_memory_used_;
202 } 240 }
203 241
204 } // namespace task_management 242 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/providers/child_process_task.h ('k') | chrome/browser/task_management/providers/task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698