OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 5 #ifndef CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
6 #define CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 6 #define CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <deque> | 10 #include <deque> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "chrome/common/resource_usage_reporter.mojom.h" | 15 #include "chrome/common/resource_usage_reporter.mojom.h" |
16 #include "third_party/WebKit/public/web/WebCache.h" | 16 #include "third_party/WebKit/public/web/WebCache.h" |
17 | 17 |
18 // Provides resource usage information about a child process. | 18 // Provides resource usage information about a child process. |
19 // | 19 // |
20 // This is a wrapper around the mojom::ResourceUsageReporter Mojo service that | 20 // This is a wrapper around the chrome::mojom::ResourceUsageReporter Mojo |
21 // exposes | 21 // service that exposes |
22 // information about resources used by a child process. Currently, this is only | 22 // information about resources used by a child process. Currently, this is only |
23 // V8 memory and Blink resource cache usage, but could be expanded to include | 23 // V8 memory and Blink resource cache usage, but could be expanded to include |
24 // other resources. This is intended for status viewers such as the task | 24 // other resources. This is intended for status viewers such as the task |
25 // manager. | 25 // manager. |
26 // | 26 // |
27 // To create: | 27 // To create: |
28 // 1. Create a mojom::ResourceUsageReporterPtr and obtain an InterfaceRequest<> | 28 // 1. Create a chrome::mojom::ResourceUsageReporterPtr and obtain an |
| 29 // InterfaceRequest<> |
29 // using | 30 // using |
30 // mojo::GetProxy. | 31 // mojo::GetProxy. |
31 // 2. Use the child process's service registry to connect to the service using | 32 // 2. Use the child process's service registry to connect to the service using |
32 // the InterfaceRequest<>. Note, ServiceRegistry is thread hostile and | 33 // the InterfaceRequest<>. Note, ServiceRegistry is thread hostile and |
33 // must always be accessed from the same thread. However, InterfaceRequest<> | 34 // must always be accessed from the same thread. However, InterfaceRequest<> |
34 // can be passed safely between threads, and therefore a task can be posted | 35 // can be passed safely between threads, and therefore a task can be posted |
35 // to the ServiceRegistry thread to connect to the remote service. | 36 // to the ServiceRegistry thread to connect to the remote service. |
36 // 3. Pass the mojom::ResourceUsageReporterPtr to the constructor. | 37 // 3. Pass the chrome::mojom::ResourceUsageReporterPtr to the constructor. |
37 // | 38 // |
38 // Example: | 39 // Example: |
39 // void Foo::ConnectToService( | 40 // void Foo::ConnectToService( |
40 // mojo::InterfaceRequest<mojom::ResourceUsageReporter> req) { | 41 // mojo::InterfaceRequest<chrome::mojom::ResourceUsageReporter> req) { |
41 // content::ServiceRegistry* registry = host_->GetServiceRegistry(); | 42 // content::ServiceRegistry* registry = host_->GetServiceRegistry(); |
42 // registry->ConnectToRemoteService(std::move(req)); | 43 // registry->ConnectToRemoteService(std::move(req)); |
43 // } | 44 // } |
44 // | 45 // |
45 // ... | 46 // ... |
46 // mojom::ResourceUsageReporterPtr service; | 47 // chrome::mojom::ResourceUsageReporterPtr service; |
47 // mojo::InterfaceRequest<mojom::ResourceUsageReporter> request = | 48 // mojo::InterfaceRequest<chrome::mojom::ResourceUsageReporter> request = |
48 // mojo::GetProxy(&service); | 49 // mojo::GetProxy(&service); |
49 // content::BrowserThread::PostTask( | 50 // content::BrowserThread::PostTask( |
50 // content::BrowserThread::IO, FROM_HERE, | 51 // content::BrowserThread::IO, FROM_HERE, |
51 // base::Bind(&Foo::ConnectToService, this, base::Passed(&request))); | 52 // base::Bind(&Foo::ConnectToService, this, base::Passed(&request))); |
52 // resource_usage_.reset(new ProcessResourceUsage(std::move(service))); | 53 // resource_usage_.reset(new ProcessResourceUsage(std::move(service))); |
53 // ... | 54 // ... |
54 // | 55 // |
55 // Note: ProcessResourceUsage is thread-hostile and must live on a single | 56 // Note: ProcessResourceUsage is thread-hostile and must live on a single |
56 // thread. | 57 // thread. |
57 class ProcessResourceUsage { | 58 class ProcessResourceUsage { |
58 public: | 59 public: |
59 // Must be called from the same thread that created |service|. | 60 // Must be called from the same thread that created |service|. |
60 explicit ProcessResourceUsage(mojom::ResourceUsageReporterPtr service); | 61 explicit ProcessResourceUsage( |
| 62 chrome::mojom::ResourceUsageReporterPtr service); |
61 ~ProcessResourceUsage(); | 63 ~ProcessResourceUsage(); |
62 | 64 |
63 // Refresh the resource usage information. |callback| is invoked when the | 65 // Refresh the resource usage information. |callback| is invoked when the |
64 // usage data is updated, or when the IPC connection is lost. | 66 // usage data is updated, or when the IPC connection is lost. |
65 void Refresh(const base::Closure& callback); | 67 void Refresh(const base::Closure& callback); |
66 | 68 |
67 // Get V8 memory usage information. | 69 // Get V8 memory usage information. |
68 bool ReportsV8MemoryStats() const; | 70 bool ReportsV8MemoryStats() const; |
69 size_t GetV8MemoryAllocated() const; | 71 size_t GetV8MemoryAllocated() const; |
70 size_t GetV8MemoryUsed() const; | 72 size_t GetV8MemoryUsed() const; |
71 | 73 |
72 // Get Blink resource cache information. | 74 // Get Blink resource cache information. |
73 blink::WebCache::ResourceTypeStats GetWebCoreCacheStats() const; | 75 blink::WebCache::ResourceTypeStats GetWebCoreCacheStats() const; |
74 | 76 |
75 private: | 77 private: |
76 // Mojo IPC callback. | 78 // Mojo IPC callback. |
77 void OnRefreshDone(mojom::ResourceUsageDataPtr data); | 79 void OnRefreshDone(chrome::mojom::ResourceUsageDataPtr data); |
78 | 80 |
79 void RunPendingRefreshCallbacks(); | 81 void RunPendingRefreshCallbacks(); |
80 | 82 |
81 mojom::ResourceUsageReporterPtr service_; | 83 chrome::mojom::ResourceUsageReporterPtr service_; |
82 bool update_in_progress_; | 84 bool update_in_progress_; |
83 std::deque<base::Closure> refresh_callbacks_; | 85 std::deque<base::Closure> refresh_callbacks_; |
84 | 86 |
85 mojom::ResourceUsageDataPtr stats_; | 87 chrome::mojom::ResourceUsageDataPtr stats_; |
86 | 88 |
87 base::ThreadChecker thread_checker_; | 89 base::ThreadChecker thread_checker_; |
88 | 90 |
89 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); | 91 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); |
90 }; | 92 }; |
91 | 93 |
92 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 94 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
OLD | NEW |