renderer_resource.h revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
1a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/basictypes.h"
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/task_manager/resource_provider.h"
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace content {
12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class RenderViewHost;
13a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace task_manager {
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Base class for various types of render process resources that provides common
18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// functionality like stats tracking.
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class RendererResource : public Resource {
20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public:
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  RendererResource(base::ProcessHandle process,
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   content::RenderViewHost* render_view_host);
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual ~RendererResource();
24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Resource methods:
2623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  virtual base::string16 GetProfileName() const OVERRIDE;
27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual base::ProcessHandle GetProcess() const OVERRIDE;
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual int GetUniqueChildProcessId() const OVERRIDE;
29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual Type GetType() const OVERRIDE;
30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual int GetRoutingID() const OVERRIDE;
31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool ReportsCacheStats() const OVERRIDE;
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual blink::WebCache::ResourceTypeStats GetWebCoreCacheStats() const
34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      OVERRIDE;
35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool ReportsFPS() const OVERRIDE;
36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual float GetFPS() const OVERRIDE;
37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool ReportsV8MemoryStats() const OVERRIDE;
38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual size_t GetV8MemoryAllocated() const OVERRIDE;
39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual size_t GetV8MemoryUsed() const OVERRIDE;
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // RenderResources are always inspectable.
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool CanInspect() const OVERRIDE;
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void Inspect() const OVERRIDE;
44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // RenderResources always provide the network usage.
46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool SupportNetworkUsage() const OVERRIDE;
47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void SetSupportNetworkUsage() OVERRIDE { }
48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void Refresh() OVERRIDE;
50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void NotifyResourceTypeStats(
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const blink::WebCache::ResourceTypeStats& stats) OVERRIDE;
53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void NotifyFPS(float fps) OVERRIDE;
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void NotifyV8HeapStats(size_t v8_memory_allocated,
57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                 size_t v8_memory_used) OVERRIDE;
58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  content::RenderViewHost* render_view_host() const {
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return render_view_host_;
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::ProcessHandle process_;
65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int pid_;
66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int unique_process_id_;
67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // RenderViewHost we use to fetch stats.
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  content::RenderViewHost* render_view_host_;
70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // The stats_ field holds information about resource usage in the renderer
71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // process and so it is updated asynchronously by the Refresh() call.
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebCache::ResourceTypeStats stats_;
73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This flag is true if we are waiting for the renderer to report its stats.
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool pending_stats_update_;
75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // The fps_ field holds the renderer frames per second.
77a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  float fps_;
78a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This flag is true if we are waiting for the renderer to report its FPS.
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool pending_fps_update_;
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // We do a similar dance to gather the V8 memory usage in a process.
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t v8_memory_allocated_;
83a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t v8_memory_used_;
84a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool pending_v8_memory_allocated_update_;
85a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(RendererResource);
87a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
88a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace task_manager
9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
92