renderer_resource.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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#ifndef CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
6#define CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
7
8#include "base/basictypes.h"
9#include "chrome/browser/task_manager/resource_provider.h"
10#include "content/public/browser/render_view_host_observer.h"
11
12namespace content {
13class RenderViewHost;
14}
15
16namespace task_manager {
17
18// Base class for various types of render process resources that provides common
19// functionality like stats tracking.
20class RendererResource : public Resource,
21                         public content::RenderViewHostObserver {
22 public:
23  RendererResource(base::ProcessHandle process,
24                   content::RenderViewHost* render_view_host);
25  virtual ~RendererResource();
26
27  // Resource methods:
28  virtual base::ProcessHandle GetProcess() const OVERRIDE;
29  virtual int GetUniqueChildProcessId() const OVERRIDE;
30  virtual Type GetType() const OVERRIDE;
31  virtual int GetRoutingID() const OVERRIDE;
32
33  virtual bool ReportsCacheStats() const OVERRIDE;
34  virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const
35      OVERRIDE;
36  virtual bool ReportsFPS() const OVERRIDE;
37  virtual float GetFPS() const OVERRIDE;
38  virtual bool ReportsV8MemoryStats() const OVERRIDE;
39  virtual size_t GetV8MemoryAllocated() const OVERRIDE;
40  virtual size_t GetV8MemoryUsed() const OVERRIDE;
41
42  // RenderResources are always inspectable.
43  virtual bool CanInspect() const OVERRIDE;
44  virtual void Inspect() const OVERRIDE;
45
46  // RenderResources always provide the network usage.
47  virtual bool SupportNetworkUsage() const OVERRIDE;
48  virtual void SetSupportNetworkUsage() OVERRIDE { }
49
50  virtual void Refresh() OVERRIDE;
51
52  virtual void NotifyResourceTypeStats(
53      const WebKit::WebCache::ResourceTypeStats& stats) OVERRIDE;
54
55  virtual void NotifyFPS(float fps) OVERRIDE;
56
57  virtual void NotifyV8HeapStats(size_t v8_memory_allocated,
58                                 size_t v8_memory_used) OVERRIDE;
59
60  // content::RenderViewHostObserver implementation.
61  virtual void RenderViewHostDestroyed(
62      content::RenderViewHost* render_view_host) OVERRIDE;
63
64  content::RenderViewHost* render_view_host() const {
65    return render_view_host_;
66  }
67
68 private:
69  base::ProcessHandle process_;
70  int pid_;
71  int unique_process_id_;
72
73  // RenderViewHost we use to fetch stats.
74  content::RenderViewHost* render_view_host_;
75  // The stats_ field holds information about resource usage in the renderer
76  // process and so it is updated asynchronously by the Refresh() call.
77  WebKit::WebCache::ResourceTypeStats stats_;
78  // This flag is true if we are waiting for the renderer to report its stats.
79  bool pending_stats_update_;
80
81  // The fps_ field holds the renderer frames per second.
82  float fps_;
83  // This flag is true if we are waiting for the renderer to report its FPS.
84  bool pending_fps_update_;
85
86  // We do a similar dance to gather the V8 memory usage in a process.
87  size_t v8_memory_allocated_;
88  size_t v8_memory_used_;
89  bool pending_v8_memory_allocated_update_;
90
91  DISALLOW_COPY_AND_ASSIGN(RendererResource);
92};
93
94}  // namespace task_manager
95
96#endif  // CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
97