renderer_resource.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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.
4
5#include "chrome/browser/task_manager/renderer_resource.h"
6
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"
15
16namespace task_manager {
17
18RendererResource::RendererResource(base::ProcessHandle process,
19                                   content::RenderViewHost* render_view_host)
20    : process_(process),
21      render_view_host_(render_view_host),
22      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
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_));
31}
32
33RendererResource::~RendererResource() {
34}
35
36void RendererResource::Refresh() {
37  if (!pending_stats_update_) {
38    render_view_host_->Send(new ChromeViewMsg_GetCacheResourceStats);
39    pending_stats_update_ = true;
40  }
41  if (!pending_v8_memory_allocated_update_) {
42    render_view_host_->Send(new ChromeViewMsg_GetV8HeapStats);
43    pending_v8_memory_allocated_update_ = true;
44  }
45}
46
47blink::WebCache::ResourceTypeStats
48RendererResource::GetWebCoreCacheStats() const {
49  return stats_;
50}
51
52size_t RendererResource::GetV8MemoryAllocated() const {
53  return v8_memory_allocated_;
54}
55
56size_t RendererResource::GetV8MemoryUsed() const {
57  return v8_memory_used_;
58}
59
60void RendererResource::NotifyResourceTypeStats(
61    const blink::WebCache::ResourceTypeStats& stats) {
62  stats_ = stats;
63  pending_stats_update_ = false;
64}
65
66void 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
73base::string16 RendererResource::GetProfileName() const {
74  return util::GetProfileNameFromInfoCache(Profile::FromBrowserContext(
75      render_view_host_->GetProcess()->GetBrowserContext()));
76}
77
78base::ProcessHandle RendererResource::GetProcess() const {
79  return process_;
80}
81
82int RendererResource::GetUniqueChildProcessId() const {
83  return unique_process_id_;
84}
85
86Resource::Type RendererResource::GetType() const {
87  return RENDERER;
88}
89
90int RendererResource::GetRoutingID() const {
91  return render_view_host_->GetRoutingID();
92}
93
94bool RendererResource::ReportsCacheStats() const {
95  return true;
96}
97
98bool RendererResource::ReportsV8MemoryStats() const {
99  return true;
100}
101
102bool RendererResource::SupportNetworkUsage() const {
103  return true;
104}
105
106}  // namespace task_manager
107