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

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

Issue 8597005: Provide a way for RenderProcessHosts to register themselves in the global host map. (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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.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) 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" 7 #include "base/lazy_instance.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "content/browser/child_process_security_policy.h" 10 #include "content/browser/child_process_security_policy.h"
11 #include "content/browser/renderer_host/render_process_host_impl.h"
11 #include "content/common/child_process_info.h" 12 #include "content/common/child_process_info.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
14 15
15 // This map is the global list of all renderer processes and is defined in
16 // render_process_host_impl.cc
17 // TODO(ananta)
18 // Clean up this dependency in a subsequent CL.
19 extern base::LazyInstance<
20 IDMap<content::RenderProcessHost>,
21 base::LeakyLazyInstanceTraits<IDMap<content::RenderProcessHost> > >
22 g_all_hosts;
23
24 MockRenderProcessHost::MockRenderProcessHost( 16 MockRenderProcessHost::MockRenderProcessHost(
25 content::BrowserContext* browser_context) 17 content::BrowserContext* browser_context)
26 : transport_dib_(NULL), 18 : transport_dib_(NULL),
27 bad_msg_count_(0), 19 bad_msg_count_(0),
28 factory_(NULL), 20 factory_(NULL),
29 id_(ChildProcessInfo::GenerateChildProcessUniqueId()), 21 id_(ChildProcessInfo::GenerateChildProcessUniqueId()),
30 browser_context_(browser_context), 22 browser_context_(browser_context),
31 max_page_id_(-1), 23 max_page_id_(-1),
32 fast_shutdown_started_(false) { 24 fast_shutdown_started_(false) {
33 // Child process security operations can't be unit tested unless we add 25 // Child process security operations can't be unit tested unless we add
34 // ourselves as an existing child process. 26 // ourselves as an existing child process.
35 ChildProcessSecurityPolicy::GetInstance()->Add(GetID()); 27 ChildProcessSecurityPolicy::GetInstance()->Add(GetID());
36 g_all_hosts.Get().AddWithID(this, GetID()); 28
29 RenderProcessHostImpl::RegisterHost(GetID(), this);
37 } 30 }
38 31
39 MockRenderProcessHost::~MockRenderProcessHost() { 32 MockRenderProcessHost::~MockRenderProcessHost() {
40 ChildProcessSecurityPolicy::GetInstance()->Remove(GetID()); 33 ChildProcessSecurityPolicy::GetInstance()->Remove(GetID());
41 delete transport_dib_; 34 delete transport_dib_;
42 if (factory_) 35 if (factory_)
43 factory_->Remove(this); 36 factory_->Remove(this);
44 // In unit tests, Release() might not have been called. 37 // In unit tests, Release() might not have been called.
45 if (g_all_hosts.Get().Lookup(GetID())) 38 RenderProcessHostImpl::UnregisterHost(GetID());
46 g_all_hosts.Get().Remove(GetID());
47 } 39 }
48 40
49 void MockRenderProcessHost::EnableSendQueue() { 41 void MockRenderProcessHost::EnableSendQueue() {
50 } 42 }
51 43
52 bool MockRenderProcessHost::Init(bool is_accessibility_enabled) { 44 bool MockRenderProcessHost::Init(bool is_accessibility_enabled) {
53 return true; 45 return true;
54 } 46 }
55 47
56 int MockRenderProcessHost::GetNextRoutingID() { 48 int MockRenderProcessHost::GetNextRoutingID() {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 Cleanup(); 158 Cleanup();
167 } 159 }
168 160
169 void MockRenderProcessHost::Cleanup() { 161 void MockRenderProcessHost::Cleanup() {
170 if (listeners_.IsEmpty()) { 162 if (listeners_.IsEmpty()) {
171 content::NotificationService::current()->Notify( 163 content::NotificationService::current()->Notify(
172 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 164 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
173 content::Source<RenderProcessHost>(this), 165 content::Source<RenderProcessHost>(this),
174 content::NotificationService::NoDetails()); 166 content::NotificationService::NoDetails());
175 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 167 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
176 g_all_hosts.Get().Remove(GetID()); 168 RenderProcessHostImpl::UnregisterHost(GetID());
177 } 169 }
178 } 170 }
179 171
180 void MockRenderProcessHost::ReportExpectingClose(int32 listener_id) { 172 void MockRenderProcessHost::ReportExpectingClose(int32 listener_id) {
181 } 173 }
182 174
183 void MockRenderProcessHost::AddPendingView() { 175 void MockRenderProcessHost::AddPendingView() {
184 } 176 }
185 177
186 void MockRenderProcessHost::RemovePendingView() { 178 void MockRenderProcessHost::RemovePendingView() {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 250
259 void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const { 251 void MockRenderProcessHostFactory::Remove(MockRenderProcessHost* host) const {
260 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); 252 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin();
261 it != processes_.end(); ++it) { 253 it != processes_.end(); ++it) {
262 if (*it == host) { 254 if (*it == host) {
263 processes_.weak_erase(it); 255 processes_.weak_erase(it);
264 break; 256 break;
265 } 257 }
266 } 258 }
267 } 259 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698