| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/browser_child_process_host.h" | 5 #include "chrome/browser/browser_child_process_host.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 NotificationType notification_type_; | 56 NotificationType notification_type_; |
| 57 ChildProcessInfo info_; | 57 ChildProcessInfo info_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 | 62 |
| 63 BrowserChildProcessHost::BrowserChildProcessHost( | 63 BrowserChildProcessHost::BrowserChildProcessHost( |
| 64 ProcessType type, ResourceDispatcherHost* resource_dispatcher_host) | 64 ChildProcessInfo::ProcessType type, |
| 65 : Receiver(type, -1), | 65 ResourceDispatcherHost* resource_dispatcher_host, |
| 66 ResourceMessageFilter::URLRequestContextOverride* |
| 67 url_request_context_override) |
| 68 : ChildProcessInfo(type, -1), |
| 66 ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), | 69 ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), |
| 67 resource_dispatcher_host_(resource_dispatcher_host) { | 70 resource_dispatcher_host_(resource_dispatcher_host) { |
| 71 Initialize(url_request_context_override); |
| 72 } |
| 73 |
| 74 BrowserChildProcessHost::BrowserChildProcessHost( |
| 75 ChildProcessInfo::ProcessType type, |
| 76 ResourceDispatcherHost* resource_dispatcher_host) |
| 77 : ChildProcessInfo(type, -1), |
| 78 ALLOW_THIS_IN_INITIALIZER_LIST(client_(this)), |
| 79 resource_dispatcher_host_(resource_dispatcher_host) { |
| 80 Initialize(NULL); |
| 81 } |
| 82 |
| 83 void BrowserChildProcessHost::Initialize( |
| 84 ResourceMessageFilter::URLRequestContextOverride* |
| 85 url_request_context_override) { |
| 86 if (resource_dispatcher_host_) { |
| 87 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( |
| 88 id(), type(), resource_dispatcher_host_); |
| 89 if (url_request_context_override) { |
| 90 resource_message_filter->set_url_request_context_override( |
| 91 url_request_context_override); |
| 92 } |
| 93 AddFilter(resource_message_filter); |
| 94 } |
| 95 |
| 68 g_child_process_list.Get().push_back(this); | 96 g_child_process_list.Get().push_back(this); |
| 69 } | 97 } |
| 70 | 98 |
| 71 | |
| 72 BrowserChildProcessHost::~BrowserChildProcessHost() { | 99 BrowserChildProcessHost::~BrowserChildProcessHost() { |
| 73 g_child_process_list.Get().remove(this); | 100 g_child_process_list.Get().remove(this); |
| 74 | |
| 75 if (resource_dispatcher_host_) | |
| 76 resource_dispatcher_host_->CancelRequestsForProcess(id()); | |
| 77 } | 101 } |
| 78 | 102 |
| 79 // static | 103 // static |
| 80 void BrowserChildProcessHost::SetCrashReporterCommandLine( | 104 void BrowserChildProcessHost::SetCrashReporterCommandLine( |
| 81 CommandLine* command_line) { | 105 CommandLine* command_line) { |
| 82 #if defined(USE_LINUX_BREAKPAD) | 106 #if defined(USE_LINUX_BREAKPAD) |
| 83 if (IsCrashReporterEnabled()) { | 107 if (IsCrashReporterEnabled()) { |
| 84 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, | 108 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 85 child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); | 109 child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); |
| 86 } | 110 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 144 } |
| 121 | 145 |
| 122 base::ProcessHandle BrowserChildProcessHost::GetChildProcessHandle() const { | 146 base::ProcessHandle BrowserChildProcessHost::GetChildProcessHandle() const { |
| 123 DCHECK(child_process_.get()) | 147 DCHECK(child_process_.get()) |
| 124 << "Requesting a child process handle before launching."; | 148 << "Requesting a child process handle before launching."; |
| 125 DCHECK(child_process_->GetHandle()) | 149 DCHECK(child_process_->GetHandle()) |
| 126 << "Requesting a child process handle before launch has completed OK."; | 150 << "Requesting a child process handle before launch has completed OK."; |
| 127 return child_process_->GetHandle(); | 151 return child_process_->GetHandle(); |
| 128 } | 152 } |
| 129 | 153 |
| 130 bool BrowserChildProcessHost::Send(IPC::Message* msg) { | |
| 131 return SendOnChannel(msg); | |
| 132 } | |
| 133 | |
| 134 void BrowserChildProcessHost::ForceShutdown() { | 154 void BrowserChildProcessHost::ForceShutdown() { |
| 135 g_child_process_list.Get().remove(this); | 155 g_child_process_list.Get().remove(this); |
| 136 ChildProcessHost::ForceShutdown(); | 156 ChildProcessHost::ForceShutdown(); |
| 137 } | 157 } |
| 138 | 158 |
| 139 void BrowserChildProcessHost::Notify(NotificationType type) { | 159 void BrowserChildProcessHost::Notify(NotificationType type) { |
| 140 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
| 141 BrowserThread::UI, FROM_HERE, new ChildNotificationTask(type, this)); | 161 BrowserThread::UI, FROM_HERE, new ChildNotificationTask(type, this)); |
| 142 } | 162 } |
| 143 | 163 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 169 } | 189 } |
| 170 default: | 190 default: |
| 171 break; | 191 break; |
| 172 } | 192 } |
| 173 // Notify in the main loop of the disconnection. | 193 // Notify in the main loop of the disconnection. |
| 174 Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); | 194 Notify(NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); |
| 175 } | 195 } |
| 176 ChildProcessHost::OnChildDied(); | 196 ChildProcessHost::OnChildDied(); |
| 177 } | 197 } |
| 178 | 198 |
| 179 bool BrowserChildProcessHost::InterceptMessageFromChild( | 199 void BrowserChildProcessHost::ShutdownStarted() { |
| 180 const IPC::Message& msg) { | 200 // Must remove the process from the list now, in case it gets used for a |
| 181 bool msg_is_ok = true; | 201 // new instance before our watcher tells us that the process terminated. |
| 182 bool handled = false; | 202 g_child_process_list.Get().remove(this); |
| 183 if (resource_dispatcher_host_) { | |
| 184 handled = resource_dispatcher_host_->OnMessageReceived( | |
| 185 msg, this, &msg_is_ok); | |
| 186 } | |
| 187 if (!handled && (msg.type() == PluginProcessHostMsg_ShutdownRequest::ID)) { | |
| 188 // Must remove the process from the list now, in case it gets used for a | |
| 189 // new instance before our watcher tells us that the process terminated. | |
| 190 g_child_process_list.Get().remove(this); | |
| 191 } | |
| 192 if (!msg_is_ok) | |
| 193 base::KillProcess(handle(), ResultCodes::KILLED_BAD_MESSAGE, false); | |
| 194 return handled; | |
| 195 } | 203 } |
| 196 | 204 |
| 197 BrowserChildProcessHost::ClientHook::ClientHook(BrowserChildProcessHost* host) | 205 BrowserChildProcessHost::ClientHook::ClientHook(BrowserChildProcessHost* host) |
| 198 : host_(host) { | 206 : host_(host) { |
| 199 } | 207 } |
| 200 | 208 |
| 201 void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { | 209 void BrowserChildProcessHost::ClientHook::OnProcessLaunched() { |
| 202 if (!host_->child_process_->GetHandle()) { | 210 if (!host_->child_process_->GetHandle()) { |
| 203 host_->OnChildDied(); | 211 host_->OnChildDied(); |
| 204 return; | 212 return; |
| 205 } | 213 } |
| 206 host_->set_handle(host_->child_process_->GetHandle()); | 214 host_->set_handle(host_->child_process_->GetHandle()); |
| 207 host_->OnProcessLaunched(); | 215 host_->OnProcessLaunched(); |
| 208 } | 216 } |
| 209 | 217 |
| 210 BrowserChildProcessHost::Iterator::Iterator() | 218 BrowserChildProcessHost::Iterator::Iterator() |
| 211 : all_(true), type_(UNKNOWN_PROCESS) { | 219 : all_(true), type_(UNKNOWN_PROCESS) { |
| 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << |
| 213 "ChildProcessInfo::Iterator must be used on the IO thread."; | 221 "ChildProcessInfo::Iterator must be used on the IO thread."; |
| 214 iterator_ = g_child_process_list.Get().begin(); | 222 iterator_ = g_child_process_list.Get().begin(); |
| 215 } | 223 } |
| 216 | 224 |
| 217 BrowserChildProcessHost::Iterator::Iterator(ProcessType type) | 225 BrowserChildProcessHost::Iterator::Iterator(ChildProcessInfo::ProcessType type) |
| 218 : all_(false), type_(type) { | 226 : all_(false), type_(type) { |
| 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << | 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)) << |
| 220 "ChildProcessInfo::Iterator must be used on the IO thread."; | 228 "ChildProcessInfo::Iterator must be used on the IO thread."; |
| 221 iterator_ = g_child_process_list.Get().begin(); | 229 iterator_ = g_child_process_list.Get().begin(); |
| 222 if (!Done() && (*iterator_)->type() != type_) | 230 if (!Done() && (*iterator_)->type() != type_) |
| 223 ++(*this); | 231 ++(*this); |
| 224 } | 232 } |
| 225 | 233 |
| 226 BrowserChildProcessHost* BrowserChildProcessHost::Iterator::operator++() { | 234 BrowserChildProcessHost* BrowserChildProcessHost::Iterator::operator++() { |
| 227 do { | 235 do { |
| 228 ++iterator_; | 236 ++iterator_; |
| 229 if (Done()) | 237 if (Done()) |
| 230 break; | 238 break; |
| 231 | 239 |
| 232 if (!all_ && (*iterator_)->type() != type_) | 240 if (!all_ && (*iterator_)->type() != type_) |
| 233 continue; | 241 continue; |
| 234 | 242 |
| 235 return *iterator_; | 243 return *iterator_; |
| 236 } while (true); | 244 } while (true); |
| 237 | 245 |
| 238 return NULL; | 246 return NULL; |
| 239 } | 247 } |
| 240 | 248 |
| 241 bool BrowserChildProcessHost::Iterator::Done() { | 249 bool BrowserChildProcessHost::Iterator::Done() { |
| 242 return iterator_ == g_child_process_list.Get().end(); | 250 return iterator_ == g_child_process_list.Get().end(); |
| 243 } | 251 } |
| OLD | NEW |