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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // is that the memory will be released to the OS if the child process is | 391 // is that the memory will be released to the OS if the child process is |
392 // no longer referencing it. | 392 // no longer referencing it. |
393 // Note: We intentionally leave the segment in the |segments| vector to | 393 // Note: We intentionally leave the segment in the |segments| vector to |
394 // avoid reconstructing the heap. The element will be removed from the heap | 394 // avoid reconstructing the heap. The element will be removed from the heap |
395 // when its last usage time is older than all other segments. | 395 // when its last usage time is older than all other segments. |
396 memory->Close(); | 396 memory->Close(); |
397 } | 397 } |
398 | 398 |
399 void HostDiscardableSharedMemoryManager::BytesAllocatedChanged( | 399 void HostDiscardableSharedMemoryManager::BytesAllocatedChanged( |
400 size_t new_bytes_allocated) const { | 400 size_t new_bytes_allocated) const { |
401 TRACE_COUNTER_ID1("renderer_host", "TotalDiscardableMemoryUsage", this, | 401 TRACE_COUNTER1("renderer_host", "TotalDiscardableMemoryUsage", |
402 new_bytes_allocated); | 402 new_bytes_allocated); |
403 | 403 |
404 static const char kTotalDiscardableMemoryUsageKey[] = "total-dm-usage"; | 404 static const char kTotalDiscardableMemoryAllocatedKey[] = |
405 base::debug::SetCrashKeyValue(kTotalDiscardableMemoryUsageKey, | 405 "total-discardable-memory-allocated"; |
| 406 base::debug::SetCrashKeyValue(kTotalDiscardableMemoryAllocatedKey, |
406 base::Uint64ToString(new_bytes_allocated)); | 407 base::Uint64ToString(new_bytes_allocated)); |
407 } | 408 } |
408 | 409 |
409 base::Time HostDiscardableSharedMemoryManager::Now() const { | 410 base::Time HostDiscardableSharedMemoryManager::Now() const { |
410 return base::Time::Now(); | 411 return base::Time::Now(); |
411 } | 412 } |
412 | 413 |
413 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { | 414 void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { |
414 lock_.AssertAcquired(); | 415 lock_.AssertAcquired(); |
415 | 416 |
416 if (enforce_memory_policy_pending_) | 417 if (enforce_memory_policy_pending_) |
417 return; | 418 return; |
418 | 419 |
419 enforce_memory_policy_pending_ = true; | 420 enforce_memory_policy_pending_ = true; |
420 base::MessageLoop::current()->PostDelayedTask( | 421 base::MessageLoop::current()->PostDelayedTask( |
421 FROM_HERE, | 422 FROM_HERE, |
422 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 423 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
423 weak_ptr_factory_.GetWeakPtr()), | 424 weak_ptr_factory_.GetWeakPtr()), |
424 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 425 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
425 } | 426 } |
426 | 427 |
427 } // namespace content | 428 } // namespace content |
OLD | NEW |