| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/discardable_memory.h" | 13 #include "base/memory/discardable_memory.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "components/discardable_memory/client/client_discardable_shared_memory_
manager.h" | 17 #include "components/discardable_memory/client/client_discardable_shared_memory_
manager.h" |
| 18 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" | 18 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" |
| 19 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/test/content_browser_test.h" | 21 #include "content/public/test/content_browser_test.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
| 23 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" | 24 #include "gpu/ipc/client/gpu_memory_buffer_impl.h" |
| 24 #include "ui/gfx/buffer_format_util.h" | 25 #include "ui/gfx/buffer_format_util.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 namespace { | 29 namespace { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 child_discardable_shared_memory_manager() | 68 child_discardable_shared_memory_manager() |
| 68 ->AllocateLockedDiscardableMemory(kSize); | 69 ->AllocateLockedDiscardableMemory(kSize); |
| 69 | 70 |
| 70 ASSERT_TRUE(memory); | 71 ASSERT_TRUE(memory); |
| 71 void* addr = memory->data(); | 72 void* addr = memory->data(); |
| 72 ASSERT_NE(nullptr, addr); | 73 ASSERT_NE(nullptr, addr); |
| 73 | 74 |
| 74 memory->Unlock(); | 75 memory->Unlock(); |
| 75 | 76 |
| 76 // Purge all unlocked memory. | 77 // Purge all unlocked memory. |
| 77 discardable_memory::DiscardableSharedMemoryManager::GetInstance() | 78 BrowserMainLoop::GetInstance() |
| 79 ->discardable_shared_memory_manager() |
| 78 ->SetMemoryLimit(0); | 80 ->SetMemoryLimit(0); |
| 79 | 81 |
| 80 // Should fail as memory should have been purged. | 82 // Should fail as memory should have been purged. |
| 81 EXPECT_FALSE(memory->Lock()); | 83 EXPECT_FALSE(memory->Lock()); |
| 82 } | 84 } |
| 83 | 85 |
| 84 // Disable the test for the Android asan build. | 86 // Disable the test for the Android asan build. |
| 85 // See http://crbug.com/667837 for detail. | 87 // See http://crbug.com/667837 for detail. |
| 86 #if !(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)) | 88 #if !(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)) |
| 87 IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, | 89 IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 ReleaseFreeDiscardableMemory) { | 109 ReleaseFreeDiscardableMemory) { |
| 108 const size_t kSize = 1024 * 1024; // 1MiB. | 110 const size_t kSize = 1024 * 1024; // 1MiB. |
| 109 | 111 |
| 110 std::unique_ptr<base::DiscardableMemory> memory = | 112 std::unique_ptr<base::DiscardableMemory> memory = |
| 111 child_discardable_shared_memory_manager() | 113 child_discardable_shared_memory_manager() |
| 112 ->AllocateLockedDiscardableMemory(kSize); | 114 ->AllocateLockedDiscardableMemory(kSize); |
| 113 | 115 |
| 114 EXPECT_TRUE(memory); | 116 EXPECT_TRUE(memory); |
| 115 memory.reset(); | 117 memory.reset(); |
| 116 | 118 |
| 117 EXPECT_GE(discardable_memory::DiscardableSharedMemoryManager::GetInstance() | 119 EXPECT_GE(BrowserMainLoop::GetInstance() |
| 120 ->discardable_shared_memory_manager() |
| 118 ->GetBytesAllocated(), | 121 ->GetBytesAllocated(), |
| 119 kSize); | 122 kSize); |
| 120 | 123 |
| 121 child_discardable_shared_memory_manager()->ReleaseFreeMemory(); | 124 child_discardable_shared_memory_manager()->ReleaseFreeMemory(); |
| 122 | 125 |
| 123 // Busy wait for host memory usage to be reduced. | 126 // Busy wait for host memory usage to be reduced. |
| 124 base::TimeTicks end = | 127 base::TimeTicks end = |
| 125 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); | 128 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(5); |
| 126 while (base::TimeTicks::Now() < end) { | 129 while (base::TimeTicks::Now() < end) { |
| 127 if (!discardable_memory::DiscardableSharedMemoryManager::GetInstance() | 130 if (!BrowserMainLoop::GetInstance() |
| 131 ->discardable_shared_memory_manager() |
| 128 ->GetBytesAllocated()) | 132 ->GetBytesAllocated()) |
| 129 break; | 133 break; |
| 130 } | 134 } |
| 131 | 135 |
| 132 EXPECT_LT(base::TimeTicks::Now(), end); | 136 EXPECT_LT(base::TimeTicks::Now(), end); |
| 133 } | 137 } |
| 134 | 138 |
| 135 } // namespace | 139 } // namespace |
| 136 } // namespace content | 140 } // namespace content |
| OLD | NEW |