Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ | 5 #ifndef CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ |
| 6 #define CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ | 6 #define CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| 11 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 12 #include <windows.h> | 12 #include <windows.h> |
| 13 #endif // defined(OS_WIN) | 13 #endif // defined(OS_WIN) |
| 14 | 14 |
| 15 #include <string> | |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 18 #include "base/file_path.h" | 19 #include "base/file_path.h" |
| 19 #include "base/ref_counted.h" | 20 #include "base/ref_counted.h" |
| 20 #include "base/task.h" | 21 #include "base/task.h" |
| 21 #include "ipc/ipc_channel.h" | 22 #include "ipc/ipc_channel.h" |
| 22 #include "chrome/service/service_child_process_host.h" | 23 #include "chrome/service/service_child_process_host.h" |
| 23 #include "printing/native_metafile.h" | 24 #include "printing/native_metafile.h" |
| 24 | 25 |
| 25 class CommandLine; | 26 class CommandLine; |
| 26 class ScopedTempDir; | 27 class ScopedTempDir; |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 class MessageLoopProxy; | 30 class MessageLoopProxy; |
| 30 } // namespace base | 31 } // namespace base |
| 31 | 32 |
| 32 namespace gfx { | 33 namespace gfx { |
| 33 class Rect; | 34 class Rect; |
| 34 } // namespace gfx | 35 } // namespace gfx |
| 35 | 36 |
| 36 namespace printing { | 37 namespace printing { |
| 37 struct PageRange; | 38 struct PageRange; |
| 39 struct PrinterCapsAndDefaults; | |
| 38 } // namespace printing | 40 } // namespace printing |
| 39 | 41 |
| 40 // Acts as the service-side host to a utility child process. A | 42 // Acts as the service-side host to a utility child process. A |
| 41 // utility process is a short-lived sandboxed process that is created to run | 43 // utility process is a short-lived sandboxed process that is created to run |
| 42 // a specific task. | 44 // a specific task. |
| 43 class ServiceUtilityProcessHost : public ServiceChildProcessHost { | 45 class ServiceUtilityProcessHost : public ServiceChildProcessHost { |
| 44 public: | 46 public: |
| 45 // Consumers of ServiceUtilityProcessHost must implement this interface to | 47 // Consumers of ServiceUtilityProcessHost must implement this interface to |
| 46 // get results back. All functions are called on the thread passed along | 48 // get results back. All functions are called on the thread passed along |
| 47 // to ServiceUtilityProcessHost. | 49 // to ServiceUtilityProcessHost. |
| 48 class Client : public base::RefCountedThreadSafe<Client> { | 50 class Client : public base::RefCountedThreadSafe<Client> { |
| 49 public: | 51 public: |
| 50 Client() {} | 52 Client() {} |
| 51 | 53 |
| 52 // Called when the child process died before a reply was receieved. | 54 // Called when the child process died before a reply was receieved. |
| 53 virtual void OnChildDied() {} | 55 virtual void OnChildDied() {} |
| 54 | 56 |
| 55 // Called when at least one page in the specified PDF has been rendered | 57 // Called when at least one page in the specified PDF has been rendered |
| 56 // successfully into |metafile|. | 58 // successfully into |metafile|. |
| 57 virtual void OnRenderPDFPagesToMetafileSucceeded( | 59 virtual void OnRenderPDFPagesToMetafileSucceeded( |
| 58 const printing::NativeMetafile& metafile, | 60 const printing::NativeMetafile& metafile, |
| 59 int highest_rendered_page_number) {} | 61 int highest_rendered_page_number) {} |
| 60 // Called when no page in the passed in PDF could be rendered. | 62 // Called when no page in the passed in PDF could be rendered. |
| 61 virtual void OnRenderPDFPagesToMetafileFailed() {} | 63 virtual void OnRenderPDFPagesToMetafileFailed() {} |
| 62 | 64 |
| 65 // Called when the printer capabilities and defaults have been | |
| 66 // retrieved successfully. | |
| 67 virtual void OnGetPrinterCapsAndDefaultsSucceeded( | |
| 68 const std::string& printer_name, | |
| 69 const printing::PrinterCapsAndDefaults& caps_and_defaults) {} | |
| 70 | |
| 71 // Called when the printer capabilities and defaults could not be | |
| 72 // retrieved successfully. | |
| 73 virtual void OnGetPrinterCapsAndDefaultsFailed( | |
| 74 const std::string& printer_name) {} | |
| 75 | |
| 63 protected: | 76 protected: |
| 64 virtual ~Client() {} | 77 virtual ~Client() {} |
| 65 | 78 |
| 66 private: | 79 private: |
| 67 friend class base::RefCountedThreadSafe<Client>; | 80 friend class base::RefCountedThreadSafe<Client>; |
| 68 friend class ServiceUtilityProcessHost; | 81 friend class ServiceUtilityProcessHost; |
| 69 | 82 |
| 70 void OnMessageReceived(const IPC::Message& message); | 83 void OnMessageReceived(const IPC::Message& message); |
| 71 // Invoked when a metafile file is ready. | 84 // Invoked when a metafile file is ready. |
| 72 void MetafileAvailable(const FilePath& metafile_path, | 85 void MetafileAvailable(const FilePath& metafile_path, |
| 73 int highest_rendered_page_number); | 86 int highest_rendered_page_number); |
| 74 | 87 |
| 75 DISALLOW_COPY_AND_ASSIGN(Client); | 88 DISALLOW_COPY_AND_ASSIGN(Client); |
| 76 }; | 89 }; |
| 77 | 90 |
| 78 ServiceUtilityProcessHost(Client* client, | 91 ServiceUtilityProcessHost(Client* client, |
| 79 base::MessageLoopProxy* client_message_loop_proxy); | 92 base::MessageLoopProxy* client_message_loop_proxy); |
| 80 virtual ~ServiceUtilityProcessHost(); | 93 virtual ~ServiceUtilityProcessHost(); |
| 81 | 94 |
| 82 // Starts a process to render the specified pages in the given PDF file into | 95 // Starts a process to render the specified pages in the given PDF file into |
| 83 // a metafile. Currently only implemented for Windows. If the PDF has fewer | 96 // a metafile. Currently only implemented for Windows. If the PDF has fewer |
| 84 // pages than the specified page ranges, it will render as many as available. | 97 // pages than the specified page ranges, it will render as many as available. |
| 85 bool StartRenderPDFPagesToMetafile( | 98 bool StartRenderPDFPagesToMetafile( |
| 86 const FilePath& pdf_path, | 99 const FilePath& pdf_path, |
| 87 const gfx::Rect& render_area, | 100 const gfx::Rect& render_area, |
| 88 int render_dpi, | 101 int render_dpi, |
| 89 const std::vector<printing::PageRange>& page_ranges); | 102 const std::vector<printing::PageRange>& page_ranges); |
| 90 | 103 |
| 104 // Starta a process to get capabilities and defaults for the specified | |
|
Scott Byer
2010/12/20 21:02:29
nit: spelling
sanjeevr
2010/12/21 21:28:45
Done.
| |
| 105 // printer. Used on Windows to isolate the service process from printer driver | |
| 106 // crashes by executing this in a separate process. The process does not run | |
| 107 // in a sandbox. | |
| 108 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); | |
| 109 | |
| 91 protected: | 110 protected: |
| 92 // Allows this method to be overridden for tests. | 111 // Allows this method to be overridden for tests. |
| 93 virtual FilePath GetUtilityProcessCmd(); | 112 virtual FilePath GetUtilityProcessCmd(); |
| 94 | 113 |
| 95 // Overriden from ChildProcessHost. | 114 // Overriden from ChildProcessHost. |
| 96 virtual bool CanShutdown(); | 115 virtual bool CanShutdown(); |
| 97 virtual void OnChildDied(); | 116 virtual void OnChildDied(); |
| 98 | 117 |
| 99 private: | 118 private: |
| 100 // Starts a process. Returns true iff it succeeded. | 119 // Starts a process. Returns true iff it succeeded. |
| 101 bool StartProcess(const FilePath& exposed_dir); | 120 bool StartProcess(bool no_sandbox, const FilePath& exposed_dir); |
| 102 | 121 |
| 103 // IPC messages: | 122 // IPC messages: |
| 104 virtual void OnMessageReceived(const IPC::Message& message); | 123 virtual void OnMessageReceived(const IPC::Message& message); |
| 105 // Called when at least one page in the specified PDF has been rendered | 124 // Called when at least one page in the specified PDF has been rendered |
| 106 // successfully into metafile_path_; | 125 // successfully into metafile_path_; |
| 107 void OnRenderPDFPagesToMetafileSucceeded(int highest_rendered_page_number); | 126 void OnRenderPDFPagesToMetafileSucceeded(int highest_rendered_page_number); |
| 108 // Any other messages to be handled by the client. | 127 // Any other messages to be handled by the client. |
| 109 bool MessageForClient(const IPC::Message& message); | 128 bool MessageForClient(const IPC::Message& message); |
| 110 | 129 |
| 111 #if defined(OS_WIN) // This hack is Windows-specific. | 130 #if defined(OS_WIN) // This hack is Windows-specific. |
| 112 void OnPreCacheFont(LOGFONT font); | 131 void OnPreCacheFont(LOGFONT font); |
| 113 #endif // defined(OS_WIN) | 132 #endif // defined(OS_WIN) |
| 114 | 133 |
| 115 // A pointer to our client interface, who will be informed of progress. | 134 // A pointer to our client interface, who will be informed of progress. |
| 116 scoped_refptr<Client> client_; | 135 scoped_refptr<Client> client_; |
| 117 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_; | 136 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_; |
| 118 bool waiting_for_reply_; | 137 bool waiting_for_reply_; |
| 119 // The path to the temp file where the metafile will be written to. | 138 // The path to the temp file where the metafile will be written to. |
| 120 FilePath metafile_path_; | 139 FilePath metafile_path_; |
| 121 // The temporary folder created for the metafile. | 140 // The temporary folder created for the metafile. |
| 122 scoped_ptr<ScopedTempDir> scratch_metafile_dir_; | 141 scoped_ptr<ScopedTempDir> scratch_metafile_dir_; |
| 123 | 142 |
| 124 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); | 143 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); |
| 125 }; | 144 }; |
| 126 | 145 |
| 127 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ | 146 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ |
| OLD | NEW |