diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 02:03:07 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-18 02:03:07 +0000 |
commit | 2d69fc42827a86e3920647fd3cf01668921d38de (patch) | |
tree | 00aa58c36ea46319bdc19629f34ffed509b7c7de /webkit/child | |
parent | 8aa3d7ba2c378e2e606310dcf4654beff3bed52c (diff) | |
download | chromium_src-2d69fc42827a86e3920647fd3cf01668921d38de.zip chromium_src-2d69fc42827a86e3920647fd3cf01668921d38de.tar.gz chromium_src-2d69fc42827a86e3920647fd3cf01668921d38de.tar.bz2 |
move webkit/glue/web_discardable_memory_impl* to webkit/child
(pipelined on https://codereview.chromium.org/17289003/)
R=jamesr@chromium.org
BUG=239107
Review URL: https://chromiumcodereview.appspot.com/17142003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206875 0039d316-1c4b-4281-b951-d872f2087c98
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*); |