Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / task_manager / renderer_resource.cc
bloba9a08e4856db60411b7159af55bbcfb0be8a85cd
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/task_manager/resource_provider.h"
10 #include "chrome/common/render_messages.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
14 namespace task_manager {
16 RendererResource::RendererResource(base::ProcessHandle process,
17 content::RenderViewHost* render_view_host)
18 : process_(process),
19 render_view_host_(render_view_host),
20 pending_stats_update_(false),
21 fps_(0.0f),
22 pending_fps_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_));
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_fps_update_) {
42 render_view_host_->Send(
43 new ChromeViewMsg_GetFPS(render_view_host_->GetRoutingID()));
44 pending_fps_update_ = true;
46 if (!pending_v8_memory_allocated_update_) {
47 render_view_host_->Send(new ChromeViewMsg_GetV8HeapStats);
48 pending_v8_memory_allocated_update_ = true;
52 blink::WebCache::ResourceTypeStats
53 RendererResource::GetWebCoreCacheStats() const {
54 return stats_;
57 float RendererResource::GetFPS() const {
58 return fps_;
61 size_t RendererResource::GetV8MemoryAllocated() const {
62 return v8_memory_allocated_;
65 size_t RendererResource::GetV8MemoryUsed() const {
66 return v8_memory_used_;
69 void RendererResource::NotifyResourceTypeStats(
70 const blink::WebCache::ResourceTypeStats& stats) {
71 stats_ = stats;
72 pending_stats_update_ = false;
75 void RendererResource::NotifyFPS(float fps) {
76 fps_ = fps;
77 pending_fps_update_ = false;
80 void RendererResource::NotifyV8HeapStats(
81 size_t v8_memory_allocated, size_t v8_memory_used) {
82 v8_memory_allocated_ = v8_memory_allocated;
83 v8_memory_used_ = v8_memory_used;
84 pending_v8_memory_allocated_update_ = false;
87 base::ProcessHandle RendererResource::GetProcess() const {
88 return process_;
91 int RendererResource::GetUniqueChildProcessId() const {
92 return unique_process_id_;
95 Resource::Type RendererResource::GetType() const {
96 return RENDERER;
99 int RendererResource::GetRoutingID() const {
100 return render_view_host_->GetRoutingID();
103 bool RendererResource::ReportsCacheStats() const {
104 return true;
107 bool RendererResource::ReportsFPS() const {
108 return true;
111 bool RendererResource::ReportsV8MemoryStats() const {
112 return true;
115 bool RendererResource::CanInspect() const {
116 return true;
119 void RendererResource::Inspect() const {
120 DevToolsWindow::OpenDevToolsWindow(render_view_host_);
123 bool RendererResource::SupportNetworkUsage() const {
124 return true;
127 } // namespace task_manager