summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2015-03-17 16:18:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-17 23:19:02 +0000
commit1af05cb3770b3e3eb61d3731a09efcd1fbec242b (patch)
treeca5db72a1069a452a3894373db195dce852784dc
parent93fb9e3408ee0b5788ee65b69c864d43f3360d3f (diff)
downloadchromium_src-1af05cb3770b3e3eb61d3731a09efcd1fbec242b.zip
chromium_src-1af05cb3770b3e3eb61d3731a09efcd1fbec242b.tar.gz
chromium_src-1af05cb3770b3e3eb61d3731a09efcd1fbec242b.tar.bz2
base: Rename discardable memory allocator interface and remove unnecessary class.
There's only one discardable memory allocator interface. Rename it to DiscardableMemoryAllocator. DiscardableMemoryShmemChunk class is unnecessary, remove it. BUG=442945,422953 Review URL: https://codereview.chromium.org/1001873002 Cr-Commit-Position: refs/heads/master@{#321008}
-rw-r--r--ash/test/test_suite.cc3
-rw-r--r--ash/test/test_suite.h4
-rw-r--r--base/base.gyp4
-rw-r--r--base/base.gypi6
-rw-r--r--base/memory/BUILD.gn12
-rw-r--r--base/memory/discardable_memory.cc5
-rw-r--r--base/memory/discardable_memory_allocator.cc34
-rw-r--r--base/memory/discardable_memory_allocator.h32
-rw-r--r--base/memory/discardable_memory_shmem.cc50
-rw-r--r--base/memory/discardable_memory_shmem.h37
-rw-r--r--base/memory/discardable_memory_shmem_allocator.cc37
-rw-r--r--base/memory/discardable_memory_shmem_allocator.h42
-rw-r--r--base/test/BUILD.gn4
-rw-r--r--base/test/test_discardable_memory_allocator.cc40
-rw-r--r--base/test/test_discardable_memory_allocator.h30
-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.h4
-rw-r--r--content/browser/browser_main_loop.cc2
-rw-r--r--content/child/child_discardable_shared_memory_manager.cc50
-rw-r--r--content/child/child_discardable_shared_memory_manager.h10
-rw-r--r--content/child/child_discardable_shared_memory_manager_browsertest.cc17
-rw-r--r--content/common/host_discardable_shared_memory_manager.cc20
-rw-r--r--content/common/host_discardable_shared_memory_manager.h15
-rw-r--r--content/renderer/render_thread_impl.cc5
-rw-r--r--content/test/blink_test_environment.cc6
-rw-r--r--ui/app_list/test/run_all_unittests.cc6
-rw-r--r--ui/message_center/test/run_all_unittests.cc6
29 files changed, 230 insertions, 322 deletions
diff --git a/ash/test/test_suite.cc b/ash/test/test_suite.cc
index 80d61f4..4f1ead0 100644
--- a/ash/test/test_suite.cc
+++ b/ash/test/test_suite.cc
@@ -53,8 +53,7 @@ void AuraShellTestSuite::Initialize() {
ui::ResourceBundle::InitSharedInstanceWithLocale(
"en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
- base::DiscardableMemoryShmemAllocator::SetInstance(
- &discardable_memory_allocator_);
+ base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
}
void AuraShellTestSuite::Shutdown() {
diff --git a/ash/test/test_suite.h b/ash/test/test_suite.h
index e2e0957..e740bac 100644
--- a/ash/test/test_suite.h
+++ b/ash/test/test_suite.h
@@ -6,7 +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_discardable_memory_allocator.h"
#include "base/test/test_suite.h"
#if defined(OS_WIN)
@@ -31,7 +31,7 @@ class AuraShellTestSuite : public base::TestSuite {
scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
#endif
- base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+ base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
};
} // namespace test
diff --git a/base/base.gyp b/base/base.gyp
index c7a2481..80da0d1 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -975,8 +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_discardable_memory_allocator.cc',
+ 'test/test_discardable_memory_allocator.h',
'test/test_file_util.cc',
'test/test_file_util.h',
'test/test_file_util_android.cc',
diff --git a/base/base.gypi b/base/base.gypi
index 13cba85..05e5de4 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -318,10 +318,8 @@
'memory/aligned_memory.h',
'memory/discardable_memory.cc',
'memory/discardable_memory.h',
- 'memory/discardable_memory_shmem.cc',
- 'memory/discardable_memory_shmem.h',
- 'memory/discardable_memory_shmem_allocator.cc',
- 'memory/discardable_memory_shmem_allocator.h',
+ 'memory/discardable_memory_allocator.cc',
+ 'memory/discardable_memory_allocator.h',
'memory/discardable_shared_memory.cc',
'memory/discardable_shared_memory.h',
'memory/linked_ptr.h',
diff --git a/base/memory/BUILD.gn b/base/memory/BUILD.gn
index 3d4c22cd..a0608e8 100644
--- a/base/memory/BUILD.gn
+++ b/base/memory/BUILD.gn
@@ -8,10 +8,8 @@ source_set("memory") {
"aligned_memory.h",
"discardable_memory.cc",
"discardable_memory.h",
- "discardable_memory_shmem.cc",
- "discardable_memory_shmem.h",
- "discardable_memory_shmem_allocator.cc",
- "discardable_memory_shmem_allocator.h",
+ "discardable_memory_allocator.cc",
+ "discardable_memory_allocator.h",
"discardable_shared_memory.cc",
"discardable_shared_memory.h",
"linked_ptr.h",
@@ -42,10 +40,8 @@ source_set("memory") {
sources -= [
"discardable_memory.cc",
"discardable_memory.h",
- "discardable_memory_shmem.cc",
- "discardable_memory_shmem.h",
- "discardable_memory_shmem_allocator.cc",
- "discardable_memory_shmem_allocator.h",
+ "discardable_memory_allocator.cc",
+ "discardable_memory_allocator.h",
"discardable_shared_memory.cc",
"discardable_shared_memory.h",
"shared_memory_posix.cc",
diff --git a/base/memory/discardable_memory.cc b/base/memory/discardable_memory.cc
index 0e3b58a..a99c6f8 100644
--- a/base/memory/discardable_memory.cc
+++ b/base/memory/discardable_memory.cc
@@ -4,14 +4,15 @@
#include "base/memory/discardable_memory.h"
-#include "base/memory/discardable_memory_shmem.h"
+#include "base/memory/discardable_memory_allocator.h"
namespace base {
// static
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemory(
size_t size) {
- return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
+ return DiscardableMemoryAllocator::GetInstance()
+ ->AllocateLockedDiscardableMemory(size);
}
} // namespace base
diff --git a/base/memory/discardable_memory_allocator.cc b/base/memory/discardable_memory_allocator.cc
new file mode 100644
index 0000000..002a3ba
--- /dev/null
+++ b/base/memory/discardable_memory_allocator.cc
@@ -0,0 +1,34 @@
+// 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/memory/discardable_memory_allocator.h"
+
+#include "base/logging.h"
+
+namespace base {
+namespace {
+
+DiscardableMemoryAllocator* g_allocator = nullptr;
+
+} // namespace
+
+// static
+void DiscardableMemoryAllocator::SetInstance(
+ DiscardableMemoryAllocator* allocator) {
+ DCHECK(allocator);
+
+ // Make sure this function is only called once before the first call
+ // to GetInstance().
+ DCHECK(!g_allocator);
+
+ g_allocator = allocator;
+}
+
+// static
+DiscardableMemoryAllocator* DiscardableMemoryAllocator::GetInstance() {
+ DCHECK(g_allocator);
+ return g_allocator;
+}
+
+} // namespace base
diff --git a/base/memory/discardable_memory_allocator.h b/base/memory/discardable_memory_allocator.h
new file mode 100644
index 0000000..400f87a
--- /dev/null
+++ b/base/memory/discardable_memory_allocator.h
@@ -0,0 +1,32 @@
+// 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_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_
+#define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_
+
+#include "base/base_export.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace base {
+class DiscardableMemory;
+
+class BASE_EXPORT DiscardableMemoryAllocator {
+ public:
+ // Returns the allocator instance.
+ static DiscardableMemoryAllocator* GetInstance();
+
+ // Sets the allocator instance. Can only be called once, e.g. on startup.
+ // Ownership of |instance| remains with the caller.
+ static void SetInstance(DiscardableMemoryAllocator* allocator);
+
+ virtual scoped_ptr<DiscardableMemory> AllocateLockedDiscardableMemory(
+ size_t size) = 0;
+
+ protected:
+ virtual ~DiscardableMemoryAllocator() {}
+};
+
+} // namespace base
+
+#endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_
diff --git a/base/memory/discardable_memory_shmem.cc b/base/memory/discardable_memory_shmem.cc
deleted file mode 100644
index 059d84c..0000000
--- a/base/memory/discardable_memory_shmem.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2014 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_shmem.h"
-
-#include "base/lazy_instance.h"
-#include "base/memory/discardable_memory_shmem_allocator.h"
-
-namespace base {
-namespace internal {
-
-DiscardableMemoryShmem::DiscardableMemoryShmem(size_t bytes)
- : chunk_(DiscardableMemoryShmemAllocator::GetInstance()
- ->AllocateLockedDiscardableMemory(bytes)),
- is_locked_(true) {
- DCHECK(chunk_);
-}
-
-DiscardableMemoryShmem::~DiscardableMemoryShmem() {
- if (is_locked_)
- Unlock();
-}
-
-bool DiscardableMemoryShmem::Lock() {
- DCHECK(!is_locked_);
- DCHECK(chunk_);
-
- if (!chunk_->Lock()) {
- chunk_.reset();
- return false;
- }
-
- is_locked_ = true;
- return true;
-}
-
-void DiscardableMemoryShmem::Unlock() {
- DCHECK(is_locked_);
- chunk_->Unlock();
- is_locked_ = false;
-}
-
-void* DiscardableMemoryShmem::Memory() const {
- DCHECK(is_locked_);
- return chunk_->Memory();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_shmem.h b/base/memory/discardable_memory_shmem.h
deleted file mode 100644
index f394562..0000000
--- a/base/memory/discardable_memory_shmem.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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_MEMORY_DISCARDABLE_MEMORY_SHMEM_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_H_
-
-#include "base/memory/discardable_memory.h"
-
-namespace base {
-class DiscardableMemoryShmemChunk;
-
-namespace internal {
-
-class DiscardableMemoryShmem : public DiscardableMemory {
- public:
- explicit DiscardableMemoryShmem(size_t bytes);
- ~DiscardableMemoryShmem() override;
-
- bool Initialize();
-
- // Overridden from DiscardableMemory:
- bool Lock() override;
- void Unlock() override;
- void* Memory() const override;
-
- private:
- scoped_ptr<DiscardableMemoryShmemChunk> chunk_;
- bool is_locked_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmem);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_H_
diff --git a/base/memory/discardable_memory_shmem_allocator.cc b/base/memory/discardable_memory_shmem_allocator.cc
deleted file mode 100644
index a87c58d..0000000
--- a/base/memory/discardable_memory_shmem_allocator.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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_shmem_allocator.h"
-
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/memory/discardable_shared_memory.h"
-
-namespace base {
-namespace {
-
-DiscardableMemoryShmemAllocator* g_allocator = nullptr;
-
-} // namespace
-
-// static
-void DiscardableMemoryShmemAllocator::SetInstance(
- DiscardableMemoryShmemAllocator* allocator) {
- DCHECK(allocator);
-
- // Make sure this function is only called once before the first call
- // to GetInstance().
- DCHECK(!g_allocator);
-
- g_allocator = allocator;
-}
-
-// static
-DiscardableMemoryShmemAllocator*
-DiscardableMemoryShmemAllocator::GetInstance() {
- DCHECK(g_allocator);
- return g_allocator;
-}
-
-} // namespace base
diff --git a/base/memory/discardable_memory_shmem_allocator.h b/base/memory/discardable_memory_shmem_allocator.h
deleted file mode 100644
index ac4118e..0000000
--- a/base/memory/discardable_memory_shmem_allocator.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2014 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_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_
-
-#include "base/base_export.h"
-#include "base/memory/scoped_ptr.h"
-
-namespace base {
-
-// TODO(reveman): Remove this by having allocator interface return
-// real DiscardableMemory instances. crbug.com/442945
-class BASE_EXPORT DiscardableMemoryShmemChunk {
- public:
- virtual ~DiscardableMemoryShmemChunk() {}
-
- virtual bool Lock() = 0;
- virtual void Unlock() = 0;
- virtual void* Memory() const = 0;
-};
-
-class BASE_EXPORT DiscardableMemoryShmemAllocator {
- public:
- // Returns the allocator instance.
- static DiscardableMemoryShmemAllocator* GetInstance();
-
- // Sets the allocator instance. Can only be called once, e.g. on startup.
- // Ownership of |instance| remains with the caller.
- static void SetInstance(DiscardableMemoryShmemAllocator* allocator);
-
- virtual scoped_ptr<DiscardableMemoryShmemChunk>
- AllocateLockedDiscardableMemory(size_t size) = 0;
-
- protected:
- virtual ~DiscardableMemoryShmemAllocator() {}
-};
-
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_SHMEM_ALLOCATOR_H_
diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn
index f5d2e4c..c4356cb 100644
--- a/base/test/BUILD.gn
+++ b/base/test/BUILD.gn
@@ -81,8 +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_discardable_memory_allocator.cc",
+ "test_discardable_memory_allocator.h",
"test_file_util.cc",
"test_file_util.h",
"test_file_util_android.cc",
diff --git a/base/test/test_discardable_memory_allocator.cc b/base/test/test_discardable_memory_allocator.cc
new file mode 100644
index 0000000..cb2cccf
--- /dev/null
+++ b/base/test/test_discardable_memory_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_allocator.h"
+
+#include <stdint.h>
+
+#include "base/memory/discardable_memory.h"
+
+namespace base {
+namespace {
+
+class DiscardableMemoryImpl : public DiscardableMemory {
+ public:
+ explicit DiscardableMemoryImpl(size_t size) : memory_(new uint8_t[size]) {}
+
+ // Overridden from DiscardableMemory:
+ bool Lock() override { return false; }
+ void Unlock() override {}
+ void* Memory() const override { return memory_.get(); }
+
+ private:
+ scoped_ptr<uint8_t[]> memory_;
+};
+
+} // namespace
+
+TestDiscardableMemoryAllocator::TestDiscardableMemoryAllocator() {
+}
+
+TestDiscardableMemoryAllocator::~TestDiscardableMemoryAllocator() {
+}
+
+scoped_ptr<DiscardableMemory>
+TestDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) {
+ return make_scoped_ptr(new DiscardableMemoryImpl(size));
+}
+
+} // namespace base
diff --git a/base/test/test_discardable_memory_allocator.h b/base/test/test_discardable_memory_allocator.h
new file mode 100644
index 0000000..df9d469
--- /dev/null
+++ b/base/test/test_discardable_memory_allocator.h
@@ -0,0 +1,30 @@
+// 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_ALLOCATOR_H_
+#define BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_
+
+#include "base/memory/discardable_memory_allocator.h"
+
+namespace base {
+
+// TestDiscardableMemoryAllocator is a simple DiscardableMemoryAllocator
+// implementation that can be used for testing. It allocates one-shot
+// DiscardableMemory instances backed by heap memory.
+class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator {
+ public:
+ TestDiscardableMemoryAllocator();
+ ~TestDiscardableMemoryAllocator() override;
+
+ // Overridden from DiscardableMemoryAllocator:
+ scoped_ptr<DiscardableMemory> AllocateLockedDiscardableMemory(
+ size_t size) override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestDiscardableMemoryAllocator);
+};
+
+} // namespace base
+
+#endif // BASE_TEST_TEST_DISCARDABLE_MEMORY_ALLOCATOR_H_
diff --git a/base/test/test_discardable_memory_shmem_allocator.cc b/base/test/test_discardable_memory_shmem_allocator.cc
deleted file mode 100644
index 24185a2..0000000
--- a/base/test/test_discardable_memory_shmem_allocator.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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
deleted file mode 100644
index a40960e..0000000
--- a/base/test/test_discardable_memory_shmem_allocator.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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 2ce04bd..a1dd475 100644
--- a/chrome/test/base/chrome_unit_test_suite.cc
+++ b/chrome/test/base/chrome_unit_test_suite.cc
@@ -111,8 +111,7 @@ void ChromeUnitTestSuite::Initialize() {
// intialization which calls base's which initializes ICU.
InitializeResourceBundle();
- base::DiscardableMemoryShmemAllocator::SetInstance(
- &discardable_memory_allocator_);
+ base::DiscardableMemoryAllocator::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 404c59f..5a92bc7 100644
--- a/chrome/test/base/chrome_unit_test_suite.h
+++ b/chrome/test/base/chrome_unit_test_suite.h
@@ -8,7 +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 "base/test/test_discardable_memory_allocator.h"
#include "chrome/test/base/chrome_test_suite.h"
// Test suite for unit tests. Creates additional stub services that are not
@@ -29,7 +29,7 @@ class ChromeUnitTestSuite : public ChromeTestSuite {
static void InitializeResourceBundle();
private:
- base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+ base::TestDiscardableMemoryAllocator 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 bf495b9..2a56518 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -461,7 +461,7 @@ void BrowserMainLoop::EarlyInitialization() {
gfx::GpuMemoryBuffer::SCANOUT);
#endif
- base::DiscardableMemoryShmemAllocator::SetInstance(
+ base::DiscardableMemoryAllocator::SetInstance(
HostDiscardableSharedMemoryManager::current());
if (parts_)
diff --git a/content/child/child_discardable_shared_memory_manager.cc b/content/child/child_discardable_shared_memory_manager.cc
index 86822a2..335a423 100644
--- a/content/child/child_discardable_shared_memory_manager.cc
+++ b/content/child/child_discardable_shared_memory_manager.cc
@@ -7,6 +7,7 @@
#include "base/atomic_sequence_num.h"
#include "base/bind.h"
#include "base/debug/crash_logging.h"
+#include "base/memory/discardable_memory.h"
#include "base/memory/discardable_shared_memory.h"
#include "base/metrics/histogram.h"
#include "base/process/process_metrics.h"
@@ -28,29 +29,46 @@ const size_t kAllocationSize = 4 * 1024 * 1024;
// Global atomic to generate unique discardable shared memory IDs.
base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id;
-class DiscardableMemoryShmemChunkImpl
- : public base::DiscardableMemoryShmemChunk {
+class DiscardableMemoryImpl : public base::DiscardableMemory {
public:
- DiscardableMemoryShmemChunkImpl(
- ChildDiscardableSharedMemoryManager* manager,
- scoped_ptr<DiscardableSharedMemoryHeap::Span> span)
- : manager_(manager), span_(span.Pass()) {}
- ~DiscardableMemoryShmemChunkImpl() override {
+ DiscardableMemoryImpl(ChildDiscardableSharedMemoryManager* manager,
+ scoped_ptr<DiscardableSharedMemoryHeap::Span> span)
+ : manager_(manager), span_(span.Pass()), is_locked_(true) {}
+
+ ~DiscardableMemoryImpl() override {
+ if (is_locked_)
+ manager_->UnlockSpan(span_.get());
+
manager_->ReleaseSpan(span_.Pass());
}
- // Overridden from DiscardableMemoryShmemChunk:
- bool Lock() override { return manager_->LockSpan(span_.get()); }
- void Unlock() override { manager_->UnlockSpan(span_.get()); }
+ // Overridden from base::DiscardableMemory:
+ bool Lock() override {
+ DCHECK(!is_locked_);
+
+ if (!manager_->LockSpan(span_.get()))
+ return false;
+
+ is_locked_ = true;
+ return true;
+ }
+ void Unlock() override {
+ DCHECK(is_locked_);
+
+ manager_->UnlockSpan(span_.get());
+ is_locked_ = false;
+ }
void* Memory() const override {
+ DCHECK(is_locked_);
return reinterpret_cast<void*>(span_->start() * base::GetPageSize());
}
private:
- ChildDiscardableSharedMemoryManager* manager_;
+ ChildDiscardableSharedMemoryManager* const manager_;
scoped_ptr<DiscardableSharedMemoryHeap::Span> span_;
+ bool is_locked_;
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
+ DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl);
};
} // namespace
@@ -70,7 +88,7 @@ ChildDiscardableSharedMemoryManager::~ChildDiscardableSharedMemoryManager() {
MemoryUsageChanged(0, 0);
}
-scoped_ptr<base::DiscardableMemoryShmemChunk>
+scoped_ptr<base::DiscardableMemory>
ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
size_t size) {
base::AutoLock lock(lock_);
@@ -124,8 +142,7 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
// at least one span from the free lists.
MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists());
- return make_scoped_ptr(
- new DiscardableMemoryShmemChunkImpl(this, free_span.Pass()));
+ return make_scoped_ptr(new DiscardableMemoryImpl(this, free_span.Pass()));
}
// Release purged memory to free up the address space before we attempt to
@@ -167,8 +184,7 @@ ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
MemoryUsageChanged(heap_.GetSize(), heap_.GetSizeOfFreeLists());
- return make_scoped_ptr(
- new DiscardableMemoryShmemChunkImpl(this, new_span.Pass()));
+ return make_scoped_ptr(new DiscardableMemoryImpl(this, new_span.Pass()));
}
void ChildDiscardableSharedMemoryManager::ReleaseFreeMemory() {
diff --git a/content/child/child_discardable_shared_memory_manager.h b/content/child/child_discardable_shared_memory_manager.h
index 518f72b..3dee173 100644
--- a/content/child/child_discardable_shared_memory_manager.h
+++ b/content/child/child_discardable_shared_memory_manager.h
@@ -5,7 +5,7 @@
#ifndef CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_
#define CONTENT_CHILD_CHILD_DISCARDABLE_SHARED_MEMORY_MANAGER_H_
-#include "base/memory/discardable_memory_shmem_allocator.h"
+#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
@@ -16,16 +16,16 @@
namespace content {
-// Implementation of DiscardableMemoryShmemAllocator that allocates
+// Implementation of DiscardableMemoryAllocator that allocates
// discardable memory segments through the browser process.
class CONTENT_EXPORT ChildDiscardableSharedMemoryManager
- : public base::DiscardableMemoryShmemAllocator {
+ : public base::DiscardableMemoryAllocator {
public:
explicit ChildDiscardableSharedMemoryManager(ThreadSafeSender* sender);
~ChildDiscardableSharedMemoryManager() override;
- // Overridden from base::DiscardableMemoryShmemAllocator:
- scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory(
+ // Overridden from base::DiscardableMemoryAllocator:
+ scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
size_t size) override;
// Release memory and associated resources that have been purged.
diff --git a/content/child/child_discardable_shared_memory_manager_browsertest.cc b/content/child/child_discardable_shared_memory_manager_browsertest.cc
index 813c55d..1764cb0 100644
--- a/content/child/child_discardable_shared_memory_manager_browsertest.cc
+++ b/content/child/child_discardable_shared_memory_manager_browsertest.cc
@@ -4,6 +4,7 @@
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/memory/discardable_memory.h"
#include "content/child/child_discardable_shared_memory_manager.h"
#include "content/child/child_thread_impl.h"
#include "content/common/host_discardable_shared_memory_manager.h"
@@ -30,23 +31,21 @@ class ChildDiscardableSharedMemoryManagerBrowserTest
static void AllocateLockedMemory(
size_t size,
- scoped_ptr<base::DiscardableMemoryShmemChunk>* memory) {
+ scoped_ptr<base::DiscardableMemory>* memory) {
*memory = ChildThreadImpl::current()
->discardable_shared_memory_manager()
->AllocateLockedDiscardableMemory(size);
}
- static void LockMemory(base::DiscardableMemoryShmemChunk* memory,
- bool* result) {
+ static void LockMemory(base::DiscardableMemory* memory, bool* result) {
*result = memory->Lock();
}
- static void UnlockMemory(base::DiscardableMemoryShmemChunk* memory) {
+ static void UnlockMemory(base::DiscardableMemory* memory) {
memory->Unlock();
}
- static void FreeMemory(scoped_ptr<base::DiscardableMemoryShmemChunk> memory) {
- }
+ static void FreeMemory(scoped_ptr<base::DiscardableMemory> memory) {}
};
IN_PROC_BROWSER_TEST_F(ChildDiscardableSharedMemoryManagerBrowserTest,
@@ -55,7 +54,7 @@ IN_PROC_BROWSER_TEST_F(ChildDiscardableSharedMemoryManagerBrowserTest,
NavigateToURL(shell(), GURL(url::kAboutBlankURL));
- scoped_ptr<base::DiscardableMemoryShmemChunk> memory;
+ scoped_ptr<base::DiscardableMemory> memory;
PostTaskToInProcessRendererAndWait(base::Bind(
&ChildDiscardableSharedMemoryManagerBrowserTest::AllocateLockedMemory,
kSize, &memory));
@@ -91,7 +90,7 @@ IN_PROC_BROWSER_TEST_F(ChildDiscardableSharedMemoryManagerBrowserTest,
NavigateToURL(shell(), GURL(url::kAboutBlankURL));
- scoped_ptr<base::DiscardableMemoryShmemChunk> instances[kNumberOfInstances];
+ scoped_ptr<base::DiscardableMemory> instances[kNumberOfInstances];
for (auto& memory : instances) {
PostTaskToInProcessRendererAndWait(base::Bind(
&ChildDiscardableSharedMemoryManagerBrowserTest::AllocateLockedMemory,
@@ -117,7 +116,7 @@ IN_PROC_BROWSER_TEST_F(ChildDiscardableSharedMemoryManagerBrowserTest,
NavigateToURL(shell(), GURL(url::kAboutBlankURL));
- scoped_ptr<base::DiscardableMemoryShmemChunk> memory;
+ scoped_ptr<base::DiscardableMemory> memory;
PostTaskToInProcessRendererAndWait(base::Bind(
&ChildDiscardableSharedMemoryManagerBrowserTest::AllocateLockedMemory,
kSize, &memory));
diff --git a/content/common/host_discardable_shared_memory_manager.cc b/content/common/host_discardable_shared_memory_manager.cc
index ab74ef0..c4fea8d 100644
--- a/content/common/host_discardable_shared_memory_manager.cc
+++ b/content/common/host_discardable_shared_memory_manager.cc
@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/debug/crash_logging.h"
#include "base/lazy_instance.h"
+#include "base/memory/discardable_memory.h"
#include "base/numerics/safe_math.h"
#include "base/profiler/scoped_tracker.h"
#include "base/strings/string_number_conversions.h"
@@ -20,23 +21,22 @@
namespace content {
namespace {
-class DiscardableMemoryShmemChunkImpl
- : public base::DiscardableMemoryShmemChunk {
+class DiscardableMemoryImpl : public base::DiscardableMemory {
public:
- DiscardableMemoryShmemChunkImpl(
- scoped_ptr<base::DiscardableSharedMemory> shared_memory,
- const base::Closure& deleted_callback)
+ DiscardableMemoryImpl(scoped_ptr<base::DiscardableSharedMemory> shared_memory,
+ const base::Closure& deleted_callback)
: shared_memory_(shared_memory.Pass()),
deleted_callback_(deleted_callback),
is_locked_(true) {}
- ~DiscardableMemoryShmemChunkImpl() override {
+
+ ~DiscardableMemoryImpl() override {
if (is_locked_)
shared_memory_->Unlock(0, 0);
deleted_callback_.Run();
}
- // Overridden from base::DiscardableMemoryShmemChunk:
+ // Overridden from base::DiscardableMemory:
bool Lock() override {
DCHECK(!is_locked_);
@@ -62,7 +62,7 @@ class DiscardableMemoryShmemChunkImpl
const base::Closure deleted_callback_;
bool is_locked_;
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryShmemChunkImpl);
+ DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryImpl);
};
base::LazyInstance<HostDiscardableSharedMemoryManager>
@@ -107,7 +107,7 @@ HostDiscardableSharedMemoryManager::current() {
return g_discardable_shared_memory_manager.Pointer();
}
-scoped_ptr<base::DiscardableMemoryShmemChunk>
+scoped_ptr<base::DiscardableMemory>
HostDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
size_t size) {
DiscardableSharedMemoryId new_id =
@@ -123,7 +123,7 @@ HostDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
scoped_ptr<base::DiscardableSharedMemory> memory(
new base::DiscardableSharedMemory(handle));
CHECK(memory->Map(size));
- return make_scoped_ptr(new DiscardableMemoryShmemChunkImpl(
+ return make_scoped_ptr(new DiscardableMemoryImpl(
memory.Pass(),
base::Bind(
&HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory,
diff --git a/content/common/host_discardable_shared_memory_manager.h b/content/common/host_discardable_shared_memory_manager.h
index 36de71d..f68ed93 100644
--- a/content/common/host_discardable_shared_memory_manager.h
+++ b/content/common/host_discardable_shared_memory_manager.h
@@ -8,7 +8,7 @@
#include <vector>
#include "base/containers/hash_tables.h"
-#include "base/memory/discardable_memory_shmem_allocator.h"
+#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/discardable_shared_memory.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h"
@@ -21,12 +21,11 @@
namespace content {
typedef int32_t DiscardableSharedMemoryId;
-// Implementation of DiscardableMemoryShmemAllocator that allocates and
-// manages discardable memory segments for the browser process and child
-// processes. This class is thread-safe and instances can safely be used
-// on any thread.
+// Implementation of DiscardableMemoryAllocator that allocates and manages
+// discardable memory segments for the browser process and child processes.
+// This class is thread-safe and instances can safely be used on any thread.
class CONTENT_EXPORT HostDiscardableSharedMemoryManager
- : public base::DiscardableMemoryShmemAllocator {
+ : public base::DiscardableMemoryAllocator {
public:
HostDiscardableSharedMemoryManager();
~HostDiscardableSharedMemoryManager() override;
@@ -34,8 +33,8 @@ class CONTENT_EXPORT HostDiscardableSharedMemoryManager
// Returns a singleton instance.
static HostDiscardableSharedMemoryManager* current();
- // Overridden from base::DiscardableMemoryShmemAllocator:
- scoped_ptr<base::DiscardableMemoryShmemChunk> AllocateLockedDiscardableMemory(
+ // Overridden from base::DiscardableMemoryAllocator:
+ scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory(
size_t size) override;
// This allocates a discardable memory segment for |process_handle|.
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index d8f7974..f9d02f1 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -13,8 +13,7 @@
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory.h"
-#include "base/memory/discardable_memory_shmem_allocator.h"
+#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/shared_memory.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
@@ -659,7 +658,7 @@ void RenderThreadImpl::Init() {
// In single process, browser main loop set up the discardable memory
// allocator.
if (!command_line.HasSwitch(switches::kSingleProcess)) {
- base::DiscardableMemoryShmemAllocator::SetInstance(
+ base::DiscardableMemoryAllocator::SetInstance(
ChildThreadImpl::discardable_shared_memory_manager());
}
diff --git a/content/test/blink_test_environment.cc b/content/test/blink_test_environment.cc
index 16b35a6..c20e986 100644
--- a/content/test/blink_test_environment.cc
+++ b/content/test/blink_test_environment.cc
@@ -10,7 +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/test/test_discardable_memory_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"
@@ -69,7 +69,7 @@ class TestEnvironment {
blink_test_support_.reset(new TestBlinkWebUnitTestSupport);
content_initializer_.reset(new content::TestContentClientInitializer());
- base::DiscardableMemoryShmemAllocator::SetInstance(
+ base::DiscardableMemoryAllocator::SetInstance(
&discardable_memory_allocator_);
}
@@ -84,7 +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_;
+ base::TestDiscardableMemoryAllocator 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 5da865b..07d09cb 100644
--- a/ui/app_list/test/run_all_unittests.cc
+++ b/ui/app_list/test/run_all_unittests.cc
@@ -7,7 +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_discardable_memory_allocator.h"
#include "base/test/test_suite.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
@@ -42,7 +42,7 @@ class AppListTestSuite : public base::TestSuite {
ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
- base::DiscardableMemoryShmemAllocator::SetInstance(
+ base::DiscardableMemoryAllocator::SetInstance(
&discardable_memory_allocator_);
}
@@ -52,7 +52,7 @@ class AppListTestSuite : public base::TestSuite {
}
private:
- base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+ base::TestDiscardableMemoryAllocator 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 b0cc026..019df50 100644
--- a/ui/message_center/test/run_all_unittests.cc
+++ b/ui/message_center/test/run_all_unittests.cc
@@ -7,7 +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_discardable_memory_allocator.h"
#include "base/test/test_suite.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
@@ -39,7 +39,7 @@ class MessageCenterTestSuite : public base::TestSuite {
ASSERT_TRUE(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path);
- base::DiscardableMemoryShmemAllocator::SetInstance(
+ base::DiscardableMemoryAllocator::SetInstance(
&discardable_memory_allocator_);
}
@@ -49,7 +49,7 @@ class MessageCenterTestSuite : public base::TestSuite {
}
private:
- base::TestDiscardableMemoryShmemAllocator discardable_memory_allocator_;
+ base::TestDiscardableMemoryAllocator discardable_memory_allocator_;
DISALLOW_COPY_AND_ASSIGN(MessageCenterTestSuite);
};