Chromium Code Reviews| 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) 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_; |
| 82 size_t size_; | |
|
reveman
2015/08/24 16:50:06
is this needed?
| |
| 69 const base::Closure deleted_callback_; | 83 const base::Closure deleted_callback_; |
| 70 bool is_locked_; | 84 bool is_locked_; |
| 71 | 85 |
| 72 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); | 86 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl); |
| 73 }; | 87 }; |
| 74 | 88 |
| 75 base::LazyInstance<HostDiscardableSharedMemoryManager> | 89 base::LazyInstance<HostDiscardableSharedMemoryManager> |
| 76 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; | 90 g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER; |
| 77 | 91 |
| 78 #if defined(OS_ANDROID) | 92 #if defined(OS_ANDROID) |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 470 |
| 457 enforce_memory_policy_pending_ = true; | 471 enforce_memory_policy_pending_ = true; |
| 458 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 472 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 459 FROM_HERE, | 473 FROM_HERE, |
| 460 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 474 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
| 461 weak_ptr_factory_.GetWeakPtr()), | 475 weak_ptr_factory_.GetWeakPtr()), |
| 462 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 476 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
| 463 } | 477 } |
| 464 | 478 |
| 465 } // namespace content | 479 } // namespace content |
| OLD | NEW |