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

Side by Side Diff: chrome/service/service_utility_process_host.h

Issue 566693002: Use file handles to interact with utility process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mon Sep 15 18:19:41 PDT 2014 Created 6 years, 3 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
OLDNEW
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 "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <string>
11 #include <vector>
12
13 #include "base/basictypes.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
17 #include "base/process/process.h" 12 #include "base/memory/weak_ptr.h"
18 #include "content/public/common/child_process_host_delegate.h" 13 #include "content/public/common/child_process_host_delegate.h"
19 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_platform_file.h"
20 #include "printing/pdf_render_settings.h"
21 15
22 namespace base { 16 namespace base {
23 class CommandLine; 17 class CommandLine;
18 class File;
19 class FilePath;
24 class MessageLoopProxy; 20 class MessageLoopProxy;
25 class ScopedTempDir; 21 class ScopedTempDir;
26 } // namespace base 22 } // namespace base
27 23
28 namespace content { 24 namespace content {
29 class ChildProcessHost; 25 class ChildProcessHost;
30 } 26 }
31 27
32 namespace printing { 28 namespace printing {
33 class MetafilePlayer; 29 class MetafilePlayer;
30 class PdfRenderSettings;
34 struct PageRange; 31 struct PageRange;
35 struct PrinterCapsAndDefaults; 32 struct PrinterCapsAndDefaults;
36 struct PrinterSemanticCapsAndDefaults; 33 struct PrinterSemanticCapsAndDefaults;
37 } // namespace printing 34 } // namespace printing
38 35
39 // Acts as the service-side host to a utility child process. A 36 // Acts as the service-side host to a utility child process. A
40 // utility process is a short-lived sandboxed process that is created to run 37 // utility process is a short-lived sandboxed process that is created to run
41 // a specific task. 38 // a specific task.
42 class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate { 39 class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
43 public: 40 public:
44 // Consumers of ServiceUtilityProcessHost must implement this interface to 41 // Consumers of ServiceUtilityProcessHost must implement this interface to
45 // get results back. All functions are called on the thread passed along 42 // get results back. All functions are called on the thread passed along
46 // to ServiceUtilityProcessHost. 43 // to ServiceUtilityProcessHost.
47 class Client : public base::RefCountedThreadSafe<Client> { 44 class Client : public base::RefCountedThreadSafe<Client> {
48 public: 45 public:
49 Client() {} 46 Client() {}
50 47
51 // Called when the child process died before a reply was receieved. 48 // Called when the child process died before a reply was receieved.
52 virtual void OnChildDied() {} 49 virtual void OnChildDied() {}
53 50
54 // Called when at least one page in the specified PDF has been rendered 51 virtual void OnRenderPDFPagesToMetafilePageDone(
55 // successfully into |metafile|. 52 double scale_factor,
56 virtual void OnRenderPDFPagesToMetafileSucceeded( 53 const printing::MetafilePlayer& emf) {}
57 const printing::MetafilePlayer& metafile, 54
58 int highest_rendered_page_number, 55 // Called when at all pages in the PDF has been rendered.
59 double scale_factor) {} 56 virtual void OnRenderPDFPagesToMetafileDone(bool success) {}
60 // Called when no page in the passed in PDF could be rendered.
61 virtual void OnRenderPDFPagesToMetafileFailed() {}
62 57
63 // Called when the printer capabilities and defaults have been 58 // Called when the printer capabilities and defaults have been
64 // retrieved successfully or if retrieval failed. 59 // retrieved successfully or if retrieval failed.
65 virtual void OnGetPrinterCapsAndDefaults( 60 virtual void OnGetPrinterCapsAndDefaults(
66 bool succedded, 61 bool succedded,
67 const std::string& printer_name, 62 const std::string& printer_name,
68 const printing::PrinterCapsAndDefaults& caps_and_defaults) {} 63 const printing::PrinterCapsAndDefaults& caps_and_defaults) {}
69 64
70 // Called when the printer capabilities and defaults have been 65 // Called when the printer capabilities and defaults have been
71 // retrieved successfully or if retrieval failed. 66 // retrieved successfully or if retrieval failed.
72 virtual void OnGetPrinterSemanticCapsAndDefaults( 67 virtual void OnGetPrinterSemanticCapsAndDefaults(
73 bool succedded, 68 bool succedded,
74 const std::string& printer_name, 69 const std::string& printer_name,
75 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {} 70 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {}
76 71
77 protected: 72 protected:
78 virtual ~Client() {} 73 virtual ~Client() {}
79 74
80 private: 75 private:
81 friend class base::RefCountedThreadSafe<Client>; 76 friend class base::RefCountedThreadSafe<Client>;
82 friend class ServiceUtilityProcessHost; 77 friend class ServiceUtilityProcessHost;
83 78
84 // Invoked when a metafile file is ready. 79 // Invoked when a metafile file is ready.
85 void MetafileAvailable(const base::FilePath& metafile_path, 80 bool MetafileAvailable(double scale_factor, base::File file);
Lei Zhang 2014/09/16 03:36:55 What does this return?
Vitaly Buka (NO REVIEWS) 2014/09/16 07:50:36 Done.
86 int highest_rendered_page_number,
87 double scale_factor);
88 81
89 DISALLOW_COPY_AND_ASSIGN(Client); 82 DISALLOW_COPY_AND_ASSIGN(Client);
90 }; 83 };
91 84
92 ServiceUtilityProcessHost(Client* client, 85 ServiceUtilityProcessHost(Client* client,
93 base::MessageLoopProxy* client_message_loop_proxy); 86 base::MessageLoopProxy* client_message_loop_proxy);
94 virtual ~ServiceUtilityProcessHost(); 87 virtual ~ServiceUtilityProcessHost();
95 88
96 // Starts a process to render the specified pages in the given PDF file into 89 // Starts a process to render the specified pages in the given PDF file into
97 // a metafile. Currently only implemented for Windows. If the PDF has fewer 90 // a metafile. Currently only implemented for Windows. If the PDF has fewer
98 // pages than the specified page ranges, it will render as many as available. 91 // pages than the specified page ranges, it will render as many as available.
99 bool StartRenderPDFPagesToMetafile( 92 bool StartRenderPDFPagesToMetafile(
100 const base::FilePath& pdf_path, 93 const base::FilePath& pdf_path,
101 const printing::PdfRenderSettings& render_settings, 94 const printing::PdfRenderSettings& render_settings);
102 const std::vector<printing::PageRange>& page_ranges);
103 95
104 // Starts a process to get capabilities and defaults for the specified 96 // Starts a process to get capabilities and defaults for the specified
105 // printer. Used on Windows to isolate the service process from printer driver 97 // 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 98 // crashes by executing this in a separate process. The process does not run
107 // in a sandbox. 99 // in a sandbox.
108 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); 100 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name);
109 101
110 // Starts a process to get capabilities and defaults for the specified 102 // Starts a process to get capabilities and defaults for the specified
111 // printer. Used on Windows to isolate the service process from printer driver 103 // printer. Used on Windows to isolate the service process from printer driver
112 // crashes by executing this in a separate process. The process does not run 104 // crashes by executing this in a separate process. The process does not run
113 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults. 105 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
114 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); 106 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
115 107
108 bool Send(IPC::Message* msg);
109
116 protected: 110 protected:
117 // Allows this method to be overridden for tests. 111 // Allows this method to be overridden for tests.
118 virtual base::FilePath GetUtilityProcessCmd(); 112 virtual base::FilePath GetUtilityProcessCmd();
119 113
120 // ChildProcessHostDelegate implementation: 114 // ChildProcessHostDelegate implementation:
121 virtual void OnChildDisconnected() OVERRIDE; 115 virtual void OnChildDisconnected() OVERRIDE;
122 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 116 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
123 virtual base::ProcessHandle GetHandle() const OVERRIDE; 117 virtual base::ProcessHandle GetHandle() const OVERRIDE;
124 118
125 private: 119 private:
126 // Starts a process. Returns true iff it succeeded. |exposed_dir| is the 120 // Starts a process. Returns true iff it succeeded.
127 // path to the exposed to the sandbox. This is ignored if |no_sandbox| is 121 bool StartProcess(bool no_sandbox);
128 // true.
129 bool StartProcess(bool no_sandbox, const base::FilePath& exposed_dir);
130 122
131 // Launch the child process synchronously. 123 // Launch the child process synchronously.
132 // TODO(sanjeevr): Determine whether we need to make the launch asynchronous. 124 bool Launch(base::CommandLine* cmd_line, bool no_sandbox);
133 // |exposed_dir| is the path to tbe exposed to the sandbox. This is ignored
134 // if |no_sandbox| is true.
135 bool Launch(base::CommandLine* cmd_line,
136 bool no_sandbox,
137 const base::FilePath& exposed_dir);
138 125
139 base::ProcessHandle handle() const { return handle_; } 126 base::ProcessHandle handle() const { return handle_; }
140 127
128 void OnMetafileSpooled(bool success);
129 void OnPDFToEmfFinished(bool success);
130
141 // Messages handlers: 131 // Messages handlers:
142 void OnRenderPDFPagesToMetafilesSucceeded( 132 void OnRenderPDFPagesToMetafilesPageCount(int page_count);
143 const std::vector<printing::PageRange>& page_ranges, 133 void OnRenderPDFPagesToMetafilesPageDone(bool success, double scale_factor);
144 double scale_factor);
145 void OnRenderPDFPagesToMetafileFailed();
146 void OnGetPrinterCapsAndDefaultsSucceeded( 134 void OnGetPrinterCapsAndDefaultsSucceeded(
147 const std::string& printer_name, 135 const std::string& printer_name,
148 const printing::PrinterCapsAndDefaults& caps_and_defaults); 136 const printing::PrinterCapsAndDefaults& caps_and_defaults);
149 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name); 137 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
150 void OnGetPrinterSemanticCapsAndDefaultsSucceeded( 138 void OnGetPrinterSemanticCapsAndDefaultsSucceeded(
151 const std::string& printer_name, 139 const std::string& printer_name,
152 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults); 140 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults);
153 void OnGetPrinterSemanticCapsAndDefaultsFailed( 141 void OnGetPrinterSemanticCapsAndDefaultsFailed(
154 const std::string& printer_name); 142 const std::string& printer_name);
155 143
156 scoped_ptr<content::ChildProcessHost> child_process_host_; 144 scoped_ptr<content::ChildProcessHost> child_process_host_;
157 base::ProcessHandle handle_; 145 base::ProcessHandle handle_;
158 // 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.
159 scoped_refptr<Client> client_; 147 scoped_refptr<Client> client_;
160 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_; 148 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_;
161 bool waiting_for_reply_; 149 bool waiting_for_reply_;
162 // The base path to the temp file where the metafile will be written to. 150
163 base::FilePath metafile_path_;
164 // The temporary folder created for the metafile.
165 scoped_ptr<base::ScopedTempDir> scratch_metafile_dir_;
166 // Start time of operation. 151 // Start time of operation.
167 base::Time start_time_; 152 base::Time start_time_;
168 153
154 class PdfToEmfState;
155 scoped_ptr<PdfToEmfState> pdf_to_emf_state_;
156
157 base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_;
158
169 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); 159 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
170 }; 160 };
171 161
172 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ 162 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698