OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/host_discardable_shared_memory_manager.h" | 5 #include "content/common/host_discardable_shared_memory_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 DCHECK(is_locked_); | 57 DCHECK(is_locked_); |
58 | 58 |
59 shared_memory_->Unlock(0, 0); | 59 shared_memory_->Unlock(0, 0); |
60 is_locked_ = false; | 60 is_locked_ = false; |
61 } | 61 } |
62 void* data() const override { | 62 void* data() const override { |
63 DCHECK(is_locked_); | 63 DCHECK(is_locked_); |
64 return shared_memory_->memory(); | 64 return shared_memory_->memory(); |
65 } | 65 } |
66 | 66 |
| 67 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( |
| 68 const char* name, |
| 69 base::trace_event::ProcessMemoryDump* pmd) const override { |
| 70 // The memory could have been purged, but we still create a dump with |
| 71 // mapped_size. So, the size can be inaccurate. |
| 72 base::trace_event::MemoryAllocatorDump* dump = |
| 73 pmd->CreateAllocatorDump(name); |
| 74 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 75 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 76 shared_memory_->mapped_size()); |
| 77 return dump; |
| 78 } |
| 79 |
67 private: | 80 private: |
68 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; | 81 scoped_ptr<base::DiscardableSharedMemory> shared_memory_; |
69 const base::Closure deleted_callback_; | 82 const base::Closure deleted_callback_; |
70 bool is_locked_; | 83 bool is_locked_; |
71 | 84 |
72 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); | 85 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); |
73 }; | 86 }; |
74 | 87 |
75 base::LazyInstance<HostDiscardableSharedMemoryManager> | 88 base::LazyInstance<HostDiscardableSharedMemoryManager> |
76 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; | 89 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 469 |
457 enforce_memory_policy_pending_ = true; | 470 enforce_memory_policy_pending_ = true; |
458 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 471 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
459 FROM_HERE, | 472 FROM_HERE, |
460 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 473 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
461 weak_ptr_factory_.GetWeakPtr()), | 474 weak_ptr_factory_.GetWeakPtr()), |
462 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 475 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
463 } | 476 } |
464 | 477 |
465 } // namespace content | 478 } // namespace content |
OLD | NEW |