| 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/debug/crash_logging.h" | 10 #include "base/debug/crash_logging.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 segments_.push_back(segment); | 222 segments_.push_back(segment); |
| 223 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime); | 223 std::push_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime); |
| 224 } | 224 } |
| 225 | 225 |
| 226 if (bytes_allocated_ != bytes_allocated_before_purging) | 226 if (bytes_allocated_ != bytes_allocated_before_purging) |
| 227 BytesAllocatedChanged(bytes_allocated_); | 227 BytesAllocatedChanged(bytes_allocated_); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void HostDiscardableSharedMemoryManager::BytesAllocatedChanged( | 230 void HostDiscardableSharedMemoryManager::BytesAllocatedChanged( |
| 231 size_t new_bytes_allocated) const { | 231 size_t new_bytes_allocated) const { |
| 232 TRACE_COUNTER_ID1( | 232 TRACE_COUNTER_ID1("renderer_host", "TotalDiscardableMemoryUsage", this, |
| 233 "base", "TotalDiscardableMemoryUsage", this, new_bytes_allocated); | 233 new_bytes_allocated); |
| 234 | 234 |
| 235 static const char kTotalDiscardableMemoryUsageKey[] = "total-dm-usage"; | 235 static const char kTotalDiscardableMemoryUsageKey[] = "total-dm-usage"; |
| 236 base::debug::SetCrashKeyValue(kTotalDiscardableMemoryUsageKey, | 236 base::debug::SetCrashKeyValue(kTotalDiscardableMemoryUsageKey, |
| 237 base::Uint64ToString(new_bytes_allocated)); | 237 base::Uint64ToString(new_bytes_allocated)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 base::Time HostDiscardableSharedMemoryManager::Now() const { | 240 base::Time HostDiscardableSharedMemoryManager::Now() const { |
| 241 return base::Time::Now(); | 241 return base::Time::Now(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { | 244 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { |
| 245 if (enforce_memory_policy_pending_) | 245 if (enforce_memory_policy_pending_) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 enforce_memory_policy_pending_ = true; | 248 enforce_memory_policy_pending_ = true; |
| 249 base::MessageLoop::current()->PostDelayedTask( | 249 base::MessageLoop::current()->PostDelayedTask( |
| 250 FROM_HERE, | 250 FROM_HERE, |
| 251 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 251 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
| 252 weak_ptr_factory_.GetWeakPtr()), | 252 weak_ptr_factory_.GetWeakPtr()), |
| 253 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 253 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace content | 256 } // namespace content |
| OLD | NEW |