| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/utility_process_host.h" | 5 #include "chrome/browser/utility_process_host.h" |
| 6 | 6 |
| 7 #include "app/app_switches.h" | 7 #include "app/app_switches.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "ipc/ipc_switches.h" | 18 #include "ipc/ipc_switches.h" |
| 19 | 19 |
| 20 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
| 21 #include "chrome/browser/sandbox_policy.h" | 21 #include "chrome/browser/sandbox_policy.h" |
| 22 #elif defined(OS_POSIX) | 22 #elif defined(OS_POSIX) |
| 23 #include "base/global_descriptors_posix.h" | 23 #include "base/global_descriptors_posix.h" |
| 24 #include "ipc/ipc_descriptors.h" | 24 #include "ipc/ipc_descriptors.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 UtilityProcessHost::UtilityProcessHost(ResourceDispatcherHost* rdh, | 27 UtilityProcessHost::UtilityProcessHost(ResourceDispatcherHost* rdh, |
| 28 Client* client, | 28 Client* client, |
| 29 MessageLoop* client_loop) | 29 ChromeThread::ID client_thread_id) |
| 30 : ChildProcessHost(UTILITY_PROCESS, rdh), | 30 : ChildProcessHost(UTILITY_PROCESS, rdh), |
| 31 client_(client), | 31 client_(client), |
| 32 client_loop_(client_loop) { | 32 client_thread_id_(client_thread_id) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 UtilityProcessHost::~UtilityProcessHost() { | 35 UtilityProcessHost::~UtilityProcessHost() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) { | 38 bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) { |
| 39 // Grant the subprocess access to the entire subdir the extension file is | 39 // Grant the subprocess access to the entire subdir the extension file is |
| 40 // in, so that it can unpack to that dir. | 40 // in, so that it can unpack to that dir. |
| 41 if (!StartProcess(extension.DirName())) | 41 if (!StartProcess(extension.DirName())) |
| 42 return false; | 42 return false; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process); | 132 base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process); |
| 133 #endif | 133 #endif |
| 134 if (!process) | 134 if (!process) |
| 135 return false; | 135 return false; |
| 136 SetHandle(process); | 136 SetHandle(process); |
| 137 | 137 |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void UtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 141 void UtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 142 client_loop_->PostTask(FROM_HERE, | 142 ChromeThread::PostTask( |
| 143 client_thread_id_, FROM_HERE, |
| 143 NewRunnableMethod(client_.get(), &Client::OnMessageReceived, message)); | 144 NewRunnableMethod(client_.get(), &Client::OnMessageReceived, message)); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void UtilityProcessHost::OnChannelError() { | 147 void UtilityProcessHost::OnChannelError() { |
| 147 bool child_exited; | 148 bool child_exited; |
| 148 bool did_crash = base::DidProcessCrash(&child_exited, handle()); | 149 bool did_crash = base::DidProcessCrash(&child_exited, handle()); |
| 149 if (did_crash) { | 150 if (did_crash) { |
| 150 client_loop_->PostTask(FROM_HERE, | 151 ChromeThread::PostTask( |
| 152 client_thread_id_, FROM_HERE, |
| 151 NewRunnableMethod(client_.get(), &Client::OnProcessCrashed)); | 153 NewRunnableMethod(client_.get(), &Client::OnProcessCrashed)); |
| 152 } | 154 } |
| 153 } | 155 } |
| 154 | 156 |
| 155 void UtilityProcessHost::Client::OnMessageReceived( | 157 void UtilityProcessHost::Client::OnMessageReceived( |
| 156 const IPC::Message& message) { | 158 const IPC::Message& message) { |
| 157 IPC_BEGIN_MESSAGE_MAP(UtilityProcessHost, message) | 159 IPC_BEGIN_MESSAGE_MAP(UtilityProcessHost, message) |
| 158 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Succeeded, | 160 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Succeeded, |
| 159 Client::OnUnpackExtensionSucceeded) | 161 Client::OnUnpackExtensionSucceeded) |
| 160 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Failed, | 162 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Failed, |
| 161 Client::OnUnpackExtensionFailed) | 163 Client::OnUnpackExtensionFailed) |
| 162 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Succeeded, | 164 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Succeeded, |
| 163 Client::OnUnpackWebResourceSucceeded) | 165 Client::OnUnpackWebResourceSucceeded) |
| 164 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Failed, | 166 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Failed, |
| 165 Client::OnUnpackWebResourceFailed) | 167 Client::OnUnpackWebResourceFailed) |
| 166 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Succeeded, | 168 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Succeeded, |
| 167 Client::OnParseUpdateManifestSucceeded) | 169 Client::OnParseUpdateManifestSucceeded) |
| 168 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed, | 170 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed, |
| 169 Client::OnParseUpdateManifestFailed) | 171 Client::OnParseUpdateManifestFailed) |
| 170 IPC_END_MESSAGE_MAP_EX() | 172 IPC_END_MESSAGE_MAP_EX() |
| 171 } | 173 } |
| OLD | NEW |