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. 4 5 #ifndef WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ 6 #define WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ 7 8 #include "base/memory/discardable_memory.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "third_party/WebKit/public/platform/WebDiscardableMemory.h" 11 #include "webkit/child/webkit_child_export.h" 12 13 namespace WebKit { 14 class WebDiscardableMemory; 15 } 16 17 namespace webkit_glue { 18 19 // Implementation of WebDiscardableMemory that is responsible for allocating 20 // discardable memory. 21 class WEBKIT_CHILD_EXPORT WebDiscardableMemoryImpl 22 : NON_EXPORTED_BASE(public WebKit::WebDiscardableMemory) { 23 public: 24 WebDiscardableMemoryImpl(); 25 virtual ~WebDiscardableMemoryImpl(); 26 27 // WebKit::WebDiscardableMemory implementation. 28 virtual bool lock(); 29 virtual void unlock(); 30 virtual void* data(); 31 32 // Initialize the WebDiscardableMemoryImpl object and lock the memory. 33 // Returns true on success. No memory is allocated if this call returns 34 // false. This call should only be called once. 35 bool InitializeAndLock(size_t size); 36 37 private: 38 scoped_ptr<base::DiscardableMemory> discardable_; 39 DISALLOW_COPY_AND_ASSIGN(WebDiscardableMemoryImpl); 40 }; 41 42 } // namespace webkit_glue 43 44 #endif // WEBKIT_CHILD_WEB_DISCARDABLE_MEMORY_IMPL_H_ 45