Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if (g_browser_process->profile_manager()) { | |
| 82 auto& enabled_extensions = | |
| 83 extensions::ExtensionRegistry::Get( | |
| 84 ProfileManager::GetActiveUserProfile())->enabled_extensions(); | |
|
afakhry
2015/11/19 01:12:01
What about this? We still need a profile or a brow
ncarter (slow)
2015/11/19 20:06:44
It is not correct to call GetActiveUserProfile lik
afakhry
2015/11/20 20:55:43
Done.
| |
| 85 auto extension = | |
| 86 enabled_extensions.GetExtensionOrAppByURL(GURL(result_title)); | |
| 87 if (extension) | |
| 88 result_title = base::UTF8ToUTF16(extension->name()); | |
| 89 } | |
| 76 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, | 90 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_NACL_PREFIX, |
| 77 result_title); | 91 result_title); |
| 92 } | |
| 78 // These types don't need display names or get them from elsewhere. | 93 // These types don't need display names or get them from elsewhere. |
| 79 case content::PROCESS_TYPE_BROWSER: | 94 case content::PROCESS_TYPE_BROWSER: |
| 80 case content::PROCESS_TYPE_RENDERER: | 95 case content::PROCESS_TYPE_RENDERER: |
| 81 case content::PROCESS_TYPE_ZYGOTE: | 96 case content::PROCESS_TYPE_ZYGOTE: |
| 82 case content::PROCESS_TYPE_SANDBOX_HELPER: | 97 case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 83 case content::PROCESS_TYPE_MAX: | 98 case content::PROCESS_TYPE_MAX: |
| 84 break; | 99 break; |
| 85 case content::PROCESS_TYPE_UNKNOWN: | 100 case content::PROCESS_TYPE_UNKNOWN: |
| 86 NOTREACHED() << "Need localized name for child process type."; | 101 NOTREACHED() << "Need localized name for child process type."; |
| 87 } | 102 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 content::BrowserThread::PostTask( | 135 content::BrowserThread::PostTask( |
| 121 content::BrowserThread::IO, | 136 content::BrowserThread::IO, |
| 122 FROM_HERE, | 137 FROM_HERE, |
| 123 base::Bind(&ConnectResourceReporterOnIOThread, | 138 base::Bind(&ConnectResourceReporterOnIOThread, |
| 124 unique_child_process_id, | 139 unique_child_process_id, |
| 125 base::Passed(&usage_reporter))); | 140 base::Passed(&usage_reporter))); |
| 126 | 141 |
| 127 return new ProcessResourceUsage(service.Pass()); | 142 return new ProcessResourceUsage(service.Pass()); |
| 128 } | 143 } |
| 129 | 144 |
| 145 // Based on |process_type| we return the name of the active user profile that | |
| 146 // started this task (at time of its construction). Some processes are shared | |
| 147 // across profiles and hence we don't show a profile name for them. | |
| 148 base::string16 GetChildProcessProfileName(int process_type) { | |
| 149 if (!g_browser_process->profile_manager()) | |
| 150 return base::string16(); | |
| 151 | |
| 152 switch (process_type) { | |
| 153 case content::PROCESS_TYPE_BROWSER: | |
| 154 case content::PROCESS_TYPE_GPU: | |
| 155 case content::PROCESS_TYPE_ZYGOTE: | |
| 156 case content::PROCESS_TYPE_SANDBOX_HELPER: | |
| 157 case content::PROCESS_TYPE_MAX: | |
| 158 case content::PROCESS_TYPE_UNKNOWN: | |
| 159 return base::string16(); | |
| 160 | |
| 161 default: | |
| 162 return Task::GetProfileNameFromProfile( | |
| 163 ProfileManager::GetActiveUserProfile()); | |
|
ncarter (slow)
2015/11/18 18:39:56
I don't think there's any reason to expect it belo
afakhry
2015/11/19 01:12:01
I assumed that at the time of this task's construc
ncarter (slow)
2015/11/19 20:06:44
No such guarantee; there's no such thing as a curr
| |
| 164 } | |
| 165 } | |
| 166 | |
| 167 bool UsesV8Memory(int process_type) { | |
| 168 switch (process_type) { | |
| 169 case content::PROCESS_TYPE_UTILITY: | |
| 170 case content::PROCESS_TYPE_BROWSER: | |
| 171 case content::PROCESS_TYPE_RENDERER: | |
| 172 return true; | |
| 173 | |
| 174 default: | |
| 175 return false; | |
| 176 } | |
| 177 } | |
| 178 | |
| 130 } // namespace | 179 } // namespace |
| 131 | 180 |
| 132 ChildProcessTask::ChildProcessTask(const content::ChildProcessData& data) | 181 ChildProcessTask::ChildProcessTask(const content::ChildProcessData& data) |
| 133 : Task(GetLocalizedTitle(data.name, data.process_type), | 182 : Task(GetLocalizedTitle(data.name, data.process_type), |
| 134 GetDefaultIcon(), | 183 GetDefaultIcon(), |
| 135 data.handle), | 184 data.handle), |
| 136 process_resources_sampler_(CreateProcessResourcesSampler(data.id)), | 185 process_resources_sampler_(CreateProcessResourcesSampler(data.id)), |
| 137 v8_memory_allocated_(-1), | 186 v8_memory_allocated_(-1), |
| 138 v8_memory_used_(-1), | 187 v8_memory_used_(-1), |
| 188 profile_name_(GetChildProcessProfileName(data.process_type)), | |
| 139 unique_child_process_id_(data.id), | 189 unique_child_process_id_(data.id), |
| 140 process_type_(data.process_type) { | 190 process_type_(data.process_type), |
| 191 uses_v8_memory_(UsesV8Memory(process_type_)) { | |
| 141 } | 192 } |
| 142 | 193 |
| 143 ChildProcessTask::~ChildProcessTask() { | 194 ChildProcessTask::~ChildProcessTask() { |
| 144 } | 195 } |
| 145 | 196 |
| 146 void ChildProcessTask::Refresh(const base::TimeDelta& update_interval, | 197 void ChildProcessTask::Refresh(const base::TimeDelta& update_interval, |
| 147 int64 refresh_flags) { | 198 int64 refresh_flags) { |
| 148 Task::Refresh(update_interval, refresh_flags); | 199 Task::Refresh(update_interval, refresh_flags); |
| 149 | 200 |
| 150 if ((refresh_flags & REFRESH_TYPE_V8_MEMORY) == 0) | 201 if ((refresh_flags & REFRESH_TYPE_V8_MEMORY) == 0) |
| 151 return; | 202 return; |
| 152 | 203 |
| 204 if (!uses_v8_memory_) | |
| 205 return; | |
| 206 | |
| 153 // The child process resources refresh is performed asynchronously, we will | 207 // The child process resources refresh is performed asynchronously, we will |
| 154 // invoke it and record the current values (which might be invalid at the | 208 // 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 | 209 // moment. We can safely ignore that and count on future refresh cycles |
| 156 // potentially having valid values). | 210 // potentially having valid values). |
| 157 process_resources_sampler_->Refresh(base::Closure()); | 211 process_resources_sampler_->Refresh(base::Closure()); |
| 158 | 212 |
| 159 v8_memory_allocated_ = base::saturated_cast<int64>( | 213 v8_memory_allocated_ = base::saturated_cast<int64>( |
| 160 process_resources_sampler_->GetV8MemoryAllocated()); | 214 process_resources_sampler_->GetV8MemoryAllocated()); |
| 161 v8_memory_used_ = base::saturated_cast<int64>( | 215 v8_memory_used_ = base::saturated_cast<int64>( |
| 162 process_resources_sampler_->GetV8MemoryUsed()); | 216 process_resources_sampler_->GetV8MemoryUsed()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 182 return Task::NACL; | 236 return Task::NACL; |
| 183 default: | 237 default: |
| 184 return Task::UNKNOWN; | 238 return Task::UNKNOWN; |
| 185 } | 239 } |
| 186 } | 240 } |
| 187 | 241 |
| 188 int ChildProcessTask::GetChildProcessUniqueID() const { | 242 int ChildProcessTask::GetChildProcessUniqueID() const { |
| 189 return unique_child_process_id_; | 243 return unique_child_process_id_; |
| 190 } | 244 } |
| 191 | 245 |
| 246 base::string16 ChildProcessTask::GetProfileName() const { | |
| 247 return profile_name_; | |
| 248 } | |
| 249 | |
| 192 bool ChildProcessTask::ReportsV8Memory() const { | 250 bool ChildProcessTask::ReportsV8Memory() const { |
| 193 return process_resources_sampler_->ReportsV8MemoryStats(); | 251 return uses_v8_memory_ && process_resources_sampler_->ReportsV8MemoryStats(); |
| 194 } | 252 } |
| 195 | 253 |
| 196 int64 ChildProcessTask::GetV8MemoryAllocated() const { | 254 int64 ChildProcessTask::GetV8MemoryAllocated() const { |
| 197 return v8_memory_allocated_; | 255 return v8_memory_allocated_; |
| 198 } | 256 } |
| 199 | 257 |
| 200 int64 ChildProcessTask::GetV8MemoryUsed() const { | 258 int64 ChildProcessTask::GetV8MemoryUsed() const { |
| 201 return v8_memory_used_; | 259 return v8_memory_used_; |
| 202 } | 260 } |
| 203 | 261 |
| 204 } // namespace task_management | 262 } // namespace task_management |
| OLD | NEW |