Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1149)

Unified Diff: base/test/test_discardable_memory_allocator.cc

Issue 1787973002: Replace blink::WebDiscardableMemory with base::DiscardableMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing OwnPtr/PassOwnPtr includes in SharedBufferTest Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/test_discardable_memory_allocator.cc
diff --git a/base/test/test_discardable_memory_allocator.cc b/base/test/test_discardable_memory_allocator.cc
index eef1c982446633c79cdf94bee44ad578c55aed86..7ed0a4565ede26f6b54a011c27e0e9484c665be7 100644
--- a/base/test/test_discardable_memory_allocator.cc
+++ b/base/test/test_discardable_memory_allocator.cc
@@ -4,7 +4,8 @@
#include "base/test/test_discardable_memory_allocator.h"
-#include <stdint.h>
+#include <cstdint>
+#include <cstring>
#include "base/memory/discardable_memory.h"
@@ -13,12 +14,28 @@ namespace {
class DiscardableMemoryImpl : public DiscardableMemory {
public:
- explicit DiscardableMemoryImpl(size_t size) : data_(new uint8_t[size]) {}
+ explicit DiscardableMemoryImpl(size_t size)
+ : data_(new uint8_t[size]), size_(size) {}
// Overridden from DiscardableMemory:
- bool Lock() override { return false; }
- void Unlock() override {}
- void* data() const override { return data_.get(); }
+ bool Lock() override {
+ DCHECK(!is_locked_);
+ is_locked_ = true;
+ return false;
+ }
+
+ void Unlock() override {
+ DCHECK(is_locked_);
+ is_locked_ = false;
+ // Force eviction to catch clients not correctly checking the return value
+ // of Lock().
+ memset(data_.get(), 0, size_);
+ }
+
+ void* data() const override {
+ DCHECK(is_locked_);
+ return data_.get();
+ }
trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump(
const char* name,
@@ -27,7 +44,9 @@ class DiscardableMemoryImpl : public DiscardableMemory {
}
private:
+ bool is_locked_ = true;
scoped_ptr<uint8_t[]> data_;
+ size_t size_;
};
} // namespace
« no previous file with comments | « no previous file | content/child/blink_platform_impl.h » ('j') | third_party/WebKit/Source/platform/PurgeableVector.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698