Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: content/child/child_discardable_shared_memory_manager.cc

Issue 1039043002: Add base::TerminateBecauseOutOfMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Thu Mar 26 16:12:29 PDT 2015 Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/child/child_discardable_shared_memory_manager.h" 5 #include "content/child/child_discardable_shared_memory_manager.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/debug/crash_logging.h" 9 #include "base/debug/crash_logging.h"
10 #include "base/memory/discardable_memory.h" 10 #include "base/memory/discardable_memory.h"
11 #include "base/memory/discardable_shared_memory.h" 11 #include "base/memory/discardable_shared_memory.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/process/memory.h"
13 #include "base/process/process_metrics.h" 14 #include "base/process/process_metrics.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
16 #include "content/common/child_process_messages.h" 17 #include "content/common/child_process_messages.h"
17 18
18 namespace content { 19 namespace content {
19 namespace { 20 namespace {
20 21
21 // Default allocation size. 22 // Default allocation size.
22 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 DiscardableSharedMemoryId id) { 258 DiscardableSharedMemoryId id) {
258 TRACE_EVENT2("renderer", 259 TRACE_EVENT2("renderer",
259 "ChildDiscardableSharedMemoryManager::" 260 "ChildDiscardableSharedMemoryManager::"
260 "AllocateLockedDiscardableSharedMemory", 261 "AllocateLockedDiscardableSharedMemory",
261 "size", size, "id", id); 262 "size", size, "id", id);
262 263
263 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle(); 264 base::SharedMemoryHandle handle = base::SharedMemory::NULLHandle();
264 sender_->Send( 265 sender_->Send(
265 new ChildProcessHostMsg_SyncAllocateLockedDiscardableSharedMemory( 266 new ChildProcessHostMsg_SyncAllocateLockedDiscardableSharedMemory(
266 size, id, &handle)); 267 size, id, &handle));
267 CHECK(base::SharedMemory::IsHandleValid(handle)); 268 CHECK(base::SharedMemory::IsHandleValid(handle));
reveman 2015/03/27 05:05:20 This is an OOM error too. You can just remove this
Vitaly Buka (NO REVIEWS) 2015/03/27 06:29:14 Done.
268 scoped_ptr<base::DiscardableSharedMemory> memory( 269 scoped_ptr<base::DiscardableSharedMemory> memory(
269 new base::DiscardableSharedMemory(handle)); 270 new base::DiscardableSharedMemory(handle));
270 CHECK(memory->Map(size)); 271 if (!memory->Map(size))
272 base::CrashWithOutOfMemory();
271 return memory.Pass(); 273 return memory.Pass();
272 } 274 }
273 275
274 void ChildDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory( 276 void ChildDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory(
275 DiscardableSharedMemoryId id) { 277 DiscardableSharedMemoryId id) {
276 sender_->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id)); 278 sender_->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id));
277 } 279 }
278 280
279 void ChildDiscardableSharedMemoryManager::MemoryUsageChanged( 281 void ChildDiscardableSharedMemoryManager::MemoryUsageChanged(
280 size_t new_bytes_total, 282 size_t new_bytes_total,
281 size_t new_bytes_free) const { 283 size_t new_bytes_free) const {
282 TRACE_COUNTER2("renderer", "DiscardableMemoryUsage", "allocated", 284 TRACE_COUNTER2("renderer", "DiscardableMemoryUsage", "allocated",
283 new_bytes_total - new_bytes_free, "free", new_bytes_free); 285 new_bytes_total - new_bytes_free, "free", new_bytes_free);
284 286
285 static const char kDiscardableMemoryAllocatedKey[] = 287 static const char kDiscardableMemoryAllocatedKey[] =
286 "discardable-memory-allocated"; 288 "discardable-memory-allocated";
287 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, 289 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey,
288 base::Uint64ToString(new_bytes_total)); 290 base::Uint64ToString(new_bytes_total));
289 291
290 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; 292 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free";
291 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, 293 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey,
292 base::Uint64ToString(new_bytes_free)); 294 base::Uint64ToString(new_bytes_free));
293 } 295 }
294 296
295 } // namespace content 297 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698