Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / task_manager / resource_provider.h
blob3b39c1be2538b093a33d2cbb9b87e3db0c722001
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 ReportsSqliteMemoryUsed() const;
71 virtual size_t SqliteMemoryUsedBytes() const;
73 virtual bool ReportsV8MemoryStats() const;
74 virtual size_t GetV8MemoryAllocated() const;
75 virtual size_t GetV8MemoryUsed() const;
77 // A helper function for ActivateProcess when selected resource refers
78 // to a Tab or other window containing web contents. Returns NULL by
79 // default because not all resources have an associated web contents.
80 virtual content::WebContents* GetWebContents() const;
82 // Whether this resource does report the network usage accurately.
83 // This controls whether 0 or N/A is displayed when no bytes have been
84 // reported as being read. This is because some plugins do not report the
85 // bytes read and we don't want to display a misleading 0 value in that
86 // case.
87 virtual bool SupportNetworkUsage() const = 0;
89 // Called when some bytes have been read and support_network_usage returns
90 // false (meaning we do have network usage support).
91 virtual void SetSupportNetworkUsage() = 0;
93 // The TaskManagerModel periodically refreshes its data and call this
94 // on all live resources.
95 virtual void Refresh() {}
97 virtual void NotifyResourceTypeStats(
98 const blink::WebCache::ResourceTypeStats& stats) {}
99 virtual void NotifyV8HeapStats(size_t v8_memory_allocated,
100 size_t v8_memory_used) {}
102 static const char* GetResourceTypeAsString(const Type type) {
103 switch (type) {
104 TASKMANAGER_RESOURCE_TYPE_LIST(TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING)
105 default: return "UNKNOWN";
109 protected:
110 Resource() {}
112 private:
113 DISALLOW_COPY_AND_ASSIGN(Resource);
116 #undef TASKMANAGER_RESOURCE_TYPE_LIST
117 #undef TASKMANAGER_RESOURCE_TYPE_LIST_ENUM
118 #undef TASKMANAGER_RESOURCE_TYPE_LIST_AS_STRING
120 // ResourceProviders are responsible for adding/removing resources to the task
121 // manager. The task manager notifies the ResourceProvider that it is ready
122 // to receive resource creation/termination notifications with a call to
123 // StartUpdating(). At that point, the resource provider should call
124 // AddResource with all the existing resources, and after that it should call
125 // AddResource/RemoveResource as resources are created/terminated.
126 // The provider remains the owner of the resource objects and is responsible
127 // for deleting them (when StopUpdating() is called).
128 // After StopUpdating() is called the provider should also stop reporting
129 // notifications to the task manager.
130 // Note: ResourceProviders have to be ref counted as they are used in
131 // MessageLoop::InvokeLater().
132 class ResourceProvider : public base::RefCountedThreadSafe<ResourceProvider> {
133 public:
134 // Should return the resource associated to the specified ids, or NULL if
135 // the resource does not belong to this provider.
136 virtual Resource* GetResource(int origin_pid,
137 int child_id,
138 int route_id) = 0;
139 virtual void StartUpdating() = 0;
140 virtual void StopUpdating() = 0;
142 protected:
143 friend class base::RefCountedThreadSafe<ResourceProvider>;
145 virtual ~ResourceProvider() {}
148 } // namespace task_manager
150 #endif // CHROME_BROWSER_TASK_MANAGER_RESOURCE_PROVIDER_H_