diff options
Diffstat (limited to 'webkit/child')
-rw-r--r-- | webkit/child/web_discardable_memory_impl.cc | 41 | ||||
-rw-r--r-- | webkit/child/web_discardable_memory_impl.h | 44 | ||||
-rw-r--r-- | webkit/child/webkitplatformsupport_child_impl.cc | 13 | ||||
-rw-r--r-- | webkit/child/webkitplatformsupport_child_impl.h | 3 |
4 files changed, 101 insertions, 0 deletions
diff --git a/webkit/child/web_discardable_memory_impl.cc b/webkit/child/web_discardable_memory_impl.cc new file mode 100644 index 0000000..0e2663c --- /dev/null +++ b/webkit/child/web_discardable_memory_impl.cc @@ -0,0 +1,41 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/child/web_discardable_memory_impl.h" + +namespace webkit_glue { + +WebDiscardableMemoryImpl::WebDiscardableMemoryImpl() + : discardable_(new base::DiscardableMemory()) { +} + +WebDiscardableMemoryImpl::~WebDiscardableMemoryImpl() {} + +bool WebDiscardableMemoryImpl::InitializeAndLock(size_t size) { + return discardable_->InitializeAndLock(size); +} + +bool WebDiscardableMemoryImpl::lock() { + base::LockDiscardableMemoryStatus status = discardable_->Lock(); + switch (status) { + case base::DISCARDABLE_MEMORY_SUCCESS: + return true; + case base::DISCARDABLE_MEMORY_PURGED: + discardable_->Unlock(); + return false; + default: + discardable_.reset(); + return false; + } +} + +void* WebDiscardableMemoryImpl::data() { + return discardable_->Memory(); +} + +void WebDiscardableMemoryImpl::unlock() { + discardable_->Unlock(); +} + +} // namespace webkit_glue diff --git a/webkit/child/web_discardable_memory_impl.h b/webkit/child/web_discardable_memory_impl.h new file mode 100644 index 0000000..f2ad328 --- /dev/null +++ b/webkit/child/web_discardable_memory_impl.h @@ -0,0 +1,44 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ +#define WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ + +#include "base/memory/discardable_memory.h" +#include "base/memory/scoped_ptr.h" +#include "third_party/WebKit/public/platform/WebDiscardableMemory.h" +#include "webkit/child/webkit_child_export.h" + +namespace WebKit { +class WebDiscardableMemory; +} + +namespace webkit_glue { + +// Implementation of WebDiscardableMemory that is responsible for allocating +// discardable memory. +class WEBKIT_CHILD_EXPORT WebDiscardableMemoryImpl + : NON_EXPORTED_BASE(public WebKit::WebDiscardableMemory) { + public: + WebDiscardableMemoryImpl(); + virtual ~WebDiscardableMemoryImpl(); + + // WebKit::WebDiscardableMemory implementation. + virtual bool lock(); + virtual void unlock(); + virtual void* data(); + + // Initialize the WebDiscardableMemoryImpl object and lock the memory. + // Returns true on success. No memory is allocated if this call returns + // false. This call should only be called once. + bool InitializeAndLock(size_t size); + + private: + scoped_ptr<base::DiscardableMemory> discardable_; + DISALLOW_COPY_AND_ASSIGN(WebDiscardableMemoryImpl); +}; + +} // namespace webkit_glue + +#endif // WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ diff --git a/webkit/child/webkitplatformsupport_child_impl.cc b/webkit/child/webkitplatformsupport_child_impl.cc index 02ee5aa..1df9a12 100644 --- a/webkit/child/webkitplatformsupport_child_impl.cc +++ b/webkit/child/webkitplatformsupport_child_impl.cc @@ -4,8 +4,10 @@ #include "webkit/child/webkitplatformsupport_child_impl.h" +#include "base/memory/discardable_memory.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "webkit/child/fling_curve_configuration.h" +#include "webkit/child/web_discardable_memory_impl.h" #include "webkit/child/webthread_impl.h" #include "webkit/child/worker_task_runner.h" @@ -89,6 +91,17 @@ void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop( worker_task_runner->OnWorkerRunLoopStopped(runLoop); } +WebKit::WebDiscardableMemory* +WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) { + if (!base::DiscardableMemory::Supported()) + return NULL; + scoped_ptr<WebDiscardableMemoryImpl> discardable( + new WebDiscardableMemoryImpl()); + if (discardable->InitializeAndLock(bytes)) + return discardable.release(); + return NULL; +} + // static void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) { WebThreadImplForMessageLoop* impl = diff --git a/webkit/child/webkitplatformsupport_child_impl.h b/webkit/child/webkitplatformsupport_child_impl.h index 21812b2..abb6338 100644 --- a/webkit/child/webkitplatformsupport_child_impl.h +++ b/webkit/child/webkitplatformsupport_child_impl.h @@ -51,6 +51,9 @@ class WEBKIT_CHILD_EXPORT WebKitPlatformSupportChildImpl : virtual void didStopWorkerRunLoop( const WebKit::WebWorkerRunLoop& runLoop) OVERRIDE; + virtual WebKit::WebDiscardableMemory* allocateAndLockDiscardableMemory( + size_t bytes); + private: static void DestroyCurrentThread(void*); |