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

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

Issue 458343003: Revert of base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
8 #include "content/public/browser/content_browser_client.h" 6 #include "content/public/browser/content_browser_client.h"
9 #include "content/public/common/content_client.h" 7 #include "content/public/common/content_client.h"
10 #include "content/public/common/content_switches.h" 8 #include "content/public/common/content_switches.h"
11 #include "content/public/renderer/content_renderer_client.h" 9 #include "content/public/renderer/content_renderer_client.h"
12 #include "content/renderer/render_process_impl.h" 10 #include "content/renderer/render_process_impl.h"
13 #include "content/renderer/render_thread_impl.h" 11 #include "content/renderer/render_thread_impl.h"
14 #include "content/test/mock_render_process.h" 12 #include "content/test/mock_render_process.h"
15 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
16 14
17 namespace content { 15 namespace content {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 RenderThreadImpl* thread = new RenderThreadImpl(channel_id); 63 RenderThreadImpl* thread = new RenderThreadImpl(channel_id);
66 thread->EnsureWebKitInitialized(); 64 thread->EnsureWebKitInitialized();
67 65
68 ASSERT_TRUE(thread->input_handler_manager()); 66 ASSERT_TRUE(thread->input_handler_manager());
69 67
70 thread->compositor_message_loop_proxy()->PostTask( 68 thread->compositor_message_loop_proxy()->PostTask(
71 FROM_HERE, 69 FROM_HERE,
72 base::Bind(&CheckRenderThreadInputHandlerManager, thread)); 70 base::Bind(&CheckRenderThreadInputHandlerManager, thread));
73 } 71 }
74 72
75 // Checks that emulated discardable memory is discarded when the last widget
76 // is hidden.
77 TEST_F(RenderThreadImplBrowserTest,
78 EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden) {
79 ContentClient content_client;
80 ContentBrowserClient content_browser_client;
81 ContentRendererClient content_renderer_client;
82 SetContentClient(&content_client);
83 SetBrowserClientForTesting(&content_browser_client);
84 SetRendererClientForTesting(&content_renderer_client);
85 base::MessageLoopForIO message_loop_;
86
87 std::string channel_id =
88 IPC::Channel::GenerateVerifiedChannelID(std::string());
89 DummyListener dummy_listener;
90 scoped_ptr<IPC::Channel> channel(
91 IPC::Channel::CreateServer(channel_id, &dummy_listener));
92 ASSERT_TRUE(channel->Connect());
93
94 scoped_ptr<MockRenderProcess> mock_process(new MockRenderProcess);
95 // Owned by mock_process.
96 RenderThreadImpl* thread = new RenderThreadImpl(channel_id);
97 thread->EnsureWebKitInitialized();
98 thread->WidgetCreated();
99
100 // Allocate 128MB of discardable memory.
101 ScopedVector<base::DiscardableMemory> discardable_memory;
102 for (int i = 0; i < 32; ++i) {
103 discardable_memory.push_back(
104 base::DiscardableMemory::CreateLockedMemoryWithType(
105 base::DISCARDABLE_MEMORY_TYPE_EMULATED, 4 * 1024 * 1024).release());
106 ASSERT_TRUE(discardable_memory.back());
107 discardable_memory.back()->Unlock();
108 }
109
110 // Hide all widgets.
111 thread->WidgetHidden();
112
113 // Count how much memory is left, should be at most one block.
114 int blocks_left = 0;
115 for (auto iter = discardable_memory.begin(); iter != discardable_memory.end();
116 ++iter) {
117 if ((*iter)->Lock() == base::DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS)
118 ++blocks_left;
119 }
120 EXPECT_LE(blocks_left, 1);
121
122 thread->WidgetDestroyed();
123 }
124
125 } // namespace 73 } // namespace
126 } // namespace content 74 } // 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