| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/renderer_resource.h" | 5 #include "chrome/browser/task_manager/renderer_resource.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "chrome/browser/devtools/devtools_window.h" | 8 #include "chrome/browser/devtools/devtools_window.h" |
| 9 #include "chrome/browser/process_resource_usage.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/task_manager/resource_provider.h" | 11 #include "chrome/browser/task_manager/resource_provider.h" |
| 11 #include "chrome/browser/task_manager/task_manager_util.h" | 12 #include "chrome/browser/task_manager/task_manager_util.h" |
| 12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/common/service_registry.h" |
| 15 | 17 |
| 16 namespace task_manager { | 18 namespace task_manager { |
| 17 | 19 |
| 18 RendererResource::RendererResource(base::ProcessHandle process, | 20 RendererResource::RendererResource(base::ProcessHandle process, |
| 19 content::RenderViewHost* render_view_host) | 21 content::RenderViewHost* render_view_host) |
| 20 : process_(process), | 22 : process_(process), |
| 21 render_view_host_(render_view_host), | 23 render_view_host_(render_view_host), |
| 22 pending_stats_update_(false), | 24 pending_stats_update_(false) { |
| 23 v8_memory_allocated_(0), | |
| 24 v8_memory_used_(0), | |
| 25 pending_v8_memory_allocated_update_(false) { | |
| 26 // We cache the process and pid as when a Tab/BackgroundContents is closed the | 25 // We cache the process and pid as when a Tab/BackgroundContents is closed the |
| 27 // process reference becomes NULL and the TaskManager still needs it. | 26 // process reference becomes NULL and the TaskManager still needs it. |
| 28 pid_ = base::GetProcId(process_); | |
| 29 unique_process_id_ = render_view_host_->GetProcess()->GetID(); | 27 unique_process_id_ = render_view_host_->GetProcess()->GetID(); |
| 30 memset(&stats_, 0, sizeof(stats_)); | 28 memset(&stats_, 0, sizeof(stats_)); |
| 29 ResourceUsageReporterPtr service; |
| 30 content::ServiceRegistry* service_registry = |
| 31 render_view_host_->GetProcess()->GetServiceRegistry(); |
| 32 if (service_registry) |
| 33 service_registry->ConnectToRemoteService(&service); |
| 34 process_resource_usage_.reset(new ProcessResourceUsage(service.Pass())); |
| 31 } | 35 } |
| 32 | 36 |
| 33 RendererResource::~RendererResource() { | 37 RendererResource::~RendererResource() { |
| 34 } | 38 } |
| 35 | 39 |
| 36 void RendererResource::Refresh() { | 40 void RendererResource::Refresh() { |
| 37 if (!pending_stats_update_) { | 41 if (!pending_stats_update_) { |
| 38 render_view_host_->Send(new ChromeViewMsg_GetCacheResourceStats); | 42 render_view_host_->Send(new ChromeViewMsg_GetCacheResourceStats); |
| 39 pending_stats_update_ = true; | 43 pending_stats_update_ = true; |
| 40 } | 44 } |
| 41 if (!pending_v8_memory_allocated_update_) { | 45 process_resource_usage_->Refresh(base::Closure()); |
| 42 render_view_host_->Send(new ChromeViewMsg_GetV8HeapStats); | |
| 43 pending_v8_memory_allocated_update_ = true; | |
| 44 } | |
| 45 } | 46 } |
| 46 | 47 |
| 47 blink::WebCache::ResourceTypeStats | 48 blink::WebCache::ResourceTypeStats |
| 48 RendererResource::GetWebCoreCacheStats() const { | 49 RendererResource::GetWebCoreCacheStats() const { |
| 49 return stats_; | 50 return stats_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 size_t RendererResource::GetV8MemoryAllocated() const { | 53 size_t RendererResource::GetV8MemoryAllocated() const { |
| 53 return v8_memory_allocated_; | 54 return process_resource_usage_->GetV8MemoryAllocated(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 size_t RendererResource::GetV8MemoryUsed() const { | 57 size_t RendererResource::GetV8MemoryUsed() const { |
| 57 return v8_memory_used_; | 58 return process_resource_usage_->GetV8MemoryUsed(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void RendererResource::NotifyResourceTypeStats( | 61 void RendererResource::NotifyResourceTypeStats( |
| 61 const blink::WebCache::ResourceTypeStats& stats) { | 62 const blink::WebCache::ResourceTypeStats& stats) { |
| 62 stats_ = stats; | 63 stats_ = stats; |
| 63 pending_stats_update_ = false; | 64 pending_stats_update_ = false; |
| 64 } | 65 } |
| 65 | 66 |
| 66 void RendererResource::NotifyV8HeapStats( | |
| 67 size_t v8_memory_allocated, size_t v8_memory_used) { | |
| 68 v8_memory_allocated_ = v8_memory_allocated; | |
| 69 v8_memory_used_ = v8_memory_used; | |
| 70 pending_v8_memory_allocated_update_ = false; | |
| 71 } | |
| 72 | |
| 73 base::string16 RendererResource::GetProfileName() const { | 67 base::string16 RendererResource::GetProfileName() const { |
| 74 return util::GetProfileNameFromInfoCache(Profile::FromBrowserContext( | 68 return util::GetProfileNameFromInfoCache(Profile::FromBrowserContext( |
| 75 render_view_host_->GetProcess()->GetBrowserContext())); | 69 render_view_host_->GetProcess()->GetBrowserContext())); |
| 76 } | 70 } |
| 77 | 71 |
| 78 base::ProcessHandle RendererResource::GetProcess() const { | 72 base::ProcessHandle RendererResource::GetProcess() const { |
| 79 return process_; | 73 return process_; |
| 80 } | 74 } |
| 81 | 75 |
| 82 int RendererResource::GetUniqueChildProcessId() const { | 76 int RendererResource::GetUniqueChildProcessId() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 | 91 |
| 98 bool RendererResource::ReportsV8MemoryStats() const { | 92 bool RendererResource::ReportsV8MemoryStats() const { |
| 99 return true; | 93 return true; |
| 100 } | 94 } |
| 101 | 95 |
| 102 bool RendererResource::SupportNetworkUsage() const { | 96 bool RendererResource::SupportNetworkUsage() const { |
| 103 return true; | 97 return true; |
| 104 } | 98 } |
| 105 | 99 |
| 106 } // namespace task_manager | 100 } // namespace task_manager |
| OLD | NEW |