Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / task_manager / resource_provider.h
blob16d48c2aa21432882aa3f1e9ed7bad2baff08f7f
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 #ifndef CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDER_H_
6 #define CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/process/process_handle.h"
11 #include "base/strings/string16.h"
12 #include "third_party/WebKit/public/web/WebCache.h"
14 class PrefRegistrySimple;
15 class TaskManagerModel;
17 namespace content {
18 class WebContents;
21 namespace extensions {
22 class Extension;
25 namespace gfx {
26 class ImageSkia;
29 namespace task_manager {
31 #define TASKMANAGER_RESOURCE_TYPE_LIST(def) \
32 def(BROWSER) /* The main browser process. */ \
33 def(RENDERER) /* A normal WebContents renderer process. */ \
34 def(EXTENSION) /* An extension or app process. */ \
35 def(NOTIFICATION) /* A notification process. */ \
36 def(GUEST) /* A browser plugin guest process. */ \
37 def(PLUGIN) /* A plugin process. */ \
38 def(WORKER) /* A web worker process. */ \
39 def(NACL) /* A NativeClient loader or broker process. */ \
40 def(UTILITY) /* A browser utility process. */ \
41 def(ZYGOTE) /* A Linux zygote process. */ \
42 def(SANDBOX_HELPER) /* A sandbox helper process. */ \
43 def(GPU) /* A graphics process. */
45 #define TASKMANAGER_RESOURCE_TYPE_LIST_ENUM(a) a,
46 #define TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING(a) case a: return #a;
48 // A resource represents one row in the task manager.
49 // Resources from similar processes are grouped together by the task manager.
50 class Resource {
51 public:
52 virtual ~Resource() {}
54 enum Type {
55 UNKNOWN = 0,
56 TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_ENUM)
59 virtual base::string16 GetTitle() const = 0;
60 virtual base::string16 GetProfileName() const = 0;
61 virtual gfx::ImageSkia GetIcon() const = 0;
62 virtual base::ProcessHandle GetProcess() const = 0;
63 virtual int GetUniqueChildProcessId() const = 0;
64 virtual Type GetType() const = 0;
65 virtual int GetRoutingID() const;
67 virtual bool ReportsCacheStats() const;
68 virtual blink::WebCache::ResourceTypeStats GetWebCoreCacheStats() const;
70 virtual bool ReportsFPS() const;
71 virtual float GetFPS() const;
73 virtual bool ReportsSqliteMemoryUsed() const;
74 virtual size_t SqliteMemoryUsedBytes() const;
76 // Return extension associated with the resource, or NULL if not applicable.
77 virtual const extensions::Extension* GetExtension() const;
79 virtual bool ReportsV8MemoryStats() const;
80 virtual size_t GetV8MemoryAllocated() const;
81 virtual size_t GetV8MemoryUsed() const;
83 virtual int GetNaClDebugStubPort() const;
85 // Returns true if this resource can be inspected using developer tools.
86 virtual bool CanInspect() const;
88 // Invokes or reveals developer tools window for this resource.
89 virtual void Inspect() const {}
91 // A helper function for ActivateProcess when selected resource refers
92 // to a Tab or other window containing web contents. Returns NULL by
93 // default because not all resources have an associated web contents.
94 virtual content::WebContents* GetWebContents() const;
96 // Whether this resource does report the network usage accurately.
97 // This controls whether 0 or N/A is displayed when no bytes have been
98 // reported as being read. This is because some plugins do not report the
99 // bytes read and we don't want to display a misleading 0 value in that
100 // case.
101 virtual bool SupportNetworkUsage() const = 0;
103 // Called when some bytes have been read and support_network_usage returns
104 // false (meaning we do have network usage support).
105 virtual void SetSupportNetworkUsage() = 0;
107 // The TaskManagerModel periodically refreshes its data and call this
108 // on all live resources.
109 virtual void Refresh() {}
111 virtual void NotifyResourceTypeStats(
112 const blink::WebCache::ResourceTypeStats& stats) {}
113 virtual void NotifyFPS(float fps) {}
114 virtual void NotifyV8HeapStats(size_t v8_memory_allocated,
115 size_t v8_memory_used) {}
117 // Returns true if this resource is not visible to the user because it lives
118 // in the background (e.g. extension background page, background contents).
119 virtual bool IsBackground() const;
121 static const char* GetResourceTypeAsString(const Type type) {
122 switch (type) {
123 TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING)
124 default: return "UNKNOWN";
128 // Returns resource identifier that is unique within single task manager
129 // session (between StartUpdating and StopUpdating).
130 int get_unique_id() { return unique_id_; }
132 protected:
133 Resource() : unique_id_(0) {}
135 private:
136 friend class ::TaskManagerModel;
137 int unique_id_;
139 DISALLOW_COPY_AND_ASSIGN(Resource);
142 #undef TASKMANAGER_RESOURCE_TYPE_LIST
143 #undef TASKMANAGER_RESOURCE_TYPE_LIST_ENUM
144 #undef TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING
146 // ResourceProviders are responsible for adding/removing resources to the task
147 // manager. The task manager notifies the ResourceProvider that it is ready
148 // to receive resource creation/termination notifications with a call to
149 // StartUpdating(). At that point, the resource provider should call
150 // AddResource with all the existing resources, and after that it should call
151 // AddResource/RemoveResource as resources are created/terminated.
152 // The provider remains the owner of the resource objects and is responsible
153 // for deleting them (when StopUpdating() is called).
154 // After StopUpdating() is called the provider should also stop reporting
155 // notifications to the task manager.
156 // Note: ResourceProviders have to be ref counted as they are used in
157 // MessageLoop::InvokeLater().
158 class ResourceProvider : public base::RefCountedThreadSafe<ResourceProvider> {
159 public:
160 // Should return the resource associated to the specified ids, or NULL if
161 // the resource does not belong to this provider.
162 virtual Resource* GetResource(int origin_pid,
163 int child_id,
164 int route_id) = 0;
165 virtual void StartUpdating() = 0;
166 virtual void StopUpdating() = 0;
168 protected:
169 friend class base::RefCountedThreadSafe<ResourceProvider>;
171 virtual ~ResourceProvider() {}
174 } // namespace task_manager
176 #endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDER_H_