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