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

Side by Side Diff: content/browser/utility_process_host.cc

Issue 6995095: Move UtilityProcessHost to content and move the message sending/dispatching to the clients. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months 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 | « content/browser/utility_process_host.h ('k') | content/common/content_client.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 "chrome/browser/utility_process_host.h" 5 #include "content/browser/utility_process_host.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h"
9 #include "base/message_loop.h" 8 #include "base/message_loop.h"
10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
12 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/utility_messages.h" 11 #include "content/common/utility_messages.h"
14 #include "content/common/indexed_db_key.h"
15 #include "content/common/serialized_script_value.h"
16 #include "ipc/ipc_switches.h" 12 #include "ipc/ipc_switches.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/base/ui_base_switches.h" 13 #include "ui/base/ui_base_switches.h"
19 14
15 UtilityProcessHost::Client::Client() {
16 }
17
18 UtilityProcessHost::Client::~Client() {
19 }
20
21 void UtilityProcessHost::Client::OnProcessCrashed(int exit_code) {
22 }
23
24 bool UtilityProcessHost::Client::OnMessageReceived(
25 const IPC::Message& message) {
26 return false;
27 }
28
20 UtilityProcessHost::UtilityProcessHost(Client* client, 29 UtilityProcessHost::UtilityProcessHost(Client* client,
21 BrowserThread::ID client_thread_id) 30 BrowserThread::ID client_thread_id)
22 : BrowserChildProcessHost(UTILITY_PROCESS), 31 : BrowserChildProcessHost(UTILITY_PROCESS),
23 client_(client), 32 client_(client),
24 client_thread_id_(client_thread_id), 33 client_thread_id_(client_thread_id),
25 is_batch_mode_(false) { 34 is_batch_mode_(false),
35 started_(false) {
26 } 36 }
27 37
28 UtilityProcessHost::~UtilityProcessHost() { 38 UtilityProcessHost::~UtilityProcessHost() {
29 DCHECK(!is_batch_mode_); 39 DCHECK(!is_batch_mode_);
30 } 40 }
31 41
32 bool UtilityProcessHost::StartExtensionUnpacker(const FilePath& extension) { 42 bool UtilityProcessHost::Send(IPC::Message* message) {
33 // Grant the subprocess access to the entire subdir the extension file is 43 if (!StartProcess())
34 // in, so that it can unpack to that dir.
35 if (!StartProcess(extension.DirName()))
36 return false; 44 return false;
37 45
38 Send(new UtilityMsg_UnpackExtension(extension)); 46 return BrowserChildProcessHost::Send(message);
39 return true;
40 }
41
42 bool UtilityProcessHost::StartWebResourceUnpacker(const std::string& data) {
43 if (!StartProcess(FilePath()))
44 return false;
45
46 Send(new UtilityMsg_UnpackWebResource(data));
47 return true;
48 }
49
50 bool UtilityProcessHost::StartUpdateManifestParse(const std::string& xml) {
51 if (!StartProcess(FilePath()))
52 return false;
53
54 Send(new UtilityMsg_ParseUpdateManifest(xml));
55 return true;
56 }
57
58 bool UtilityProcessHost::StartImageDecoding(
59 const std::vector<unsigned char>& encoded_data) {
60 if (!StartProcess(FilePath()))
61 return false;
62
63 Send(new UtilityMsg_DecodeImage(encoded_data));
64 return true;
65 }
66
67 bool UtilityProcessHost::StartImageDecodingBase64(
68 const std::string& base64_encoded_data) {
69 if (!StartProcess(FilePath()))
70 return false;
71
72 Send(new UtilityMsg_DecodeImageBase64(base64_encoded_data));
73 return true;
74 }
75
76 bool UtilityProcessHost::StartIDBKeysFromValuesAndKeyPath(
77 int id, const std::vector<SerializedScriptValue>& serialized_values,
78 const string16& key_path) {
79 if (!StartProcess(FilePath()))
80 return false;
81
82 Send(new UtilityMsg_IDBKeysFromValuesAndKeyPath(
83 id, serialized_values, key_path));
84 return true;
85 }
86
87 bool UtilityProcessHost::StartInjectIDBKey(
88 const IndexedDBKey& key, const SerializedScriptValue& value,
89 const string16& key_path) {
90 if (!StartProcess(FilePath()))
91 return false;
92
93 Send(new UtilityMsg_InjectIDBKey(key, value, key_path));
94 return true;
95 }
96
97 bool UtilityProcessHost::StartJSONParsing(const std::string& json) {
98 if (!StartProcess(FilePath()))
99 return false;
100 Send(new UtilityMsg_ParseJSON(json));
101 return true;
102 } 47 }
103 48
104 bool UtilityProcessHost::StartBatchMode() { 49 bool UtilityProcessHost::StartBatchMode() {
105 CHECK(!is_batch_mode_); 50 CHECK(!is_batch_mode_);
106 is_batch_mode_ = StartProcess(FilePath()); 51 is_batch_mode_ = StartProcess();
107 Send(new UtilityMsg_BatchMode_Started()); 52 Send(new UtilityMsg_BatchMode_Started());
108 return is_batch_mode_; 53 return is_batch_mode_;
109 } 54 }
110 55
111 void UtilityProcessHost::EndBatchMode() { 56 void UtilityProcessHost::EndBatchMode() {
112 CHECK(is_batch_mode_); 57 CHECK(is_batch_mode_);
113 is_batch_mode_ = false; 58 is_batch_mode_ = false;
114 Send(new UtilityMsg_BatchMode_Finished()); 59 Send(new UtilityMsg_BatchMode_Finished());
115 } 60 }
116 61
117 FilePath UtilityProcessHost::GetUtilityProcessCmd() { 62 FilePath UtilityProcessHost::GetUtilityProcessCmd() {
118 return GetChildPath(true); 63 return GetChildPath(true);
119 } 64 }
120 65
121 bool UtilityProcessHost::StartProcess(const FilePath& exposed_dir) { 66 bool UtilityProcessHost::StartProcess() {
67 if (started_)
68 return true;
69 started_ = true;
Matt Perry 2011/06/09 20:54:49 we should only set this at the end of the method,
jam 2011/06/09 21:13:45 I think it doesn't matter either way, because if i
70
122 if (is_batch_mode_) 71 if (is_batch_mode_)
123 return true; 72 return true;
124 // Name must be set or metrics_service will crash in any test which 73 // Name must be set or metrics_service will crash in any test which
125 // launches a UtilityProcessHost. 74 // launches a UtilityProcessHost.
126 set_name(L"utility process"); 75 set_name(L"utility process");
127 76
128 if (!CreateChannel()) 77 if (!CreateChannel())
129 return false; 78 return false;
130 79
131 FilePath exe_path = GetUtilityProcessCmd(); 80 FilePath exe_path = GetUtilityProcessCmd();
(...skipping 25 matching lines...) Expand all
157 // Linux updating. 106 // Linux updating.
158 bool has_cmd_prefix = browser_command_line.HasSwitch( 107 bool has_cmd_prefix = browser_command_line.HasSwitch(
159 switches::kUtilityCmdPrefix); 108 switches::kUtilityCmdPrefix);
160 if (has_cmd_prefix) { 109 if (has_cmd_prefix) {
161 // launch the utility child process with some prefix (usually "xterm -e gdb 110 // launch the utility child process with some prefix (usually "xterm -e gdb
162 // --args"). 111 // --args").
163 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( 112 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative(
164 switches::kUtilityCmdPrefix)); 113 switches::kUtilityCmdPrefix));
165 } 114 }
166 115
167 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir); 116 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_);
168 #endif 117 #endif
169 118
170 Launch( 119 Launch(
171 #if defined(OS_WIN) 120 #if defined(OS_WIN)
172 exposed_dir, 121 exposed_dir_,
173 #elif defined(OS_POSIX) 122 #elif defined(OS_POSIX)
174 false, 123 false,
175 base::environment_vector(), 124 base::environment_vector(),
176 #endif 125 #endif
177 cmd_line); 126 cmd_line);
178 127
179 return true; 128 return true;
180 } 129 }
181 130
182 bool UtilityProcessHost::OnMessageReceived(const IPC::Message& message) { 131 bool UtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
183 BrowserThread::PostTask( 132 BrowserThread::PostTask(
184 client_thread_id_, FROM_HERE, 133 client_thread_id_, FROM_HERE,
185 NewRunnableMethod(client_.get(), &Client::OnMessageReceived, message)); 134 NewRunnableMethod(client_.get(), &Client::OnMessageReceived, message));
186 return true; 135 return true;
187 } 136 }
188 137
189 void UtilityProcessHost::OnProcessCrashed(int exit_code) { 138 void UtilityProcessHost::OnProcessCrashed(int exit_code) {
190 BrowserThread::PostTask( 139 BrowserThread::PostTask(
191 client_thread_id_, FROM_HERE, 140 client_thread_id_, FROM_HERE,
192 NewRunnableMethod(client_.get(), &Client::OnProcessCrashed, exit_code)); 141 NewRunnableMethod(client_.get(), &Client::OnProcessCrashed, exit_code));
193 } 142 }
194 143
195 bool UtilityProcessHost::CanShutdown() { 144 bool UtilityProcessHost::CanShutdown() {
196 return true; 145 return true;
197 } 146 }
198
199 bool UtilityProcessHost::Client::OnMessageReceived(
200 const IPC::Message& message) {
201 bool handled = true;
202 IPC_BEGIN_MESSAGE_MAP(UtilityProcessHost, message)
203 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Succeeded,
204 Client::OnUnpackExtensionSucceeded)
205 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackExtension_Failed,
206 Client::OnUnpackExtensionFailed)
207 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Succeeded,
208 Client::OnUnpackWebResourceSucceeded)
209 IPC_MESSAGE_HANDLER(UtilityHostMsg_UnpackWebResource_Failed,
210 Client::OnUnpackWebResourceFailed)
211 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Succeeded,
212 Client::OnParseUpdateManifestSucceeded)
213 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseUpdateManifest_Failed,
214 Client::OnParseUpdateManifestFailed)
215 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Succeeded,
216 Client::OnDecodeImageSucceeded)
217 IPC_MESSAGE_HANDLER(UtilityHostMsg_DecodeImage_Failed,
218 Client::OnDecodeImageFailed)
219 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded,
220 Client::OnIDBKeysFromValuesAndKeyPathSucceeded)
221 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed,
222 Client::OnIDBKeysFromValuesAndKeyPathFailed)
223 IPC_MESSAGE_HANDLER(UtilityHostMsg_InjectIDBKey_Finished,
224 Client::OnInjectIDBKeyFinished)
225 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseJSON_Succeeded,
226 Client::OnJSONParseSucceeded)
227 IPC_MESSAGE_HANDLER(UtilityHostMsg_ParseJSON_Failed,
228 Client::OnJSONParseFailed)
229 IPC_MESSAGE_UNHANDLED(handled = false)
230 IPC_END_MESSAGE_MAP_EX()
231 return handled;
232 }
OLDNEW
« no previous file with comments | « content/browser/utility_process_host.h ('k') | content/common/content_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698