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 <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "chrome/common/resource_usage_reporter.mojom.h" | 14 #include "chrome/common/resource_usage_reporter.mojom.h" |
15 | 15 |
16 // Provides resource usage information about a child process. | 16 // Provides resource usage information about a child process. |
17 // | 17 // |
18 // This is a wrapper around the ResourceUsageReporter Mojo service that exposes | 18 // This is a wrapper around the ResourceUsageReporter Mojo service that exposes |
19 // information about resources used by a child process. Currently, this is only | 19 // information about resources used by a child process. Currently, this is only |
20 // V8 memory usage, but could be expanded to include other resources such as web | 20 // V8 memory usage, but could be expanded to include other resources such as web |
21 // cache. This is intended for status viewers such as the task manager and | 21 // cache. This is intended for status viewers such as the task manager and |
22 // about://memory-internals. | 22 // about://memory-internals. |
23 // | 23 // |
24 // To create: | 24 // To create: |
25 // 1. Obtain a ResourceUsageReporter connection using the child process's | 25 // 1. Create a ResourceUsageReporterPtr and obtain an InterfaceRequest<> using |
26 // service registry. i.e: | 26 // mojo::GetProxy. |
27 // ResourceUsageReporterPtr service; | 27 // 2. Use the child process's service registry to connect to the service using |
28 // process->GetServiceRegistry()->ConnectToRemoteService(&service); | 28 // the InterfaceRequest<>. Note, ServiceRegistry is thread hostile and |
29 // 2. If needed, the connection can be passed to another thread using | 29 // must always be accessed from the same thread. However, InterfaceRequest<> |
30 // ResourceUsageReporterPtr::PassInterface(). | 30 // can be passed safely between threads, and therefore a task can be posted |
31 // 3. Pass the service to the constructor. | 31 // to the ServiceRegistry thread to connect to the remote service. |
| 32 // 3. Pass the ResourceUsageReporterPtr to the constructor. |
| 33 // |
| 34 // Example: |
| 35 // void Foo::ConnectToService( |
| 36 // mojo::InterfaceRequest<ResourceUsageReporter> req) { |
| 37 // content::ServiceRegistry* registry = host_->GetServiceRegistry(); |
| 38 // registry->ConnectToRemoteService(req.Pass()); |
| 39 // } |
| 40 // |
| 41 // ... |
| 42 // ResourceUsageReporterPtr service; |
| 43 // mojo::InterfaceRequest<ResourceUsageReporter> request = |
| 44 // mojo::GetProxy(&service); |
| 45 // content::BrowserThread::PostTask( |
| 46 // content::BrowserThread::IO, FROM_HERE, |
| 47 // base::Bind(&Foo::ConnectToService, this, base::Passed(&request))); |
| 48 // resource_usage_.reset(new ProcessResourceUsage(service.Pass())); |
| 49 // ... |
32 // | 50 // |
33 // Note: ProcessResourceUsage is thread-hostile and must live on a single | 51 // Note: ProcessResourceUsage is thread-hostile and must live on a single |
34 // thread. | 52 // thread. |
35 class ProcessResourceUsage { | 53 class ProcessResourceUsage { |
36 public: | 54 public: |
37 // Must be called from the same thread that created |service|. | 55 // Must be called from the same thread that created |service|. |
38 explicit ProcessResourceUsage(ResourceUsageReporterPtr service); | 56 explicit ProcessResourceUsage(ResourceUsageReporterPtr service); |
39 ~ProcessResourceUsage(); | 57 ~ProcessResourceUsage(); |
40 | 58 |
41 // Refresh the resource usage information. |callback| is invoked when the | 59 // Refresh the resource usage information. |callback| is invoked when the |
(...skipping 19 matching lines...) Expand all Loading... |
61 | 79 |
62 ResourceUsageDataPtr stats_; | 80 ResourceUsageDataPtr stats_; |
63 | 81 |
64 scoped_ptr<ErrorHandler> error_handler_; | 82 scoped_ptr<ErrorHandler> error_handler_; |
65 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
66 | 84 |
67 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); | 85 DISALLOW_COPY_AND_ASSIGN(ProcessResourceUsage); |
68 }; | 86 }; |
69 | 87 |
70 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ | 88 #endif // CHROME_BROWSER_PROCESS_RESOURCE_USAGE_H_ |
OLD | NEW |