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/memory/memory_coordinator_client_registry.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
16 #include "base/trace_event/memory_dump_manager.h" | 17 #include "base/trace_event/memory_dump_manager.h" |
17 #include "cc/base/container_util.h" | 18 #include "cc/base/container_util.h" |
18 #include "cc/resources/resource_provider.h" | 19 #include "cc/resources/resource_provider.h" |
19 #include "cc/resources/resource_util.h" | 20 #include "cc/resources/resource_util.h" |
20 #include "cc/resources/scoped_resource.h" | 21 #include "cc/resources/scoped_resource.h" |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 base::TimeDelta ResourcePool::kDefaultExpirationDelay = | 24 base::TimeDelta ResourcePool::kDefaultExpirationDelay = |
(...skipping 40 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 base::MemoryCoordinatorClientRegistry. |
| 77 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
74 } | 78 } |
75 | 79 |
76 ResourcePool::~ResourcePool() { | 80 ResourcePool::~ResourcePool() { |
77 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 81 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
78 this); | 82 this); |
| 83 // Unregister this component with memory_coordinator::ClientRegistry. |
| 84 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); |
79 | 85 |
80 DCHECK_EQ(0u, in_use_resources_.size()); | 86 DCHECK_EQ(0u, in_use_resources_.size()); |
81 | 87 |
82 while (!busy_resources_.empty()) { | 88 while (!busy_resources_.empty()) { |
83 DidFinishUsingResource(PopBack(&busy_resources_)); | 89 DidFinishUsingResource(PopBack(&busy_resources_)); |
84 } | 90 } |
85 | 91 |
86 SetResourceUsageLimits(0, 0); | 92 SetResourceUsageLimits(0, 0); |
87 DCHECK_EQ(0u, unused_resources_.size()); | 93 DCHECK_EQ(0u, unused_resources_.size()); |
88 DCHECK_EQ(0u, in_use_memory_usage_bytes_); | 94 DCHECK_EQ(0u, in_use_memory_usage_bytes_); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 452 } |
447 for (const auto& resource : busy_resources_) { | 453 for (const auto& resource : busy_resources_) { |
448 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 454 resource->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
449 } | 455 } |
450 for (const auto& entry : in_use_resources_) { | 456 for (const auto& entry : in_use_resources_) { |
451 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); | 457 entry.second->OnMemoryDump(pmd, resource_provider_, false /* is_free */); |
452 } | 458 } |
453 return true; | 459 return true; |
454 } | 460 } |
455 | 461 |
| 462 void ResourcePool::OnMemoryStateChange(base::MemoryState state) { |
| 463 switch (state) { |
| 464 case base::MemoryState::NORMAL: |
| 465 // TODO(tasak): go back to normal state. |
| 466 break; |
| 467 case base::MemoryState::THROTTLED: |
| 468 // TODO(tasak): make the limits of this component's caches smaller to |
| 469 // save memory usage. |
| 470 break; |
| 471 case base::MemoryState::SUSPENDED: |
| 472 // TODO(tasak): free this component's caches as much as possible before |
| 473 // suspending renderer. |
| 474 break; |
| 475 case base::MemoryState::UNKNOWN: |
| 476 // NOT_REACHED. |
| 477 break; |
| 478 } |
| 479 } |
| 480 |
456 } // namespace cc | 481 } // namespace cc |
OLD | NEW |