OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 RenderProcessHostImpl::RegisterHost(GetID(), this); | 50 RenderProcessHostImpl::RegisterHost(GetID(), this); |
51 } | 51 } |
52 | 52 |
53 MockRenderProcessHost::~MockRenderProcessHost() { | 53 MockRenderProcessHost::~MockRenderProcessHost() { |
54 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); | 54 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); |
55 if (factory_) | 55 if (factory_) |
56 factory_->Remove(this); | 56 factory_->Remove(this); |
57 | 57 |
58 // In unit tests, Cleanup() might not have been called. | 58 // In unit tests, Cleanup() might not have been called. |
59 if (!deletion_callback_called_) { | 59 if (!deletion_callback_called_) { |
60 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 60 for (auto& observer : observers_) |
61 observers_, | 61 observer.RenderProcessHostDestroyed(this); |
62 RenderProcessHostDestroyed(this)); | |
63 RenderProcessHostImpl::UnregisterHost(GetID()); | 62 RenderProcessHostImpl::UnregisterHost(GetID()); |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 void MockRenderProcessHost::SimulateCrash() { | 66 void MockRenderProcessHost::SimulateCrash() { |
68 has_connection_ = false; | 67 has_connection_ = false; |
69 RenderProcessHost::RendererClosedDetails details( | 68 RenderProcessHost::RendererClosedDetails details( |
70 base::TERMINATION_STATUS_PROCESS_CRASHED, 0); | 69 base::TERMINATION_STATUS_PROCESS_CRASHED, 0); |
71 NotificationService::current()->Notify( | 70 NotificationService::current()->Notify( |
72 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 71 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
73 Details<RenderProcessHost::RendererClosedDetails>(&details)); | 72 Details<RenderProcessHost::RendererClosedDetails>(&details)); |
74 | 73 |
75 FOR_EACH_OBSERVER( | 74 for (auto& observer : observers_) |
76 RenderProcessHostObserver, observers_, | 75 observer.RenderProcessExited(this, details.status, details.exit_code); |
77 RenderProcessExited(this, details.status, details.exit_code)); | |
78 | 76 |
79 // Send every routing ID a FrameHostMsg_RenderProcessGone message. To ensure a | 77 // Send every routing ID a FrameHostMsg_RenderProcessGone message. To ensure a |
80 // predictable order for unittests which may assert against the order, we sort | 78 // predictable order for unittests which may assert against the order, we sort |
81 // the listeners by descending routing ID, instead of using the arbitrary | 79 // the listeners by descending routing ID, instead of using the arbitrary |
82 // hash-map order like RenderProcessHostImpl. | 80 // hash-map order like RenderProcessHostImpl. |
83 std::vector<std::pair<int32_t, IPC::Listener*>> sorted_listeners_; | 81 std::vector<std::pair<int32_t, IPC::Listener*>> sorted_listeners_; |
84 IDMap<IPC::Listener>::iterator iter(&listeners_); | 82 IDMap<IPC::Listener>::iterator iter(&listeners_); |
85 while (!iter.IsAtEnd()) { | 83 while (!iter.IsAtEnd()) { |
86 sorted_listeners_.push_back( | 84 sorted_listeners_.push_back( |
87 std::make_pair(iter.GetCurrentKey(), iter.GetCurrentValue())); | 85 std::make_pair(iter.GetCurrentKey(), iter.GetCurrentValue())); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 195 |
198 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { | 196 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { |
199 } | 197 } |
200 | 198 |
201 bool MockRenderProcessHost::IgnoreInputEvents() const { | 199 bool MockRenderProcessHost::IgnoreInputEvents() const { |
202 return false; | 200 return false; |
203 } | 201 } |
204 | 202 |
205 void MockRenderProcessHost::Cleanup() { | 203 void MockRenderProcessHost::Cleanup() { |
206 if (listeners_.IsEmpty()) { | 204 if (listeners_.IsEmpty()) { |
207 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 205 for (auto& observer : observers_) |
208 observers_, | 206 observer.RenderProcessHostDestroyed(this); |
209 RenderProcessHostDestroyed(this)); | |
210 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 207 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
211 RenderProcessHostImpl::UnregisterHost(GetID()); | 208 RenderProcessHostImpl::UnregisterHost(GetID()); |
212 deletion_callback_called_ = true; | 209 deletion_callback_called_ = true; |
213 } | 210 } |
214 } | 211 } |
215 | 212 |
216 void MockRenderProcessHost::AddPendingView() { | 213 void MockRenderProcessHost::AddPendingView() { |
217 } | 214 } |
218 | 215 |
219 void MockRenderProcessHost::RemovePendingView() { | 216 void MockRenderProcessHost::RemovePendingView() { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); | 368 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); |
372 it != processes_.end(); ++it) { | 369 it != processes_.end(); ++it) { |
373 if (*it == host) { | 370 if (*it == host) { |
374 processes_.weak_erase(it); | 371 processes_.weak_erase(it); |
375 break; | 372 break; |
376 } | 373 } |
377 } | 374 } |
378 } | 375 } |
379 | 376 |
380 } // namespace content | 377 } // namespace content |
OLD | NEW |