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 "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/utility_messages.h" | 13 #include "chrome/common/utility_messages.h" |
14 #include "ipc/ipc_switches.h" | 14 #include "ipc/ipc_switches.h" |
15 | 15 |
16 UtilityProcessHost::UtilityProcessHost(ResourceDispatcherHost* rdh, | 16 UtilityProcessHost::UtilityProcessHost(ResourceDispatcherHost* rdh, |
17 Client* client, | 17 Client* client, |
18 ChromeThread::ID client_thread_id) | 18 ChromeThread::ID client_thread_id) |
19 : BrowserChildProcessHost(UTILITY_PROCESS, rdh), | 19 : BrowserChildProcessHost(UTILITY_PROCESS, rdh), |
20 client_(client), | 20 client_(client), |
21 client_thread_id_(client_thread_id) { | 21 client_thread_id_(client_thread_id), |
| 22 is_batch_mode_(false) { |
22 } | 23 } |
23 | 24 |
24 UtilityProcessHost::~UtilityProcessHost() { | 25 UtilityProcessHost::~UtilityProcessHost() { |
| 26 DCHECK(!is_batch_mode_); |
25 } | 27 } |
26 | 28 |
27 bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) { | 29 bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) { |
28 // Grant the subprocess access to the entire subdir the extension file is | 30 // Grant the subprocess access to the entire subdir the extension file is |
29 // in, so that it can unpack to that dir. | 31 // in, so that it can unpack to that dir. |
30 if (!StartProcess(extension.DirName())) | 32 if (!StartProcess(extension.DirName())) |
31 return false; | 33 return false; |
32 | 34 |
33 Send(new UtilityMsg_UnpackExtension(extension)); | 35 Send(new UtilityMsg_UnpackExtension(extension)); |
34 return true; | 36 return true; |
(...skipping 17 matching lines...) Expand all Loading... |
52 | 54 |
53 bool UtilityProcessHost::StartImageDecoding( | 55 bool UtilityProcessHost::StartImageDecoding( |
54 const std::vector<unsigned char>& encoded_data) { | 56 const std::vector<unsigned char>& encoded_data) { |
55 if (!StartProcess(FilePath())) | 57 if (!StartProcess(FilePath())) |
56 return false; | 58 return false; |
57 | 59 |
58 Send(new UtilityMsg_DecodeImage(encoded_data)); | 60 Send(new UtilityMsg_DecodeImage(encoded_data)); |
59 return true; | 61 return true; |
60 } | 62 } |
61 | 63 |
| 64 bool UtilityProcessHost::StartIDBKeysFromValuesAndKeyPath( |
| 65 int id, const std::vector<SerializedScriptValue>& serialized_values, |
| 66 const string16& key_path) { |
| 67 if (!StartProcess(FilePath())) |
| 68 return false; |
| 69 |
| 70 Send(new UtilityMsg_IDBKeysFromValuesAndKeyPath( |
| 71 id, serialized_values, key_path)); |
| 72 return true; |
| 73 } |
| 74 |
| 75 bool UtilityProcessHost::StartBatchMode() { |
| 76 CHECK(!is_batch_mode_); |
| 77 is_batch_mode_ = StartProcess(FilePath()); |
| 78 Send(new UtilityMsg_BatchMode_Started()); |
| 79 return is_batch_mode_; |
| 80 } |
| 81 |
| 82 void UtilityProcessHost::EndBatchMode() { |
| 83 CHECK(is_batch_mode_); |
| 84 is_batch_mode_ = false; |
| 85 Send(new UtilityMsg_BatchMode_Finished()); |
| 86 } |
| 87 |
62 FilePath UtilityProcessHost::GetUtilityProcessCmd() { | 88 FilePath UtilityProcessHost::GetUtilityProcessCmd() { |
63 return GetChildPath(true); | 89 return GetChildPath(true); |
64 } | 90 } |
65 | 91 |
66 bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) { | 92 bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) { |
| 93 if (is_batch_mode_) |
| 94 return true; |
67 // Name must be set or metrics_service will crash in any test which | 95 // Name must be set or metrics_service will crash in any test which |
68 // launches a UtilityProcessHost. | 96 // launches a UtilityProcessHost. |
69 set_name(L"utility process"); | 97 set_name(L"utility process"); |
70 | 98 |
71 if (!CreateChannel()) | 99 if (!CreateChannel()) |
72 return false; | 100 return false; |
73 | 101 |
74 FilePath exe_path = GetUtilityProcessCmd(); | 102 FilePath exe_path = GetUtilityProcessCmd(); |
75 if (exe_path.empty()) { | 103 if (exe_path.empty()) { |
76 NOTREACHED() << "Unable to get utility process binary name."; | 104 NOTREACHED() << "Unable to get utility process binary name."; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Failed, | 180 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Failed, |
153 Client::OnUnpackWebResourceFailed) | 181 Client::OnUnpackWebResourceFailed) |
154 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Succeeded, | 182 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Succeeded, |
155 Client::OnParseUpdateManifestSucceeded) | 183 Client::OnParseUpdateManifestSucceeded) |
156 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed, | 184 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed, |
157 Client::OnParseUpdateManifestFailed) | 185 Client::OnParseUpdateManifestFailed) |
158 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Succeeded, | 186 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Succeeded, |
159 Client::OnDecodeImageSucceeded) | 187 Client::OnDecodeImageSucceeded) |
160 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Failed, | 188 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Failed, |
161 Client::OnDecodeImageFailed) | 189 Client::OnDecodeImageFailed) |
| 190 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded, |
| 191 Client::OnIDBKeysFromValuesAndKeyPathSucceeded) |
| 192 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed, |
| 193 Client::OnIDBKeysFromValuesAndKeyPathFailed) |
162 IPC_END_MESSAGE_MAP_EX() | 194 IPC_END_MESSAGE_MAP_EX() |
163 } | 195 } |
OLD | NEW |