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/bind.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 "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
16 #include "content/common/child_process_info.h" | |
17 #include "ipc/ipc_switches.h" | 16 #include "ipc/ipc_switches.h" |
18 #include "printing/page_range.h" | 17 #include "printing/page_range.h" |
19 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
21 | 20 |
22 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
23 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
24 #include "base/win/scoped_handle.h" | 23 #include "base/win/scoped_handle.h" |
25 #include "content/common/child_process_messages.h" | |
26 #include "printing/emf_win.h" | 24 #include "printing/emf_win.h" |
27 #endif | 25 #endif |
28 | 26 |
29 ServiceUtilityProcessHost::ServiceUtilityProcessHost( | 27 ServiceUtilityProcessHost::ServiceUtilityProcessHost( |
30 Client* client, base::MessageLoopProxy* client_message_loop_proxy) | 28 Client* client, base::MessageLoopProxy* client_message_loop_proxy) |
31 : client_(client), | 29 : client_(client), |
32 client_message_loop_proxy_(client_message_loop_proxy), | 30 client_message_loop_proxy_(client_message_loop_proxy), |
33 waiting_for_reply_(false) { | 31 waiting_for_reply_(false) { |
34 process_id_ = ChildProcessInfo::GenerateChildProcessUniqueId(); | |
35 } | 32 } |
36 | 33 |
37 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { | 34 ServiceUtilityProcessHost::~ServiceUtilityProcessHost() { |
38 } | 35 } |
39 | 36 |
40 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( | 37 bool ServiceUtilityProcessHost::StartRenderPDFPagesToMetafile( |
41 const FilePath& pdf_path, | 38 const FilePath& pdf_path, |
42 const printing::PdfRenderSettings& render_settings, | 39 const printing::PdfRenderSettings& render_settings, |
43 const std::vector<printing::PageRange>& page_ranges) { | 40 const std::vector<printing::PageRange>& page_ranges) { |
44 #if !defined(OS_WIN) | 41 #if !defined(OS_WIN) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // If we are yet to receive a reply then notify the client that the | 127 // If we are yet to receive a reply then notify the client that the |
131 // child died. | 128 // child died. |
132 client_message_loop_proxy_->PostTask( | 129 client_message_loop_proxy_->PostTask( |
133 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); | 130 FROM_HERE, base::Bind(&Client::OnChildDied, client_.get())); |
134 } | 131 } |
135 // The base class implementation will delete |this|. | 132 // The base class implementation will delete |this|. |
136 ServiceChildProcessHost::OnChildDied(); | 133 ServiceChildProcessHost::OnChildDied(); |
137 } | 134 } |
138 | 135 |
139 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { | 136 bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) { |
140 bool msg_is_ok = false; | 137 bool handled = true; |
141 IPC_BEGIN_MESSAGE_MAP_EX(ServiceUtilityProcessHost, message, msg_is_ok) | 138 IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message) |
142 #if defined(OS_WIN) // This hack is Windows-specific. | |
143 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_PreCacheFont, OnPreCacheFont) | |
144 IPC_MESSAGE_HANDLER(ChildProcessHostMsg_ReleaseCachedFonts, | |
145 OnReleaseCachedFonts) | |
146 #endif | |
147 IPC_MESSAGE_HANDLER( | 139 IPC_MESSAGE_HANDLER( |
148 ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded, | 140 ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Succeeded, |
149 OnRenderPDFPagesToMetafileSucceeded) | 141 OnRenderPDFPagesToMetafileSucceeded) |
150 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed, | 142 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafile_Failed, |
151 OnRenderPDFPagesToMetafileFailed) | 143 OnRenderPDFPagesToMetafileFailed) |
152 IPC_MESSAGE_HANDLER( | 144 IPC_MESSAGE_HANDLER( |
153 ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded, | 145 ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded, |
154 OnGetPrinterCapsAndDefaultsSucceeded) | 146 OnGetPrinterCapsAndDefaultsSucceeded) |
155 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed, | 147 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed, |
156 OnGetPrinterCapsAndDefaultsFailed) | 148 OnGetPrinterCapsAndDefaultsFailed) |
157 IPC_MESSAGE_UNHANDLED(msg_is_ok__ = false) | 149 IPC_MESSAGE_UNHANDLED(handled = false) |
158 IPC_END_MESSAGE_MAP_EX() | 150 IPC_END_MESSAGE_MAP() |
159 return true; | 151 return handled; |
160 } | 152 } |
161 | 153 |
162 #if defined(OS_WIN) // This hack is Windows-specific. | |
163 void ServiceUtilityProcessHost::OnPreCacheFont(const LOGFONT& font) { | |
164 PreCacheFont(font, process_id_); | |
165 } | |
166 | |
167 void ServiceUtilityProcessHost::OnReleaseCachedFonts() { | |
168 ReleaseCachedFonts(process_id_); | |
169 } | |
170 #endif // OS_WIN | |
171 | |
172 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded( | 154 void ServiceUtilityProcessHost::OnRenderPDFPagesToMetafileSucceeded( |
173 int highest_rendered_page_number) { | 155 int highest_rendered_page_number) { |
174 DCHECK(waiting_for_reply_); | 156 DCHECK(waiting_for_reply_); |
175 waiting_for_reply_ = false; | 157 waiting_for_reply_ = false; |
176 // If the metafile was successfully created, we need to take our hands off the | 158 // If the metafile was successfully created, we need to take our hands off the |
177 // scratch metafile directory. The client will delete it when it is done with | 159 // scratch metafile directory. The client will delete it when it is done with |
178 // metafile. | 160 // metafile. |
179 scratch_metafile_dir_->Take(); | 161 scratch_metafile_dir_->Take(); |
180 client_message_loop_proxy_->PostTask( | 162 client_message_loop_proxy_->PostTask( |
181 FROM_HERE, | 163 FROM_HERE, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 printing::Emf metafile; | 209 printing::Emf metafile; |
228 if (!metafile.InitFromFile(metafile_path)) { | 210 if (!metafile.InitFromFile(metafile_path)) { |
229 OnRenderPDFPagesToMetafileFailed(); | 211 OnRenderPDFPagesToMetafileFailed(); |
230 } else { | 212 } else { |
231 OnRenderPDFPagesToMetafileSucceeded(metafile, | 213 OnRenderPDFPagesToMetafileSucceeded(metafile, |
232 highest_rendered_page_number); | 214 highest_rendered_page_number); |
233 } | 215 } |
234 #endif // defined(OS_WIN) | 216 #endif // defined(OS_WIN) |
235 } | 217 } |
236 | 218 |
OLD | NEW |