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
3 // found in the LICENSE file.
5 #include "chrome/browser/task_manager/renderer_resource.h"
7 #include "base/basictypes.h"
8 #include "chrome/browser/devtools/devtools_window.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/task_manager/resource_provider.h"
11 #include "chrome/browser/task_manager/task_manager_util.h"
12 #include "chrome/common/render_messages.h"
13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h"
16 namespace task_manager
{
18 RendererResource::RendererResource(base::ProcessHandle process
,
19 content::RenderViewHost
* render_view_host
)
21 render_view_host_(render_view_host
),
22 pending_stats_update_(false),
23 v8_memory_allocated_(0),
25 pending_v8_memory_allocated_update_(false) {
26 // 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.
28 pid_
= base::GetProcId(process_
);
29 unique_process_id_
= render_view_host_
->GetProcess()->GetID();
30 memset(&stats_
, 0, sizeof(stats_
));
33 RendererResource::~RendererResource() {
36 void RendererResource::Refresh() {
37 if (!pending_stats_update_
) {
38 render_view_host_
->Send(new ChromeViewMsg_GetCacheResourceStats
);
39 pending_stats_update_
= true;
41 if (!pending_v8_memory_allocated_update_
) {
42 render_view_host_
->Send(new ChromeViewMsg_GetV8HeapStats
);
43 pending_v8_memory_allocated_update_
= true;
47 blink::WebCache::ResourceTypeStats
48 RendererResource::GetWebCoreCacheStats() const {
52 size_t RendererResource::GetV8MemoryAllocated() const {
53 return v8_memory_allocated_
;
56 size_t RendererResource::GetV8MemoryUsed() const {
57 return v8_memory_used_
;
60 void RendererResource::NotifyResourceTypeStats(
61 const blink::WebCache::ResourceTypeStats
& stats
) {
63 pending_stats_update_
= false;
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;
73 base::string16
RendererResource::GetProfileName() const {
74 return util::GetProfileNameFromInfoCache(Profile::FromBrowserContext(
75 render_view_host_
->GetProcess()->GetBrowserContext()));
78 base::ProcessHandle
RendererResource::GetProcess() const {
82 int RendererResource::GetUniqueChildProcessId() const {
83 return unique_process_id_
;
86 Resource::Type
RendererResource::GetType() const {
90 int RendererResource::GetRoutingID() const {
91 return render_view_host_
->GetRoutingID();
94 bool RendererResource::ReportsCacheStats() const {
98 bool RendererResource::ReportsV8MemoryStats() const {
102 bool RendererResource::SupportNetworkUsage() const {
106 } // namespace task_manager