Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / task_manager / renderer_resource.cc
bloba4d5f23a70a3a51e38a5516364d27e81cf77c010
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)
20 : process_(process),
21 render_view_host_(render_view_host),
22 pending_stats_update_(false),
23 fps_(0.0f),
24 pending_fps_update_(false),
25 v8_memory_allocated_(0),
26 v8_memory_used_(0),
27 pending_v8_memory_allocated_update_(false) {
28 // We cache the process and pid as when a Tab/BackgroundContents is closed the
29 // process reference becomes NULL and the TaskManager still needs it.
30 pid_ = base::GetProcId(process_);
31 unique_process_id_ = render_view_host_->GetProcess()->GetID();
32 memset(&stats_, 0, sizeof(stats_));
35 RendererResource::~RendererResource() {
38 void RendererResource::Refresh() {
39 if (!pending_stats_update_) {
40 render_view_host_->Send(new ChromeViewMsg_GetCacheResourceStats);
41 pending_stats_update_ = true;
43 if (!pending_fps_update_) {
44 render_view_host_->Send(
45 new ChromeViewMsg_GetFPS(render_view_host_->GetRoutingID()));
46 pending_fps_update_ = true;
48 if (!pending_v8_memory_allocated_update_) {
49 render_view_host_->Send(new ChromeViewMsg_GetV8HeapStats);
50 pending_v8_memory_allocated_update_ = true;
54 blink::WebCache::ResourceTypeStats
55 RendererResource::GetWebCoreCacheStats() const {
56 return stats_;
59 float RendererResource::GetFPS() const {
60 return fps_;
63 size_t RendererResource::GetV8MemoryAllocated() const {
64 return v8_memory_allocated_;
67 size_t RendererResource::GetV8MemoryUsed() const {
68 return v8_memory_used_;
71 void RendererResource::NotifyResourceTypeStats(
72 const blink::WebCache::ResourceTypeStats& stats) {
73 stats_ = stats;
74 pending_stats_update_ = false;
77 void RendererResource::NotifyFPS(float fps) {
78 fps_ = fps;
79 pending_fps_update_ = false;
82 void RendererResource::NotifyV8HeapStats(
83 size_t v8_memory_allocated, size_t v8_memory_used) {
84 v8_memory_allocated_ = v8_memory_allocated;
85 v8_memory_used_ = v8_memory_used;
86 pending_v8_memory_allocated_update_ = false;
89 base::string16 RendererResource::GetProfileName() const {
90 return util::GetProfileNameFromInfoCache(Profile::FromBrowserContext(
91 render_view_host_->GetProcess()->GetBrowserContext()));
94 base::ProcessHandle RendererResource::GetProcess() const {
95 return process_;
98 int RendererResource::GetUniqueChildProcessId() const {
99 return unique_process_id_;
102 Resource::Type RendererResource::GetType() const {
103 return RENDERER;
106 int RendererResource::GetRoutingID() const {
107 return render_view_host_->GetRoutingID();
110 bool RendererResource::ReportsCacheStats() const {
111 return true;
114 bool RendererResource::ReportsFPS() const {
115 return true;
118 bool RendererResource::ReportsV8MemoryStats() const {
119 return true;
122 bool RendererResource::CanInspect() const {
123 return true;
126 void RendererResource::Inspect() const {
127 DevToolsWindow::OpenDevToolsWindow(render_view_host_);
130 bool RendererResource::SupportNetworkUsage() const {
131 return true;
134 } // namespace task_manager