Home | History | Annotate | Download | only in child
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/child/web_discardable_memory_impl.h"
      6 
      7 namespace content {
      8 
      9 WebDiscardableMemoryImpl::~WebDiscardableMemoryImpl() {}
     10 
     11 // static
     12 scoped_ptr<WebDiscardableMemoryImpl>
     13 WebDiscardableMemoryImpl::CreateLockedMemory(size_t size) {
     14   scoped_ptr<base::DiscardableMemory> memory(
     15       base::DiscardableMemory::CreateLockedMemory(size));
     16   if (!memory)
     17     return scoped_ptr<WebDiscardableMemoryImpl>();
     18   return make_scoped_ptr(new WebDiscardableMemoryImpl(memory.Pass()));
     19 }
     20 
     21 bool WebDiscardableMemoryImpl::lock() {
     22   base::DiscardableMemoryLockStatus status = discardable_->Lock();
     23   switch (status) {
     24     case base::DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS:
     25       return true;
     26     case base::DISCARDABLE_MEMORY_LOCK_STATUS_PURGED:
     27       discardable_->Unlock();
     28       return false;
     29     default:
     30       discardable_.reset();
     31       return false;
     32   }
     33 }
     34 
     35 void WebDiscardableMemoryImpl::unlock() {
     36   discardable_->Unlock();
     37 }
     38 
     39 void* WebDiscardableMemoryImpl::data() {
     40   return discardable_->Memory();
     41 }
     42 
     43 WebDiscardableMemoryImpl::WebDiscardableMemoryImpl(
     44     scoped_ptr<base::DiscardableMemory> memory)
     45     : discardable_(memory.Pass()) {
     46 }
     47 
     48 }  // namespace content
     49