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 ReportsV8MemoryStats() const OVERRIDE;
36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual size_t GetV8MemoryAllocated() const OVERRIDE;
37a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual size_t GetV8MemoryUsed() const OVERRIDE;
38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // RenderResources always provide the network usage.
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool SupportNetworkUsage() const OVERRIDE;
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void SetSupportNetworkUsage() OVERRIDE { }
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void Refresh() OVERRIDE;
44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void NotifyResourceTypeStats(
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      const blink::WebCache::ResourceTypeStats& stats) OVERRIDE;
47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void NotifyV8HeapStats(size_t v8_memory_allocated,
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                                 size_t v8_memory_used) OVERRIDE;
50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  content::RenderViewHost* render_view_host() const {
52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return render_view_host_;
53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::ProcessHandle process_;
57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int pid_;
58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int unique_process_id_;
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // RenderViewHost we use to fetch stats.
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  content::RenderViewHost* render_view_host_;
62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // The stats_ field holds information about resource usage in the renderer
63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // process and so it is updated asynchronously by the Refresh() call.
64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebCache::ResourceTypeStats stats_;
65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This flag is true if we are waiting for the renderer to report its stats.
66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool pending_stats_update_;
67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // We do a similar dance to gather the V8 memory usage in a process.
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t v8_memory_allocated_;
70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  size_t v8_memory_used_;
71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  bool pending_v8_memory_allocated_update_;
72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(RendererResource);
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
75a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace task_manager
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // CHROME_BROWSER_TASK_MANAGER_RENDERER_RESOURCE_H_
79