OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "components/printing/common/printing.mojom.h" |
14 #include "content/public/common/child_process_host_delegate.h" | 15 #include "content/public/common/child_process_host_delegate.h" |
15 #include "ipc/ipc_platform_file.h" | 16 #include "ipc/ipc_platform_file.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class CommandLine; | 19 class CommandLine; |
19 class File; | 20 class File; |
20 class FilePath; | 21 class FilePath; |
21 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
22 } // namespace base | 23 } // namespace base |
23 | 24 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // in a sandbox. | 100 // in a sandbox. |
100 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); | 101 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); |
101 | 102 |
102 // Starts a process to get capabilities and defaults for the specified | 103 // Starts a process to get capabilities and defaults for the specified |
103 // printer. Used on Windows to isolate the service process from printer driver | 104 // printer. Used on Windows to isolate the service process from printer driver |
104 // crashes by executing this in a separate process. The process does not run | 105 // crashes by executing this in a separate process. The process does not run |
105 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults. | 106 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults. |
106 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); | 107 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); |
107 | 108 |
108 protected: | 109 protected: |
109 bool Send(IPC::Message* msg); | |
110 | |
111 // Allows this method to be overridden for tests. | 110 // Allows this method to be overridden for tests. |
112 virtual base::FilePath GetUtilityProcessCmd(); | 111 virtual base::FilePath GetUtilityProcessCmd(); |
113 | 112 |
114 // ChildProcessHostDelegate implementation: | 113 // ChildProcessHostDelegate implementation: |
115 void OnChildDisconnected() override; | 114 void OnChildDisconnected() override; |
116 bool OnMessageReceived(const IPC::Message& message) override; | 115 bool OnMessageReceived(const IPC::Message& message) override; |
117 const base::Process& GetProcess() const override; | 116 const base::Process& GetProcess() const override; |
118 | 117 |
119 private: | 118 private: |
120 // Starts a process. Returns true iff it succeeded. | 119 // Starts a process. Returns true iff it succeeded. |
121 bool StartProcess(bool no_sandbox); | 120 bool StartProcess(bool no_sandbox); |
122 | 121 |
123 // Launch the child process synchronously. | 122 // Launch the child process synchronously. |
124 bool Launch(base::CommandLine* cmd_line, bool no_sandbox); | 123 bool Launch(base::CommandLine* cmd_line, bool no_sandbox); |
125 | 124 |
126 base::ProcessHandle handle() const { return process_.Handle(); } | 125 base::ProcessHandle handle() const { return process_.Handle(); } |
127 | 126 |
128 void OnMetafileSpooled(bool success); | 127 void OnMetafileSpooled(bool success); |
129 void OnPDFToEmfFinished(bool success); | 128 void OnPDFToEmfFinished(bool success); |
130 | 129 |
131 // Messages handlers: | 130 // Messages handlers: |
132 void OnRenderPDFPagesToMetafilesPageCount(int page_count); | 131 void OnRenderPDFPagesToMetafilesPageCount(int page_count); |
133 void OnRenderPDFPagesToMetafilesPageDone(bool success, float scale_factor); | 132 void OnRenderPDFPagesToMetafilesPageDone(bool success, float scale_factor); |
134 void OnGetPrinterCapsAndDefaultsSucceeded( | 133 void OnGetPrinterCapsAndDefaults( |
135 const std::string& printer_name, | 134 const std::string& printer_name, |
136 const printing::PrinterCapsAndDefaults& caps_and_defaults); | 135 const base::Optional<printing::PrinterCapsAndDefaults>& |
137 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name); | 136 caps_and_defaults); |
138 void OnGetPrinterSemanticCapsAndDefaultsSucceeded( | 137 void OnGetPrinterSemanticCapsAndDefaults( |
139 const std::string& printer_name, | 138 const std::string& printer_name, |
140 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults); | 139 const base::Optional<printing::PrinterSemanticCapsAndDefaults>& |
141 void OnGetPrinterSemanticCapsAndDefaultsFailed( | 140 caps_and_defaults); |
142 const std::string& printer_name); | 141 |
| 142 printing::mojom::Printing* GetPrinting(); |
143 | 143 |
144 std::unique_ptr<content::ChildProcessHost> child_process_host_; | 144 std::unique_ptr<content::ChildProcessHost> child_process_host_; |
145 base::Process process_; | 145 base::Process process_; |
146 // A pointer to our client interface, who will be informed of progress. | 146 // A pointer to our client interface, who will be informed of progress. |
147 scoped_refptr<Client> client_; | 147 scoped_refptr<Client> client_; |
148 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; | 148 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_; |
149 bool waiting_for_reply_; | 149 bool waiting_for_reply_; |
150 const std::string mojo_child_token_; | 150 const std::string mojo_child_token_; |
151 | 151 |
152 // Start time of operation. | 152 // Start time of operation. |
153 base::Time start_time_; | 153 base::Time start_time_; |
154 | 154 |
155 class PdfToEmfState; | 155 class PdfToEmfState; |
156 std::unique_ptr<PdfToEmfState> pdf_to_emf_state_; | 156 std::unique_ptr<PdfToEmfState> pdf_to_emf_state_; |
157 | 157 |
| 158 printing::mojom::PrintingPtr printing_; |
| 159 |
158 base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_; | 160 base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_; |
159 | 161 |
160 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); | 162 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); |
161 }; | 163 }; |
162 | 164 |
163 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ | 165 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ |
OLD | NEW |