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

Side by Side Diff: content/public/test/mock_render_process_host.cc

Issue 247263005: Remove TransportDIB methods from RenderProcess(Host) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/public/test/mock_render_process_host.h ('k') | content/renderer/render_process.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/test/mock_render_process_host.h" 5 #include "content/public/test/mock_render_process_host.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/child_process_security_policy_impl.h" 10 #include "content/browser/child_process_security_policy_impl.h"
11 #include "content/browser/renderer_host/render_process_host_impl.h" 11 #include "content/browser/renderer_host/render_process_host_impl.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/renderer_host/render_widget_host_impl.h" 13 #include "content/browser/renderer_host/render_widget_host_impl.h"
14 #include "content/common/child_process_host_impl.h" 14 #include "content/common/child_process_host_impl.h"
15 #include "content/public/browser/global_request_id.h" 15 #include "content/public/browser/global_request_id.h"
16 #include "content/public/browser/render_widget_host_iterator.h" 16 #include "content/public/browser/render_widget_host_iterator.h"
17 #include "content/public/browser/storage_partition.h" 17 #include "content/public/browser/storage_partition.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context) 21 MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context)
22 : transport_dib_(NULL), 22 : bad_msg_count_(0),
23 bad_msg_count_(0),
24 factory_(NULL), 23 factory_(NULL),
25 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 24 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
26 browser_context_(browser_context), 25 browser_context_(browser_context),
27 prev_routing_id_(0), 26 prev_routing_id_(0),
28 fast_shutdown_started_(false), 27 fast_shutdown_started_(false),
29 deletion_callback_called_(false), 28 deletion_callback_called_(false),
30 is_guest_(false) { 29 is_guest_(false) {
31 // Child process security operations can't be unit tested unless we add 30 // Child process security operations can't be unit tested unless we add
32 // ourselves as an existing child process. 31 // ourselves as an existing child process.
33 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); 32 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID());
34 33
35 RenderProcessHostImpl::RegisterHost(GetID(), this); 34 RenderProcessHostImpl::RegisterHost(GetID(), this);
36 } 35 }
37 36
38 MockRenderProcessHost::~MockRenderProcessHost() { 37 MockRenderProcessHost::~MockRenderProcessHost() {
39 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 38 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
40 delete transport_dib_;
41 if (factory_) 39 if (factory_)
42 factory_->Remove(this); 40 factory_->Remove(this);
43 41
44 // In unit tests, Cleanup() might not have been called. 42 // In unit tests, Cleanup() might not have been called.
45 if (!deletion_callback_called_) { 43 if (!deletion_callback_called_) {
46 FOR_EACH_OBSERVER(RenderProcessHostObserver, 44 FOR_EACH_OBSERVER(RenderProcessHostObserver,
47 observers_, 45 observers_,
48 RenderProcessHostDestroyed(this)); 46 RenderProcessHostDestroyed(this));
49 RenderProcessHostImpl::UnregisterHost(GetID()); 47 RenderProcessHostImpl::UnregisterHost(GetID());
50 } 48 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return base::Process::Current().handle(); 132 return base::Process::Current().handle();
135 } 133 }
136 134
137 bool MockRenderProcessHost::Send(IPC::Message* msg) { 135 bool MockRenderProcessHost::Send(IPC::Message* msg) {
138 // Save the message in the sink. 136 // Save the message in the sink.
139 sink_.OnMessageReceived(*msg); 137 sink_.OnMessageReceived(*msg);
140 delete msg; 138 delete msg;
141 return true; 139 return true;
142 } 140 }
143 141
144 TransportDIB* MockRenderProcessHost::MapTransportDIB(TransportDIB::Id dib_id) {
145 #if defined(OS_WIN)
146 // NULL should be used here instead of INVALID_HANDLE_VALUE (or pseudo-handle)
147 // except for when dealing with the small number of Win16-derived APIs
148 // that require INVALID_HANDLE_VALUE (e.g. CreateFile and friends).
149 HANDLE duped = NULL;
150 if (!DuplicateHandle(GetCurrentProcess(), dib_id.handle, GetCurrentProcess(),
151 &duped, 0, TRUE, DUPLICATE_SAME_ACCESS))
152 duped = NULL;
153 return TransportDIB::Map(duped);
154 #elif defined(OS_ANDROID)
155 // On Android, Handles and Ids are the same underlying type.
156 return TransportDIB::Map(dib_id);
157 #else
158 // On POSIX, TransportDIBs are always created in the browser, so we cannot map
159 // one from a dib_id.
160 return TransportDIB::Create(100 * 100 * 4, 0);
161 #endif
162 }
163
164 TransportDIB* MockRenderProcessHost::GetTransportDIB(TransportDIB::Id dib_id) {
165 if (transport_dib_)
166 return transport_dib_;
167
168 transport_dib_ = MapTransportDIB(dib_id);
169 return transport_dib_;
170 }
171
172 int MockRenderProcessHost::GetID() const { 142 int MockRenderProcessHost::GetID() const {
173 return id_; 143 return id_;
174 } 144 }
175 145
176 bool MockRenderProcessHost::HasConnection() const { 146 bool MockRenderProcessHost::HasConnection() const {
177 return true; 147 return true;
178 } 148 }
179 149
180 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { 150 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) {
181 } 151 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); 278 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin();
309 it != processes_.end(); ++it) { 279 it != processes_.end(); ++it) {
310 if (*it == host) { 280 if (*it == host) {
311 processes_.weak_erase(it); 281 processes_.weak_erase(it);
312 break; 282 break;
313 } 283 }
314 } 284 }
315 } 285 }
316 286
317 } // content 287 } // content
OLDNEW
« no previous file with comments | « content/public/test/mock_render_process_host.h ('k') | content/renderer/render_process.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698