summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/test/test_suite.cc3
-rw-r--r--ash/test/test_suite.h3
-rw-r--r--base/BUILD.gn1
-rw-r--r--base/base.gyp3
-rw-r--r--base/memory/discardable_memory_shmem_allocator.cc43
-rw-r--r--base/memory/discardable_memory_unittest.cc64
-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
-rw-r--r--chrome/test/base/chrome_unit_test_suite.cc3
-rw-r--r--chrome/test/base/chrome_unit_test_suite.h2
-rw-r--r--content/browser/browser_main_loop.cc4
-rw-r--r--content/common/host_discardable_shared_memory_manager.cc159
-rw-r--r--content/common/host_discardable_shared_memory_manager.h4
-rw-r--r--content/renderer/render_thread_impl.cc8
-rw-r--r--content/test/blink_test_environment.cc5
-rw-r--r--ui/app_list/test/run_all_unittests.cc6
-rw-r--r--ui/message_center/test/run_all_unittests.cc6
18 files changed, 220 insertions, 164 deletions
diff --git a/ash/test/test_suite.cc b/ash/test/test_suite.cc
index 1b7eb46..80d61f4 100644
--- a/ash/test/test_suite.cc
+++ b/ash/test/test_suite.cc
@@ -52,6 +52,9 @@ void AuraShellTestSuite::Initialize() {
// output, it'll pass regardless of the system language.
ui::ResourceBundle::InitSharedInstanceWithLocale(
"en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
+
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ &discardable_memory_allocator_);
}
void AuraShellTestSuite::Shutdown() {
diff --git a/ash/test/test_suite.h b/ash/test/test_suite.h
index 33fcd23..e2e0957 100644
--- a/ash/test/test_suite.h
+++ b/ash/test/test_suite.h
@@ -6,6 +6,7 @@
#define ASH_TEST_TEST_SUITE_H_
#include "base/compiler_specific.h"
+#include "base/test/test_discardable_memory_shmem_allocator.h"
#include "base/test/test_suite.h"
#if defined(OS_WIN)
@@ -29,6 +30,8 @@ class AuraShellTestSuite : public base::TestSuite {
#if defined(OS_WIN)
scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
#endif
+
+ base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
};
} // namespace test
diff --git a/base/BUILD.gn b/base/BUILD.gn
index bd81cf6..abba51b 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -1132,7 +1132,6 @@ test("base_unittests") {
"mac/scoped_sending_event_unittest.mm",
"md5_unittest.cc",
"memory/aligned_memory_unittest.cc",
- "memory/discardable_memory_unittest.cc",
"memory/discardable_shared_memory_unittest.cc",
"memory/linked_ptr_unittest.cc",
"memory/ref_counted_memory_unittest.cc",
diff --git a/base/base.gyp b/base/base.gyp
index 5f640d8..c7a2481 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -541,7 +541,6 @@
'mac/scoped_sending_event_unittest.mm',
'md5_unittest.cc',
'memory/aligned_memory_unittest.cc',
- 'memory/discardable_memory_unittest.cc',
'memory/discardable_shared_memory_unittest.cc',
'memory/linked_ptr_unittest.cc',
'memory/ref_counted_memory_unittest.cc',
@@ -976,6 +975,8 @@
'test/simple_test_tick_clock.h',
'test/task_runner_test_template.cc',
'test/task_runner_test_template.h',
+ 'test/test_discardable_memory_shmem_allocator.cc',
+ 'test/test_discardable_memory_shmem_allocator.h',
'test/test_file_util.cc',
'test/test_file_util.h',
'test/test_file_util_android.cc',
diff --git a/base/memory/discardable_memory_shmem_allocator.cc b/base/memory/discardable_memory_shmem_allocator.cc
index 761204f..a87c58d 100644
--- a/base/memory/discardable_memory_shmem_allocator.cc
+++ b/base/memory/discardable_memory_shmem_allocator.cc
@@ -11,45 +11,6 @@
namespace base {
namespace {
-class DiscardableMemoryShmemChunkImpl : public DiscardableMemoryShmemChunk {
- public:
- explicit DiscardableMemoryShmemChunkImpl(
- scoped_ptr<DiscardableSharedMemory> shared_memory)
- : shared_memory_(shared_memory.Pass()) {}
-
- // Overridden from DiscardableMemoryShmemChunk:
- bool Lock() override { return false; }
- void Unlock() override {
- shared_memory_->Unlock(0, 0);
- shared_memory_.reset();
- }
- void* Memory() const override { return shared_memory_->memory(); }
-
- private:
- scoped_ptr<DiscardableSharedMemory> shared_memory_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
-};
-
-// Default allocator implementation that allocates in-process
-// DiscardableSharedMemory instances.
-class DiscardableMemoryShmemAllocatorImpl
- : public DiscardableMemoryShmemAllocator {
- public:
- // Overridden from DiscardableMemoryShmemAllocator:
- scoped_ptr<DiscardableMemoryShmemChunk>
- AllocateLockedDiscardableMemory(size_t size) override {
- scoped_ptr<DiscardableSharedMemory> memory(new DiscardableSharedMemory);
- if (!memory->CreateAndMap(size))
- return nullptr;
-
- return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(memory.Pass()));
- }
-};
-
-LazyInstance<DiscardableMemoryShmemAllocatorImpl>::Leaky g_default_allocator =
- LAZY_INSTANCE_INITIALIZER;
-
DiscardableMemoryShmemAllocator* g_allocator = nullptr;
} // namespace
@@ -69,9 +30,7 @@ void DiscardableMemoryShmemAllocator::SetInstance(
// static
DiscardableMemoryShmemAllocator*
DiscardableMemoryShmemAllocator::GetInstance() {
- if (!g_allocator)
- g_allocator = g_default_allocator.Pointer();
-
+ DCHECK(g_allocator);
return g_allocator;
}
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc
deleted file mode 100644
index 60750746..0000000
--- a/base/memory/discardable_memory_unittest.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// 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 "base/memory/discardable_memory.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace {
-
-const size_t kSize = 1024;
-
-// Test Lock() and Unlock() functionalities.
-TEST(DiscardableMemoryTest, LockAndUnLock) {
- const scoped_ptr<DiscardableMemory> memory(
- DiscardableMemory::CreateLockedMemory(kSize));
- ASSERT_TRUE(memory);
- void* addr = memory->Memory();
- EXPECT_NE(nullptr, addr);
- memory->Unlock();
-}
-
-// Test delete a discardable memory while it is locked.
-TEST(DiscardableMemoryTest, DeleteWhileLocked) {
- const scoped_ptr<DiscardableMemory> memory(
- DiscardableMemory::CreateLockedMemory(kSize));
- ASSERT_TRUE(memory);
-}
-
-#if !defined(NDEBUG) && !defined(OS_ANDROID)
-// Death tests are not supported with Android APKs.
-TEST(DiscardableMemoryTest, UnlockedMemoryAccessCrashesInDebugMode) {
- const scoped_ptr<DiscardableMemory> memory(
- DiscardableMemory::CreateLockedMemory(kSize));
- ASSERT_TRUE(memory);
- memory->Unlock();
- ASSERT_DEATH_IF_SUPPORTED(
- { *static_cast<int*>(memory->Memory()) = 0xdeadbeef; }, ".*");
-}
-#endif
-
-// Test behavior when creating enough instances that could use up a 32-bit
-// address space.
-// This is disabled under AddressSanitizer on Windows as it crashes (by design)
-// on OOM. See http://llvm.org/PR22026 for the details.
-#if !defined(ADDRESS_SANITIZER) || !defined(OS_WIN)
-TEST(DiscardableMemoryTest, AddressSpace) {
- const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB.
- const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
-
- scoped_ptr<DiscardableMemory> instances[kNumberOfInstances];
- for (auto& memory : instances) {
- memory = DiscardableMemory::CreateLockedMemory(kLargeSize);
- ASSERT_TRUE(memory);
- void* addr = memory->Memory();
- EXPECT_NE(nullptr, addr);
- memory->Unlock();
- }
-}
-#endif
-
-} // namespace
-} // namespace base
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_
diff --git a/chrome/test/base/chrome_unit_test_suite.cc b/chrome/test/base/chrome_unit_test_suite.cc
index c78d463..2ce04bd 100644
--- a/chrome/test/base/chrome_unit_test_suite.cc
+++ b/chrome/test/base/chrome_unit_test_suite.cc
@@ -110,6 +110,9 @@ void ChromeUnitTestSuite::Initialize() {
// This needs to run after ChromeTestSuite::Initialize which calls content's
// intialization which calls base's which initializes ICU.
InitializeResourceBundle();
+
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ &discardable_memory_allocator_);
}
void ChromeUnitTestSuite::Shutdown() {
diff --git a/chrome/test/base/chrome_unit_test_suite.h b/chrome/test/base/chrome_unit_test_suite.h
index a8bb208..404c59f 100644
--- a/chrome/test/base/chrome_unit_test_suite.h
+++ b/chrome/test/base/chrome_unit_test_suite.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
+#include "base/test/test_discardable_memory_shmem_allocator.h"
#include "chrome/test/base/chrome_test_suite.h"
// Test suite for unit tests. Creates additional stub services that are not
@@ -28,6 +29,7 @@ class ChromeUnitTestSuite : public ChromeTestSuite {
static void InitializeResourceBundle();
private:
+ base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
DISALLOW_COPY_AND_ASSIGN(ChromeUnitTestSuite);
};
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index cbb70ac..bf495b9 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -41,6 +41,7 @@
#include "content/browser/webui/content_web_ui_controller_factory.h"
#include "content/browser/webui/url_data_manager.h"
#include "content/common/content_switches_internal.h"
+#include "content/common/host_discardable_shared_memory_manager.h"
#include "content/public/browser/browser_main_parts.h"
#include "content/public/browser/browser_shutdown.h"
#include "content/public/browser/content_browser_client.h"
@@ -460,6 +461,9 @@ void BrowserMainLoop::EarlyInitialization() {
gfx::GpuMemoryBuffer::SCANOUT);
#endif
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ HostDiscardableSharedMemoryManager::current());
+
if (parts_)
parts_->PostEarlyInitialization();
}
diff --git a/content/common/host_discardable_shared_memory_manager.cc b/content/common/host_discardable_shared_memory_manager.cc
index e150fc6..3d2be9d 100644
--- a/content/common/host_discardable_shared_memory_manager.cc
+++ b/content/common/host_discardable_shared_memory_manager.cc
@@ -18,6 +18,46 @@
namespace content {
namespace {
+class DiscardableMemoryShmemChunkImpl
+ : public base::DiscardableMemoryShmemChunk {
+ public:
+ explicit DiscardableMemoryShmemChunkImpl(
+ scoped_ptr<base::DiscardableSharedMemory> shared_memory)
+ : shared_memory_(shared_memory.Pass()), is_locked_(true) {}
+ ~DiscardableMemoryShmemChunkImpl() override {
+ if (is_locked_)
+ shared_memory_->Unlock(0, 0);
+ shared_memory_->Purge(base::Time::Now());
+ }
+
+ // Overridden from base::DiscardableMemoryShmemChunk:
+ bool Lock() override {
+ DCHECK(!is_locked_);
+
+ if (shared_memory_->Lock(0, 0) != base::DiscardableSharedMemory::SUCCESS)
+ return false;
+
+ is_locked_ = true;
+ return true;
+ }
+ void Unlock() override {
+ DCHECK(is_locked_);
+
+ shared_memory_->Unlock(0, 0);
+ is_locked_ = false;
+ }
+ void* Memory() const override {
+ DCHECK(is_locked_);
+ return shared_memory_->memory();
+ }
+
+ private:
+ scoped_ptr<base::DiscardableSharedMemory> shared_memory_;
+ bool is_locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
+};
+
base::LazyInstance<HostDiscardableSharedMemoryManager>
g_discardable_shared_memory_manager = LAZY_INSTANCE_INITIALIZER;
@@ -61,10 +101,16 @@ HostDiscardableSharedMemoryManager::current() {
scoped_ptr<base::DiscardableMemoryShmemChunk>
HostDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
size_t size) {
- // TODO(reveman): Need to implement this for discardable memory support in
- // the browser process.
- NOTIMPLEMENTED();
- return nullptr;
+ // Note: Use DiscardableSharedMemoryHeap for in-process allocation
+ // of discardable memory if the cost of each allocation is too high.
+ base::SharedMemoryHandle handle;
+ AllocateLockedDiscardableSharedMemory(base::GetCurrentProcessHandle(), size,
+ &handle);
+ CHECK(base::SharedMemory::IsHandleValid(handle));
+ scoped_ptr<base::DiscardableSharedMemory> memory(
+ new base::DiscardableSharedMemory(handle));
+ CHECK(memory->Map(size));
+ return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(memory.Pass()));
}
void HostDiscardableSharedMemoryManager::
@@ -72,11 +118,60 @@ void HostDiscardableSharedMemoryManager::
base::ProcessHandle process_handle,
size_t size,
base::SharedMemoryHandle* shared_memory_handle) {
+ AllocateLockedDiscardableSharedMemory(process_handle, size,
+ shared_memory_handle);
+}
+
+void HostDiscardableSharedMemoryManager::ProcessRemoved(
+ base::ProcessHandle process_handle) {
+ base::AutoLock lock(lock_);
+
+ size_t bytes_allocated_before_purging = bytes_allocated_;
+ for (auto& segment : segments_) {
+ // Skip segments that belong to a different process.
+ if (segment.process_handle != process_handle)
+ continue;
+
+ size_t size = segment.memory->mapped_size();
+ DCHECK_GE(bytes_allocated_, size);
+
+ // This will unmap the memory segment and drop our reference. The result
+ // is that the memory will be released to the OS if the child process is
+ // no longer referencing it.
+ // Note: We intentionally leave the segment in the vector to avoid
+ // reconstructing the heap. The element will be removed from the heap
+ // when its last usage time is older than all other segments.
+ segment.memory->Close();
+ bytes_allocated_ -= size;
+ }
+
+ if (bytes_allocated_ != bytes_allocated_before_purging)
+ BytesAllocatedChanged(bytes_allocated_);
+}
+
+void HostDiscardableSharedMemoryManager::SetMemoryLimit(size_t limit) {
+ base::AutoLock lock(lock_);
+
+ memory_limit_ = limit;
+ ReduceMemoryUsageUntilWithinMemoryLimit();
+}
+
+void HostDiscardableSharedMemoryManager::EnforceMemoryPolicy() {
+ base::AutoLock lock(lock_);
+
+ enforce_memory_policy_pending_ = false;
+ ReduceMemoryUsageUntilWithinMemoryLimit();
+}
+
+void HostDiscardableSharedMemoryManager::AllocateLockedDiscardableSharedMemory(
+ base::ProcessHandle process_handle,
+ size_t size,
+ base::SharedMemoryHandle* shared_memory_handle) {
// TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466405
// is fixed.
tracked_objects::ScopedTracker tracking_profile1(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "466405 AllocateLockedDiscardableSharedMemoryForChild::Start"));
+ "466405 AllocateLockedDiscardableSharedMemory::Start"));
base::AutoLock lock(lock_);
// Memory usage must be reduced to prevent the addition of |size| from
@@ -94,8 +189,7 @@ void HostDiscardableSharedMemoryManager::
// is fixed.
tracked_objects::ScopedTracker tracking_profile2(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "466405 "
- "AllocateLockedDiscardableSharedMemoryForChild::ReduceMemoryUsage"));
+ "466405 AllocateLockedDiscardableSharedMemory::ReduceMemoryUsage"));
if (bytes_allocated_ > limit)
ReduceMemoryUsageUntilWithinLimit(limit);
@@ -103,7 +197,7 @@ void HostDiscardableSharedMemoryManager::
// is fixed.
tracked_objects::ScopedTracker tracking_profile3(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "466405 AllocateLockedDiscardableSharedMemoryForChild::NewMemory"));
+ "466405 AllocateLockedDiscardableSharedMemory::NewMemory"));
linked_ptr<base::DiscardableSharedMemory> memory(
new base::DiscardableSharedMemory);
if (!memory->CreateAndMap(size)) {
@@ -115,8 +209,7 @@ void HostDiscardableSharedMemoryManager::
// is fixed.
tracked_objects::ScopedTracker tracking_profile4(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
- "466405 "
- "AllocateLockedDiscardableSharedMemoryForChild::ShareToProcess"));
+ "466405 AllocateLockedDiscardableSharedMemory::ShareToProcess"));
if (!memory->ShareToProcess(process_handle, shared_memory_handle)) {
LOG(ERROR) << "Cannot share discardable memory segment";
*shared_memory_handle = base::SharedMemory::NULLHandle();
@@ -135,8 +228,7 @@ void HostDiscardableSharedMemoryManager::
tracked_objects::ScopedTracker tracking_profile5(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"466405 "
- "AllocateLockedDiscardableSharedMemoryForChild::"
- "BytesAllocatedChanged"));
+ "AllocateLockedDiscardableSharedMemory::BytesAllocatedChanged"));
bytes_allocated_ = checked_bytes_allocated.ValueOrDie();
BytesAllocatedChanged(bytes_allocated_);
@@ -148,53 +240,12 @@ void HostDiscardableSharedMemoryManager::
tracked_objects::ScopedTracker tracking_profile6(
FROM_HERE_WITH_EXPLICIT_FUNCTION(
"466405 "
- "AllocateLockedDiscardableSharedMemoryForChild::"
+ "AllocateLockedDiscardableSharedMemory::"
"ScheduleEnforceMemoryPolicy"));
if (bytes_allocated_ > memory_limit_)
ScheduleEnforceMemoryPolicy();
}
-void HostDiscardableSharedMemoryManager::ProcessRemoved(
- base::ProcessHandle process_handle) {
- base::AutoLock lock(lock_);
-
- size_t bytes_allocated_before_purging = bytes_allocated_;
- for (auto& segment : segments_) {
- // Skip segments that belong to a different process.
- if (segment.process_handle != process_handle)
- continue;
-
- size_t size = segment.memory->mapped_size();
- DCHECK_GE(bytes_allocated_, size);
-
- // This will unmap the memory segment and drop our reference. The result
- // is that the memory will be released to the OS if the child process is
- // no longer referencing it.
- // Note: We intentionally leave the segment in the vector to avoid
- // reconstructing the heap. The element will be removed from the heap
- // when its last usage time is older than all other segments.
- segment.memory->Close();
- bytes_allocated_ -= size;
- }
-
- if (bytes_allocated_ != bytes_allocated_before_purging)
- BytesAllocatedChanged(bytes_allocated_);
-}
-
-void HostDiscardableSharedMemoryManager::SetMemoryLimit(size_t limit) {
- base::AutoLock lock(lock_);
-
- memory_limit_ = limit;
- ReduceMemoryUsageUntilWithinMemoryLimit();
-}
-
-void HostDiscardableSharedMemoryManager::EnforceMemoryPolicy() {
- base::AutoLock lock(lock_);
-
- enforce_memory_policy_pending_ = false;
- ReduceMemoryUsageUntilWithinMemoryLimit();
-}
-
void HostDiscardableSharedMemoryManager::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
base::AutoLock lock(lock_);
diff --git a/content/common/host_discardable_shared_memory_manager.h b/content/common/host_discardable_shared_memory_manager.h
index 624dd2f..6998f0d 100644
--- a/content/common/host_discardable_shared_memory_manager.h
+++ b/content/common/host_discardable_shared_memory_manager.h
@@ -71,6 +71,10 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager
return a.memory->last_known_usage() > b.memory->last_known_usage();
}
+ void AllocateLockedDiscardableSharedMemory(
+ base::ProcessHandle process_handle,
+ size_t size,
+ base::SharedMemoryHandle* shared_memory_handle);
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
void ReduceMemoryUsageUntilWithinMemoryLimit();
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 184bcc6..4e8819c 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -656,8 +656,12 @@ void RenderThreadImpl::Init() {
#endif
}
- base::DiscardableMemoryShmemAllocator::SetInstance(
- ChildThreadImpl::discardable_shared_memory_manager());
+ // In single process, browser main loop set up the discardable memory
+ // allocator.
+ if (!command_line.HasSwitch(switches::kSingleProcess)) {
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ ChildThreadImpl::discardable_shared_memory_manager());
+ }
service_registry()->AddService<RenderFrameSetup>(
base::Bind(CreateRenderFrameSetup));
diff --git a/content/test/blink_test_environment.cc b/content/test/blink_test_environment.cc
index 816983c..16b35a6 100644
--- a/content/test/blink_test_environment.cc
+++ b/content/test/blink_test_environment.cc
@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/string_tokenizer.h"
+#include "base/test/test_discardable_memory_shmem_allocator.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/user_agent.h"
@@ -67,6 +68,9 @@ class TestEnvironment {
// TestBlinkWebUnitTestSupport must be instantiated after MessageLoopType.
blink_test_support_.reset(new TestBlinkWebUnitTestSupport);
content_initializer_.reset(new content::TestContentClientInitializer());
+
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ &discardable_memory_allocator_);
}
~TestEnvironment() {
@@ -80,6 +84,7 @@ class TestEnvironment {
scoped_ptr<MessageLoopType> main_message_loop_;
scoped_ptr<TestBlinkWebUnitTestSupport> blink_test_support_;
scoped_ptr<TestContentClientInitializer> content_initializer_;
+ base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
};
TestEnvironment* test_environment;
diff --git a/ui/app_list/test/run_all_unittests.cc b/ui/app_list/test/run_all_unittests.cc
index b60b438..5da865b 100644
--- a/ui/app_list/test/run_all_unittests.cc
+++ b/ui/app_list/test/run_all_unittests.cc
@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/path_service.h"
#include "base/test/launcher/unit_test_launcher.h"
+#include "base/test/test_discardable_memory_shmem_allocator.h"
#include "base/test/test_suite.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
@@ -40,6 +41,9 @@ class AppListTestSuite : public base::TestSuite {
base::FilePath ui_test_pak_path;
ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
+
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ &discardable_memory_allocator_);
}
void Shutdown() override {
@@ -48,6 +52,8 @@ class AppListTestSuite : public base::TestSuite {
}
private:
+ base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+
DISALLOW_COPY_AND_ASSIGN(AppListTestSuite);
};
diff --git a/ui/message_center/test/run_all_unittests.cc b/ui/message_center/test/run_all_unittests.cc
index fa53d67..b0cc026 100644
--- a/ui/message_center/test/run_all_unittests.cc
+++ b/ui/message_center/test/run_all_unittests.cc
@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/path_service.h"
#include "base/test/launcher/unit_test_launcher.h"
+#include "base/test/test_discardable_memory_shmem_allocator.h"
#include "base/test/test_suite.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
@@ -37,6 +38,9 @@ class MessageCenterTestSuite : public base::TestSuite {
base::FilePath ui_test_pak_path;
ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
+
+ base::DiscardableMemoryShmemAllocator::SetInstance(
+ &discardable_memory_allocator_);
}
void Shutdown() override {
@@ -45,6 +49,8 @@ class MessageCenterTestSuite : public base::TestSuite {
}
private:
+ base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+
DISALLOW_COPY_AND_ASSIGN(MessageCenterTestSuite);
};