OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "cc/resources/resource_pool.h" | 5 #include "cc/resources/resource_pool.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/trace_event/memory_dump_manager.h" | 16 #include "base/trace_event/memory_dump_manager.h" |
17 #include "cc/base/container_util.h" | 17 #include "cc/base/container_util.h" |
18 #include "cc/resources/resource_provider.h" | 18 #include "cc/resources/resource_provider.h" |
19 #include "cc/resources/resource_util.h" | 19 #include "cc/resources/resource_util.h" |
20 #include "cc/resources/scoped_resource.h" | 20 #include "cc/resources/scoped_resource.h" |
| 21 #include "components/memory_coordinator/common/client_registry.h" |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 base::TimeDelta ResourcePool::kDefaultExpirationDelay = | 24 base::TimeDelta ResourcePool::kDefaultExpirationDelay = |
24 base::TimeDelta::FromSeconds(1); | 25 base::TimeDelta::FromSeconds(1); |
25 | 26 |
26 void ResourcePool::PoolResource::OnMemoryDump( | 27 void ResourcePool::PoolResource::OnMemoryDump( |
27 base::trace_event::ProcessMemoryDump* pmd, | 28 base::trace_event::ProcessMemoryDump* pmd, |
28 const ResourceProvider* resource_provider, | 29 const ResourceProvider* resource_provider, |
29 bool is_free) const { | 30 bool is_free) const { |
30 // Resource IDs are not process-unique, so log with the ResourceProvider's | 31 // Resource IDs are not process-unique, so log with the ResourceProvider's |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 max_resource_count_(0), | 65 max_resource_count_(0), |
65 in_use_memory_usage_bytes_(0), | 66 in_use_memory_usage_bytes_(0), |
66 total_memory_usage_bytes_(0), | 67 total_memory_usage_bytes_(0), |
67 total_resource_count_(0), | 68 total_resource_count_(0), |
68 task_runner_(task_runner), | 69 task_runner_(task_runner), |
69 evict_expired_resources_pending_(false), | 70 evict_expired_resources_pending_(false), |
70 resource_expiration_delay_(expiration_delay), | 71 resource_expiration_delay_(expiration_delay), |
71 weak_ptr_factory_(this) { | 72 weak_ptr_factory_(this) { |
72 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 73 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
73 this, "cc::ResourcePool", task_runner_.get()); | 74 this, "cc::ResourcePool", task_runner_.get()); |
| 75 |
| 76 // Register this component with memory_coordinator::ClientRegistry. |
| 77 memory_coordinator::ClientRegistry* registry = |
| 78 memory_coordinator::ClientRegistry::GetInstance(); |
| 79 if (registry) |
| 80 registry->RegisterClient(this); |
74 } | 81 } |
75 | 82 |
76 ResourcePool::~ResourcePool() { | 83 ResourcePool::~ResourcePool() { |
77 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 84 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
78 this); | 85 this); |
| 86 // Unregister this component with memory_coordinator::ClientRegistry. |
| 87 memory_coordinator::ClientRegistry* registry = |
| 88 memory_coordinator::ClientRegistry::GetInstance(); |
| 89 if (registry) |
| 90 registry->UnregisterClient(this); |
79 | 91 |
80 DCHECK_EQ(0u, in_use_resources_.size()); | 92 DCHECK_EQ(0u, in_use_resources_.size()); |
81 | 93 |
82 while (!busy_resources_.empty()) { | 94 while (!busy_resources_.empty()) { |
83 DidFinishUsingResource(PopBack(&busy_resources_)); | 95 DidFinishUsingResource(PopBack(&busy_resources_)); |
84 } | 96 } |
85 | 97 |
86 SetResourceUsageLimits(0, 0); | 98 SetResourceUsageLimits(0, 0); |
87 DCHECK_EQ(0u, unused_resources_.size()); | 99 DCHECK_EQ(0u, unused_resources_.size()); |
88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); | 100 DCHECK_EQ(0u, in_use_memory_usage_bytes_); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 458 } |
447 for (const auto& resource : busy_resources_) { | 459 for (const auto& resource : busy_resources_) { |
448 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 460 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
449 } | 461 } |
450 for (const auto& entry : in_use_resources_) { | 462 for (const auto& entry : in_use_resources_) { |
451 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 463 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
452 } | 464 } |
453 return true; | 465 return true; |
454 } | 466 } |
455 | 467 |
| 468 void ResourcePool::OnMemoryStateChange( |
| 469 memory_coordinator::mojom::MemoryState state) { |
| 470 switch (state) { |
| 471 case memory_coordinator::mojom::MemoryState::NORMAL: |
| 472 // TODO(tasak): go back to normal state. |
| 473 break; |
| 474 case memory_coordinator::mojom::MemoryState::THROTTLED: |
| 475 // TODO(tasak): make the limits of this component's caches smaller to |
| 476 // save memory usage. |
| 477 break; |
| 478 case memory_coordinator::mojom::MemoryState::SUSPENDED: |
| 479 // TODO(tasak): free this component's caches as much as possible before |
| 480 // suspending renderer. |
| 481 break; |
| 482 default: |
| 483 // NOT_REACHED. |
| 484 break; |
| 485 } |
| 486 } |
| 487 |
456 } // namespace cc | 488 } // namespace cc |
OLD | NEW |