1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "webkit/child/web_discardable_memory_impl.h" 6 7 namespace webkit_glue { 8 9 WebDiscardableMemoryImpl::WebDiscardableMemoryImpl() 10 : discardable_(new base::DiscardableMemory()) { 11 } 12 13 WebDiscardableMemoryImpl::~WebDiscardableMemoryImpl() {} 14 15 bool WebDiscardableMemoryImpl::InitializeAndLock(size_t size) { 16 return discardable_->InitializeAndLock(size); 17 } 18 19 bool WebDiscardableMemoryImpl::lock() { 20 base::LockDiscardableMemoryStatus status = discardable_->Lock(); 21 switch (status) { 22 case base::DISCARDABLE_MEMORY_SUCCESS: 23 return true; 24 case base::DISCARDABLE_MEMORY_PURGED: 25 discardable_->Unlock(); 26 return false; 27 default: 28 discardable_.reset(); 29 return false; 30 } 31 } 32 33 void* WebDiscardableMemoryImpl::data() { 34 return discardable_->Memory(); 35 } 36 37 void WebDiscardableMemoryImpl::unlock() { 38 discardable_->Unlock(); 39 } 40 41 } // namespace webkit_glue 42