| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/debug/crash_logging.h" | 12 #include "base/debug/crash_logging.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/memory/discardable_memory.h" | 14 #include "base/memory/discardable_memory.h" |
| 15 #include "base/numerics/safe_math.h" | 15 #include "base/numerics/safe_math.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "base/thread_task_runner_handle.h" | |
| 19 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 class DiscardableMemoryImpl : public base::DiscardableMemory { | 23 class DiscardableMemoryImpl : public base::DiscardableMemory { |
| 25 public: | 24 public: |
| 26 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory, | 25 DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory, |
| 27 const base::Closure& deleted_callback) | 26 const base::Closure& deleted_callback) |
| 28 : shared_memory_(shared_memory.Pass()), | 27 : shared_memory_(shared_memory.Pass()), |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 return base::Time::Now(); | 382 return base::Time::Now(); |
| 384 } | 383 } |
| 385 | 384 |
| 386 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { | 385 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { |
| 387 lock_.AssertAcquired(); | 386 lock_.AssertAcquired(); |
| 388 | 387 |
| 389 if (enforce_memory_policy_pending_) | 388 if (enforce_memory_policy_pending_) |
| 390 return; | 389 return; |
| 391 | 390 |
| 392 enforce_memory_policy_pending_ = true; | 391 enforce_memory_policy_pending_ = true; |
| 393 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 392 base::MessageLoop::current()->PostDelayedTask( |
| 394 FROM_HERE, | 393 FROM_HERE, |
| 395 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 394 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
| 396 weak_ptr_factory_.GetWeakPtr()), | 395 weak_ptr_factory_.GetWeakPtr()), |
| 397 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 396 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
| 398 } | 397 } |
| 399 | 398 |
| 400 } // namespace content | 399 } // namespace content |
| OLD | NEW |