summaryrefslogtreecommitdiffstats
path: root/base/test
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2015-03-16 12:06:21 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-16 19:06:57 +0000
commit2799f7fb3d3a2406b1608f0b9bc470ff76ad4ea0 (patch)
tree3341fbe69860daf6f75b67076a73642caa7d895d /base/test
parent42f59e67e6c4d58a913d48b3a81600cdcd3ced88 (diff)
downloadchromium_src-2799f7fb3d3a2406b1608f0b9bc470ff76ad4ea0.zip
chromium_src-2799f7fb3d3a2406b1608f0b9bc470ff76ad4ea0.tar.gz
chromium_src-2799f7fb3d3a2406b1608f0b9bc470ff76ad4ea0.tar.bz2
Re-land: base: Implement browser process support for discardable memory.
This implements support for in-process discardable memory. Each in-process discardable memory instance is associated with a discardable shared memory segment. This is hopefully efficient enough with the limited use of discardable memory in the browser process. DiscardableSharedMemoryHeap can be used if this is not enough. This also moves the test implementation of the discardable memory allocator into a TestDiscardableMemoryShmemAllocator class and requires tests that use discardable memory to explicitly use this test allocator. Browser tests uses the real discardable memory allocator. BUG=422953,463250 Review URL: https://codereview.chromium.org/1004043002 Cr-Commit-Position: refs/heads/master@{#320764}
Diffstat (limited to 'base/test')
-rw-r--r--base/test/BUILD.gn2
-rw-r--r--base/test/test_discardable_memory_shmem_allocator.cc40
-rw-r--r--base/test/test_discardable_memory_shmem_allocator.h28
3 files changed, 70 insertions, 0 deletions
diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn
index 55e710d..f5d2e4c 100644
--- a/base/test/BUILD.gn
+++ b/base/test/BUILD.gn
@@ -81,6 +81,8 @@ source_set("test_support") {
"simple_test_tick_clock.h",
"task_runner_test_template.cc",
"task_runner_test_template.h",
+ "test_discardable_memory_shmem_allocator.cc",
+ "test_discardable_memory_shmem_allocator.h",
"test_file_util.cc",
"test_file_util.h",
"test_file_util_android.cc",
diff --git a/base/test/test_discardable_memory_shmem_allocator.cc b/base/test/test_discardable_memory_shmem_allocator.cc
new file mode 100644
index 0000000..24185a2
--- /dev/null
+++ b/base/test/test_discardable_memory_shmem_allocator.cc
@@ -0,0 +1,40 @@
+// Copyright 2015 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 "base/test/test_discardable_memory_shmem_allocator.h"
+
+#include <stdint.h>
+
+namespace base {
+namespace {
+
+class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk {
+ public:
+ explicit DiscardableMemoryShmemChunkImpl(size_t size)
+ : memory_(new uint8_t[size]) {}
+
+ // Overridden from DiscardableMemoryShmemChunk:
+ bool Lock() override { return false; }
+ void Unlock() override {}
+ void* Memory() const override { return memory_.get(); }
+
+ private:
+ scoped_ptr<uint8_t[]> memory_;
+};
+
+} // namespace
+
+TestDiscardableMemoryShmemAllocator::TestDiscardableMemoryShmemAllocator() {
+}
+
+TestDiscardableMemoryShmemAllocator::~TestDiscardableMemoryShmemAllocator() {
+}
+
+scoped_ptr<DiscardableMemoryShmemChunk>
+TestDiscardableMemoryShmemAllocator::AllocateLockedDiscardableMemory(
+ size_t size) {
+ return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(size));
+}
+
+} // namespace base
diff --git a/base/test/test_discardable_memory_shmem_allocator.h b/base/test/test_discardable_memory_shmem_allocator.h
new file mode 100644
index 0000000..a40960e
--- /dev/null
+++ b/base/test/test_discardable_memory_shmem_allocator.h
@@ -0,0 +1,28 @@
+// Copyright 2015 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 BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_
+#define BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_
+
+#include "base/memory/discardable_memory_shmem_allocator.h"
+
+namespace base {
+
+class TestDiscardableMemoryShmemAllocator
+ : public DiscardableMemoryShmemAllocator {
+ public:
+ TestDiscardableMemoryShmemAllocator();
+ ~TestDiscardableMemoryShmemAllocator() override;
+
+ // Overridden from DiscardableMemoryShmemAllocator:
+ scoped_ptr<DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory(
+ size_t size) override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestDiscardableMemoryShmemAllocator);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_TEST_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_