summaryrefslogtreecommitdiffstats
path: root/webkit/glue/web_discardable_memory_impl.h
blob: 7f92affb8d58c5d5453bc405f5dac60a6d63a5ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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_