Get foreground tab on Android
[chromium-blink-merge.git] / webkit / child / web_discardable_memory_impl.cc
blob285f1b0de9a47dce20dedad2610ee2dca244ae96
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.
5 #include "webkit/child/web_discardable_memory_impl.h"
7 namespace webkit_glue {
9 WebDiscardableMemoryImpl::~WebDiscardableMemoryImpl() {}
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()));
21 bool WebDiscardableMemoryImpl::lock() {
22 base::LockDiscardableMemoryStatus status = discardable_->Lock();
23 switch (status) {
24 case base::DISCARDABLE_MEMORY_SUCCESS:
25 return true;
26 case base::DISCARDABLE_MEMORY_PURGED:
27 discardable_->Unlock();
28 return false;
29 default:
30 discardable_.reset();
31 return false;
35 void WebDiscardableMemoryImpl::unlock() {
36 discardable_->Unlock();
39 void* WebDiscardableMemoryImpl::data() {
40 return discardable_->Memory();
43 WebDiscardableMemoryImpl::WebDiscardableMemoryImpl(
44 scoped_ptr<base::DiscardableMemory> memory)
45 : discardable_(memory.Pass()) {
48 } // namespace webkit_glue