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

Side by Side Diff: content/renderer/render_thread_impl_browsertest.cc

Issue 448173002: Re-land: base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden with lsan Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/discardable_memory.h"
7 #include "base/memory/scoped_vector.h"
6 #include "content/public/browser/content_browser_client.h" 8 #include "content/public/browser/content_browser_client.h"
7 #include "content/public/common/content_client.h" 9 #include "content/public/common/content_client.h"
8 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
9 #include "content/public/renderer/content_renderer_client.h" 11 #include "content/public/renderer/content_renderer_client.h"
10 #include "content/renderer/render_process_impl.h" 12 #include "content/renderer/render_process_impl.h"
11 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
12 #include "content/test/mock_render_process.h" 14 #include "content/test/mock_render_process.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace content { 17 namespace content {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 RenderThreadImpl* thread = new RenderThreadImpl(channel_id); 65 RenderThreadImpl* thread = new RenderThreadImpl(channel_id);
64 thread->EnsureWebKitInitialized(); 66 thread->EnsureWebKitInitialized();
65 67
66 ASSERT_TRUE(thread->input_handler_manager()); 68 ASSERT_TRUE(thread->input_handler_manager());
67 69
68 thread->compositor_message_loop_proxy()->PostTask( 70 thread->compositor_message_loop_proxy()->PostTask(
69 FROM_HERE, 71 FROM_HERE,
70 base::Bind(&CheckRenderThreadInputHandlerManager, thread)); 72 base::Bind(&CheckRenderThreadInputHandlerManager, thread));
71 } 73 }
72 74
75 // Checks that emulated discardable memory is discarded when the last widget
76 // is hidden.
77 // Disabled under LeakSanitizer due to memory leaks.
78 #if defined(LEAK_SANITIZER)
79 #define MAYBE_EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden \
80 DISABLED_EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden
81 #else
82 #define MAYBE_EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden \
83 EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden
84 #endif
85 TEST_F(RenderThreadImplBrowserTest,
86 MAYBE_EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden) {
87 ContentClient content_client;
88 ContentBrowserClient content_browser_client;
89 ContentRendererClient content_renderer_client;
90 SetContentClient(&content_client);
91 SetBrowserClientForTesting(&content_browser_client);
92 SetRendererClientForTesting(&content_renderer_client);
93 base::MessageLoopForIO message_loop_;
94
95 std::string channel_id =
96 IPC::Channel::GenerateVerifiedChannelID(std::string());
97 DummyListener dummy_listener;
98 scoped_ptr<IPC::Channel> channel(
99 IPC::Channel::CreateServer(channel_id, &dummy_listener));
100 ASSERT_TRUE(channel->Connect());
101
102 scoped_ptr<MockRenderProcess> mock_process(new MockRenderProcess);
103 // Owned by mock_process.
104 RenderThreadImpl* thread = new RenderThreadImpl(channel_id);
105 thread->EnsureWebKitInitialized();
106 thread->WidgetCreated();
107
108 // Allocate 128MB of discardable memory.
109 ScopedVector<base::DiscardableMemory> discardable_memory;
110 for (int i = 0; i < 32; ++i) {
111 discardable_memory.push_back(
112 base::DiscardableMemory::CreateLockedMemoryWithType(
113 base::DISCARDABLE_MEMORY_TYPE_EMULATED, 4 * 1024 * 1024).release());
114 ASSERT_TRUE(discardable_memory.back());
115 discardable_memory.back()->Unlock();
116 }
117
118 // Hide all widgets.
119 thread->WidgetHidden();
120
121 // Count how much memory is left, should be at most one block.
122 int blocks_left = 0;
123 for (auto iter = discardable_memory.begin(); iter != discardable_memory.end();
124 ++iter) {
125 if ((*iter)->Lock() == base::DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS)
126 ++blocks_left;
127 }
128 EXPECT_LE(blocks_left, 1);
129
130 thread->WidgetDestroyed();
131 }
132
73 } // namespace 133 } // namespace
74 } // namespace content 134 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698