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

Side by Side Diff: content/browser/renderer_host/mock_render_process_host.cc

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/browser/renderer_host/mock_render_process_host.h" 5 #include "content/browser/renderer_host/mock_render_process_host.h"
6 6
7 #include "base/lazy_instance.h"
8 #include "base/message_loop.h"
7 #include "content/browser/child_process_security_policy.h" 9 #include "content/browser/child_process_security_policy.h"
10 #include "content/common/child_process_info.h"
11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h"
13
14 // This map is the global list of all renderer processes and is defined in
15 // render_process_host_impl.cc
16 // TODO(ananta)
17 // Clean up this dependency in a subsequent CL.
jam 2011/11/16 22:10:19 it's fine to do this in a future change since this
ananta 2011/11/17 13:34:45 I will do that in a follow up CL.
18 extern base::LazyInstance<IDMap<RenderProcessHost>,
19 base::LeakyLazyInstanceTraits<IDMap<RenderProcessHost> > >
20 g_all_hosts;
8 21
9 MockRenderProcessHost::MockRenderProcessHost( 22 MockRenderProcessHost::MockRenderProcessHost(
10 content::BrowserContext* browser_context) 23 content::BrowserContext* browser_context)
11 : RenderProcessHost(browser_context), 24 : transport_dib_(NULL),
12 transport_dib_(NULL),
13 bad_msg_count_(0), 25 bad_msg_count_(0),
14 factory_(NULL) { 26 factory_(NULL),
27 id_(ChildProcessInfo::GenerateChildProcessUniqueId()),
28 browser_context_(browser_context),
29 max_page_id_(0),
30 fast_shutdown_started_(false) {
15 // Child process security operations can't be unit tested unless we add 31 // Child process security operations can't be unit tested unless we add
16 // ourselves as an existing child process. 32 // ourselves as an existing child process.
17 ChildProcessSecurityPolicy::GetInstance()->Add(id()); 33 ChildProcessSecurityPolicy::GetInstance()->Add(GetID());
34 g_all_hosts.Get().AddWithID(this, GetID());
18 } 35 }
19 36
20 MockRenderProcessHost::~MockRenderProcessHost() { 37 MockRenderProcessHost::~MockRenderProcessHost() {
21 ChildProcessSecurityPolicy::GetInstance()->Remove(id()); 38 ChildProcessSecurityPolicy::GetInstance()->Remove(GetID());
22 delete transport_dib_; 39 delete transport_dib_;
23 if (factory_) 40 if (factory_)
24 factory_->Remove(this); 41 factory_->Remove(this);
42 // In unit tests, Release() might not have been called.
43 if (g_all_hosts.Get().Lookup(GetID()))
44 g_all_hosts.Get().Remove(GetID());
25 } 45 }
26 46
27 void MockRenderProcessHost::EnableSendQueue() { 47 void MockRenderProcessHost::EnableSendQueue() {
28 } 48 }
29 49
30 bool MockRenderProcessHost::Init(bool is_accessibility_enabled) { 50 bool MockRenderProcessHost::Init(bool is_accessibility_enabled) {
31 return true; 51 return true;
32 } 52 }
33 53
34 int MockRenderProcessHost::GetNextRoutingID() { 54 int MockRenderProcessHost::GetNextRoutingID() {
(...skipping 24 matching lines...) Expand all
59 void MockRenderProcessHost::WidgetHidden() { 79 void MockRenderProcessHost::WidgetHidden() {
60 } 80 }
61 81
62 int MockRenderProcessHost::VisibleWidgetCount() const { 82 int MockRenderProcessHost::VisibleWidgetCount() const {
63 return 1; 83 return 1;
64 } 84 }
65 85
66 void MockRenderProcessHost::AddWord(const string16& word) { 86 void MockRenderProcessHost::AddWord(const string16& word) {
67 } 87 }
68 88
69
70 bool MockRenderProcessHost::FastShutdownIfPossible() { 89 bool MockRenderProcessHost::FastShutdownIfPossible() {
71 // We aren't actually going to do anything, but set |fast_shutdown_started_| 90 // We aren't actually going to do anything, but set |fast_shutdown_started_|
72 // to true so that tests know we've been called. 91 // to true so that tests know we've been called.
73 fast_shutdown_started_ = true; 92 fast_shutdown_started_ = true;
74 return true; 93 return true;
75 } 94 }
76 95
96 bool MockRenderProcessHost::FastShutdownStarted() const {
97 return fast_shutdown_started_;
98 }
99
77 void MockRenderProcessHost::DumpHandles() { 100 void MockRenderProcessHost::DumpHandles() {
78 } 101 }
79 102
80 base::ProcessHandle MockRenderProcessHost::GetHandle() { 103 base::ProcessHandle MockRenderProcessHost::GetHandle() {
81 return base::kNullProcessHandle; 104 return base::kNullProcessHandle;
82 } 105 }
83 106
84 bool MockRenderProcessHost::Send(IPC::Message* msg) { 107 bool MockRenderProcessHost::Send(IPC::Message* msg) {
85 // Save the message in the sink. 108 // Save the message in the sink.
86 sink_.OnMessageReceived(*msg); 109 sink_.OnMessageReceived(*msg);
(...skipping 18 matching lines...) Expand all
105 #endif 128 #endif
106 129
107 return transport_dib_; 130 return transport_dib_;
108 } 131 }
109 132
110 void MockRenderProcessHost::SetCompositingSurface( 133 void MockRenderProcessHost::SetCompositingSurface(
111 int render_widget_id, 134 int render_widget_id,
112 gfx::PluginWindowHandle compositing_surface) { 135 gfx::PluginWindowHandle compositing_surface) {
113 } 136 }
114 137
138 int MockRenderProcessHost::GetID() const {
139 return id_;
140 }
141
142 bool MockRenderProcessHost::HasConnection() const {
143 return true;
144 }
145
146 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) {
147 }
148
149 bool MockRenderProcessHost::IgnoreInputEvents() const {
150 return false;
151 }
152
153 void MockRenderProcessHost::Attach(IPC::Channel::Listener* listener,
154 int routing_id) {
155 listeners_.AddWithID(listener, routing_id);
156 }
157
158 void MockRenderProcessHost::Release(int listener_id) {
159 listeners_.Remove(listener_id);
160 Cleanup();
161 }
162
163 void MockRenderProcessHost::Cleanup() {
164 if (listeners_.IsEmpty()) {
165 content::NotificationService::current()->Notify(
166 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
167 content::Source<RenderProcessHost>(this),
168 content::NotificationService::NoDetails());
169 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
170 g_all_hosts.Get().Remove(GetID());
171 }
172 }
173
174 void MockRenderProcessHost::ReportExpectingClose(int32 listener_id) {
175 }
176
177 void MockRenderProcessHost::AddPendingView() {
178 }
179
180 void MockRenderProcessHost::RemovePendingView() {
181 }
182
183 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) {
184 }
185
186 bool MockRenderProcessHost::SuddenTerminationAllowed() const {
187 return true;
188 }
189
190 IPC::Channel::Listener* MockRenderProcessHost::GetListenerByID(
191 int routing_id) {
192 return listeners_.Lookup(routing_id);
193 }
194
195 void MockRenderProcessHost::UpdateMaxPageID(int32 page_id) {
196 if (page_id > max_page_id_)
197 max_page_id_ = page_id;
198 }
199
200 content::BrowserContext* MockRenderProcessHost::GetBrowserContext() const {
201 return browser_context_;
202 }
203
204 IPC::ChannelProxy* MockRenderProcessHost::GetChannel() {
205 return NULL;
206 }
207
208 bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) {
209 if (listeners_.size() == count)
210 return FastShutdownIfPossible();
211 return false;
212 }
213
214 RenderProcessHost::listeners_iterator
215 MockRenderProcessHost::ListenersIterator() {
216 IDMap<IPC::Channel::Listener> listeners;
217 return listeners_iterator(&listeners);
218 }
219
115 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { 220 bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
116 return false; 221 return false;
117 } 222 }
118 223
119 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) { 224 void MockRenderProcessHost::OnChannelConnected(int32 peer_pid) {
120 } 225 }
121 226
122 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {} 227 MockRenderProcessHostFactory::MockRenderProcessHostFactory() {}
123 228
124 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() { 229 MockRenderProcessHostFactory::~MockRenderProcessHostFactory() {
(...skipping 17 matching lines...) Expand all
142 247
143 void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const { 248 void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const {
144 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); 249 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin();
145 it != processes_.end(); ++it) { 250 it != processes_.end(); ++it) {
146 if (*it == host) { 251 if (*it == host) {
147 processes_.weak_erase(it); 252 processes_.weak_erase(it);
148 break; 253 break;
149 } 254 }
150 } 255 }
151 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698