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

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

Issue 72203003: Introduce RenderProcessHostObserver, use it in its first client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 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
« no previous file with comments | « content/public/test/mock_render_process_host.h ('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 (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/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/render_widget_host_iterator.h" 17 #include "content/public/browser/render_widget_host_iterator.h"
18 #include "content/public/browser/storage_partition.h" 18 #include "content/public/browser/storage_partition.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 MockRenderProcessHost::MockRenderProcessHost( 22 MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context)
23 BrowserContext* browser_context) 23 : transport_dib_(NULL),
24 : transport_dib_(NULL), 24 bad_msg_count_(0),
25 bad_msg_count_(0), 25 factory_(NULL),
26 factory_(NULL), 26 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
27 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 27 browser_context_(browser_context),
28 browser_context_(browser_context), 28 prev_routing_id_(0),
29 prev_routing_id_(0), 29 fast_shutdown_started_(false),
30 fast_shutdown_started_(false) { 30 deletion_callback_called_(false) {
31 // 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
32 // ourselves as an existing child process. 32 // ourselves as an existing child process.
33 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); 33 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID());
34 34
35 RenderProcessHostImpl::RegisterHost(GetID(), this); 35 RenderProcessHostImpl::RegisterHost(GetID(), this);
36 } 36 }
37 37
38 MockRenderProcessHost::~MockRenderProcessHost() { 38 MockRenderProcessHost::~MockRenderProcessHost() {
39 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 39 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
40 delete transport_dib_; 40 delete transport_dib_;
41 if (factory_) 41 if (factory_)
42 factory_->Remove(this); 42 factory_->Remove(this);
43 // In unit tests, Release() might not have been called. 43
44 RenderProcessHostImpl::UnregisterHost(GetID()); 44 // In unit tests, Cleanup() might not have been called.
45 if (!deletion_callback_called_) {
46 FOR_EACH_OBSERVER(RenderProcessHostObserver,
47 observers_,
48 RenderProcessHostDestroyed(this));
49 RenderProcessHostImpl::UnregisterHost(GetID());
50 }
45 } 51 }
46 52
47 void MockRenderProcessHost::EnableSendQueue() { 53 void MockRenderProcessHost::EnableSendQueue() {
48 } 54 }
49 55
50 bool MockRenderProcessHost::Init() { 56 bool MockRenderProcessHost::Init() {
51 return true; 57 return true;
52 } 58 }
53 59
54 int MockRenderProcessHost::GetNextRoutingID() { 60 int MockRenderProcessHost::GetNextRoutingID() {
55 return ++prev_routing_id_; 61 return ++prev_routing_id_;
56 } 62 }
57 63
58 void MockRenderProcessHost::AddRoute( 64 void MockRenderProcessHost::AddRoute(
59 int32 routing_id, 65 int32 routing_id,
60 IPC::Listener* listener) { 66 IPC::Listener* listener) {
61 listeners_.AddWithID(listener, routing_id); 67 listeners_.AddWithID(listener, routing_id);
62 } 68 }
63 69
64 void MockRenderProcessHost::RemoveRoute(int32 routing_id) { 70 void MockRenderProcessHost::RemoveRoute(int32 routing_id) {
65 DCHECK(listeners_.Lookup(routing_id) != NULL); 71 DCHECK(listeners_.Lookup(routing_id) != NULL);
66 listeners_.Remove(routing_id); 72 listeners_.Remove(routing_id);
67 Cleanup(); 73 Cleanup();
68 } 74 }
69 75
76 void MockRenderProcessHost::AddObserver(RenderProcessHostObserver* observer) {
77 observers_.AddObserver(observer);
78 }
79
80 void MockRenderProcessHost::RemoveObserver(
81 RenderProcessHostObserver* observer) {
82 observers_.RemoveObserver(observer);
83 }
84
70 bool MockRenderProcessHost::WaitForBackingStoreMsg( 85 bool MockRenderProcessHost::WaitForBackingStoreMsg(
71 int render_widget_id, 86 int render_widget_id,
72 const base::TimeDelta& max_delay, 87 const base::TimeDelta& max_delay,
73 IPC::Message* msg) { 88 IPC::Message* msg) {
74 return false; 89 return false;
75 } 90 }
76 91
77 void MockRenderProcessHost::ReceivedBadMessage() { 92 void MockRenderProcessHost::ReceivedBadMessage() {
78 ++bad_msg_count_; 93 ++bad_msg_count_;
79 } 94 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 177
163 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { 178 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) {
164 } 179 }
165 180
166 bool MockRenderProcessHost::IgnoreInputEvents() const { 181 bool MockRenderProcessHost::IgnoreInputEvents() const {
167 return false; 182 return false;
168 } 183 }
169 184
170 void MockRenderProcessHost::Cleanup() { 185 void MockRenderProcessHost::Cleanup() {
171 if (listeners_.IsEmpty()) { 186 if (listeners_.IsEmpty()) {
187 FOR_EACH_OBSERVER(RenderProcessHostObserver,
188 observers_,
189 RenderProcessHostDestroyed(this));
172 NotificationService::current()->Notify( 190 NotificationService::current()->Notify(
173 NOTIFICATION_RENDERER_PROCESS_TERMINATED, 191 NOTIFICATION_RENDERER_PROCESS_TERMINATED,
174 Source<RenderProcessHost>(this), 192 Source<RenderProcessHost>(this),
175 NotificationService::NoDetails()); 193 NotificationService::NoDetails());
176 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 194 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
177 RenderProcessHostImpl::UnregisterHost(GetID()); 195 RenderProcessHostImpl::UnregisterHost(GetID());
196 deletion_callback_called_ = true;
178 } 197 }
179 } 198 }
180 199
181 void MockRenderProcessHost::AddPendingView() { 200 void MockRenderProcessHost::AddPendingView() {
182 } 201 }
183 202
184 void MockRenderProcessHost::RemovePendingView() { 203 void MockRenderProcessHost::RemovePendingView() {
185 } 204 }
186 205
187 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) { 206 void MockRenderProcessHost::SetSuddenTerminationAllowed(bool allowed) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); 292 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin();
274 it != processes_.end(); ++it) { 293 it != processes_.end(); ++it) {
275 if (*it == host) { 294 if (*it == host) {
276 processes_.weak_erase(it); 295 processes_.weak_erase(it);
277 break; 296 break;
278 } 297 }
279 } 298 }
280 } 299 }
281 300
282 } // content 301 } // content
OLDNEW
« no previous file with comments | « content/public/test/mock_render_process_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698