diff options
author | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-25 00:28:17 +0000 |
---|---|---|
committer | qinmin@chromium.org <qinmin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-25 00:28:17 +0000 |
commit | 989738aa9b54e3b08e098a821b49cfa0c567c551 (patch) | |
tree | 9e6b66cf8d7e5ed10dedfd2eda80a5448c06c0a8 /webkit | |
parent | 216be77033945a68340ad75b06911e5b0ce7bb62 (diff) | |
download | chromium_src-989738aa9b54e3b08e098a821b49cfa0c567c551.zip chromium_src-989738aa9b54e3b08e098a821b49cfa0c567c551.tar.gz chromium_src-989738aa9b54e3b08e098a821b49cfa0c567c551.tar.bz2 |
Add implementation for WebKit::WebDiscardableMemory and WebKitPlatformSupportImpl::allocateAndLockDiscardableMemory
https://bugs.webkit.org/show_bug.cgi?id=107183 added WebDiscardableMemory and
the allocateAndLockDiscardableMemory() call
This CL adds implementation for that.
BUG=164052
Review URL: https://codereview.chromium.org/12045053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178711 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/web_discardable_memory_impl.cc | 41 | ||||
-rw-r--r-- | webkit/glue/web_discardable_memory_impl.h | 44 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/glue/webkitplatformsupport_impl.cc | 14 | ||||
-rw-r--r-- | webkit/glue/webkitplatformsupport_impl.h | 2 |
5 files changed, 103 insertions, 0 deletions
diff --git a/webkit/glue/web_discardable_memory_impl.cc b/webkit/glue/web_discardable_memory_impl.cc new file mode 100644 index 0000000..d4c3ee2 --- /dev/null +++ b/webkit/glue/web_discardable_memory_impl.cc @@ -0,0 +1,41 @@ +// Copyright (c) 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/glue/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/glue/web_discardable_memory_impl.h b/webkit/glue/web_discardable_memory_impl.h new file mode 100644 index 0000000..7f92aff --- /dev/null +++ b/webkit/glue/web_discardable_memory_impl.h @@ -0,0 +1,44 @@ +// Copyright (c) 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_GLUE_WEB_DISCARDABLE_MEMORY_IMPL_H_ +#define WEBKIT_GLUE_WEB_DISCARDABLE_MEMORY_IMPL_H_ + +#include "base/memory/discardable_memory.h" +#include "base/memory/scoped_ptr.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebDiscardableMemory.h" +#include "webkit/glue/webkit_glue_export.h" + +namespace WebKit { +class WebDiscardableMemory; +} + +namespace webkit_glue { + +// Implementation of WebDiscardableMemory that is responsible for allocating +// discardable memory. +class WEBKIT_GLUE_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_GLUE_WEB_DISCARDABLE_MEMORY_IMPL_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 814d5c5..ad0b4de 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -314,6 +314,8 @@ 'simple_webmimeregistry_impl.h', 'touch_fling_gesture_curve.cc', 'touch_fling_gesture_curve.h', + 'web_discardable_memory_impl.cc', + 'web_discardable_memory_impl.h', 'webclipboard_impl.cc', 'webclipboard_impl.h', 'webcookie.cc', diff --git a/webkit/glue/webkitplatformsupport_impl.cc b/webkit/glue/webkitplatformsupport_impl.cc index 6ebd52a..409d700 100644 --- a/webkit/glue/webkitplatformsupport_impl.cc +++ b/webkit/glue/webkitplatformsupport_impl.cc @@ -11,6 +11,7 @@ #include "base/allocator/allocator_extension.h" #include "base/bind.h" #include "base/debug/trace_event.h" +#include "base/memory/discardable_memory.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/message_loop.h" @@ -30,6 +31,7 @@ #include "grit/webkit_strings.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebCookie.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebDiscardableMemory.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurve.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" @@ -42,6 +44,7 @@ #include "webkit/base/file_path_string_conversions.h" #include "webkit/compositor_bindings/web_compositor_support_impl.h" #include "webkit/glue/touch_fling_gesture_curve.h" +#include "webkit/glue/web_discardable_memory_impl.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/websocketstreamhandle_impl.h" #include "webkit/glue/webthread_impl.h" @@ -928,4 +931,15 @@ WebKit::WebGestureCurve* WebKitPlatformSupportImpl::createFlingAnimationCurve( return TouchFlingGestureCurve::CreateForTouchPad(velocity, cumulative_scroll); } +WebKit::WebDiscardableMemory* + WebKitPlatformSupportImpl::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; +} + } // namespace webkit_glue diff --git a/webkit/glue/webkitplatformsupport_impl.h b/webkit/glue/webkitplatformsupport_impl.h index 8f858a2..8d928ba 100644 --- a/webkit/glue/webkitplatformsupport_impl.h +++ b/webkit/glue/webkitplatformsupport_impl.h @@ -118,6 +118,8 @@ class WEBKIT_GLUE_EXPORT WebKitPlatformSupportImpl : virtual WebKit::WebThread* createThread(const char* name); virtual WebKit::WebThread* currentThread(); virtual WebKit::WebCompositorSupport* compositorSupport(); + virtual WebKit::WebDiscardableMemory* allocateAndLockDiscardableMemory( + size_t bytes); // Embedder functions. The following are not implemented by the glue layer and |