OLD | NEW |
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/service/service_utility_process_host.h" | 5 #include "chrome/service/service_utility_process_host.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
11 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
15 #include "ipc/ipc_switches.h" | 16 #include "ipc/ipc_switches.h" |
16 #include "printing/page_range.h" | 17 #include "printing/page_range.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 127 |
127 bool ServiceUtilityProcessHost::CanShutdown() { | 128 bool ServiceUtilityProcessHost::CanShutdown() { |
128 return true; | 129 return true; |
129 } | 130 } |
130 | 131 |
131 void ServiceUtilityProcessHost::OnChildDied() { | 132 void ServiceUtilityProcessHost::OnChildDied() { |
132 if (waiting_for_reply_) { | 133 if (waiting_for_reply_) { |
133 // If we are yet to receive a reply then notify the client that the | 134 // If we are yet to receive a reply then notify the client that the |
134 // child died. | 135 // child died. |
135 client_message_loop_proxy_->PostTask( | 136 client_message_loop_proxy_->PostTask( |
136 FROM_HERE, | 137 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
137 NewRunnableMethod(client_.get(), &Client::OnChildDied)); | |
138 } | 138 } |
139 // The base class implementation will delete |this|. | 139 // The base class implementation will delete |this|. |
140 ServiceChildProcessHost::OnChildDied(); | 140 ServiceChildProcessHost::OnChildDied(); |
141 } | 141 } |
142 | 142 |
143 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 143 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
144 bool msg_is_ok = false; | 144 bool msg_is_ok = false; |
145 IPC_BEGIN_MESSAGE_MAP_EX(ServiceUtilityProcessHost, message, msg_is_ok) | 145 IPC_BEGIN_MESSAGE_MAP_EX(ServiceUtilityProcessHost, message, msg_is_ok) |
146 #if defined(OS_WIN) // This hack is Windows-specific. | 146 #if defined(OS_WIN) // This hack is Windows-specific. |
147 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) | 147 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) |
(...skipping 28 matching lines...) Expand all Loading... |
176 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded( | 176 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded( |
177 int highest_rendered_page_number) { | 177 int highest_rendered_page_number) { |
178 DCHECK(waiting_for_reply_); | 178 DCHECK(waiting_for_reply_); |
179 waiting_for_reply_ = false; | 179 waiting_for_reply_ = false; |
180 // If the metafile was successfully created, we need to take our hands off the | 180 // If the metafile was successfully created, we need to take our hands off the |
181 // scratch metafile directory. The client will delete it when it is done with | 181 // scratch metafile directory. The client will delete it when it is done with |
182 // metafile. | 182 // metafile. |
183 scratch_metafile_dir_->Take(); | 183 scratch_metafile_dir_->Take(); |
184 client_message_loop_proxy_->PostTask( | 184 client_message_loop_proxy_->PostTask( |
185 FROM_HERE, | 185 FROM_HERE, |
186 NewRunnableMethod(client_.get(), | 186 base::Bind(&Client::MetafileAvailable, client_.get(), metafile_path_, |
187 &Client::MetafileAvailable, | 187 highest_rendered_page_number)); |
188 metafile_path_, | |
189 highest_rendered_page_number)); | |
190 } | 188 } |
191 | 189 |
192 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileFailed() { | 190 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileFailed() { |
193 DCHECK(waiting_for_reply_); | 191 DCHECK(waiting_for_reply_); |
194 waiting_for_reply_ = false; | 192 waiting_for_reply_ = false; |
195 client_message_loop_proxy_->PostTask( | 193 client_message_loop_proxy_->PostTask( |
196 FROM_HERE, | 194 FROM_HERE, |
197 NewRunnableMethod(client_.get(), | 195 base::Bind(&Client::OnRenderPDFPagesToMetafileFailed, client_.get())); |
198 &Client::OnRenderPDFPagesToMetafileFailed)); | |
199 } | 196 } |
200 | 197 |
201 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded( | 198 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded( |
202 const std::string& printer_name, | 199 const std::string& printer_name, |
203 const printing::PrinterCapsAndDefaults& caps_and_defaults) { | 200 const printing::PrinterCapsAndDefaults& caps_and_defaults) { |
204 DCHECK(waiting_for_reply_); | 201 DCHECK(waiting_for_reply_); |
205 waiting_for_reply_ = false; | 202 waiting_for_reply_ = false; |
206 client_message_loop_proxy_->PostTask( | 203 client_message_loop_proxy_->PostTask( |
207 FROM_HERE, | 204 FROM_HERE, |
208 NewRunnableMethod(client_.get(), | 205 base::Bind(&Client::OnGetPrinterCapsAndDefaultsSucceeded, client_.get(), |
209 &Client::OnGetPrinterCapsAndDefaultsSucceeded, | 206 printer_name, caps_and_defaults)); |
210 printer_name, | |
211 caps_and_defaults)); | |
212 } | 207 } |
213 | 208 |
214 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed( | 209 void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed( |
215 const std::string& printer_name) { | 210 const std::string& printer_name) { |
216 DCHECK(waiting_for_reply_); | 211 DCHECK(waiting_for_reply_); |
217 waiting_for_reply_ = false; | 212 waiting_for_reply_ = false; |
218 client_message_loop_proxy_->PostTask( | 213 client_message_loop_proxy_->PostTask( |
219 FROM_HERE, | 214 FROM_HERE, |
220 NewRunnableMethod(client_.get(), | 215 base::Bind(&Client::OnGetPrinterCapsAndDefaultsFailed, client_.get(), |
221 &Client::OnGetPrinterCapsAndDefaultsFailed, | 216 printer_name)); |
222 printer_name)); | |
223 } | 217 } |
224 | 218 |
225 void ServiceUtilityProcessHost::Client::MetafileAvailable( | 219 void ServiceUtilityProcessHost::Client::MetafileAvailable( |
226 const FilePath& metafile_path, | 220 const FilePath& metafile_path, |
227 int highest_rendered_page_number) { | 221 int highest_rendered_page_number) { |
228 // The metafile was created in a temp folder which needs to get deleted after | 222 // The metafile was created in a temp folder which needs to get deleted after |
229 // we have processed it. | 223 // we have processed it. |
230 ScopedTempDir scratch_metafile_dir; | 224 ScopedTempDir scratch_metafile_dir; |
231 if (!scratch_metafile_dir.Set(metafile_path.DirName())) | 225 if (!scratch_metafile_dir.Set(metafile_path.DirName())) |
232 LOG(WARNING) << "Unable to set scratch metafile directory"; | 226 LOG(WARNING) << "Unable to set scratch metafile directory"; |
233 #if defined(OS_WIN) | 227 #if defined(OS_WIN) |
234 // It's important that metafile is declared after scratch_metafile_dir so | 228 // It's important that metafile is declared after scratch_metafile_dir so |
235 // that the metafile destructor closes the file before the ScopedTempDir | 229 // that the metafile destructor closes the file before the ScopedTempDir |
236 // destructor tries to remove the directory. | 230 // destructor tries to remove the directory. |
237 printing::Emf metafile; | 231 printing::Emf metafile; |
238 if (!metafile.InitFromFile(metafile_path)) { | 232 if (!metafile.InitFromFile(metafile_path)) { |
239 OnRenderPDFPagesToMetafileFailed(); | 233 OnRenderPDFPagesToMetafileFailed(); |
240 } else { | 234 } else { |
241 OnRenderPDFPagesToMetafileSucceeded(metafile, | 235 OnRenderPDFPagesToMetafileSucceeded(metafile, |
242 highest_rendered_page_number); | 236 highest_rendered_page_number); |
243 } | 237 } |
244 #endif // defined(OS_WIN) | 238 #endif // defined(OS_WIN) |
245 } | 239 } |
246 | 240 |
OLD | NEW |