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

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 03:22:54 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"
11 #include "base/memory/weak_ptr.h"
16 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
17 #include "base/process/process.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 successfully.
59 double scale_factor) {} 56 virtual void OnRenderPDFPagesToMetafileSucceeded() {}
60 // Called when no page in the passed in PDF could be rendered. 57 // Called when at least one page in PDF could be rendered.
61 virtual void OnRenderPDFPagesToMetafileFailed() {} 58 virtual void OnRenderPDFPagesToMetafileFailed() {}
62 59
63 // Called when the printer capabilities and defaults have been 60 // Called when the printer capabilities and defaults have been
64 // retrieved successfully or if retrieval failed. 61 // retrieved successfully or if retrieval failed.
65 virtual void OnGetPrinterCapsAndDefaults( 62 virtual void OnGetPrinterCapsAndDefaults(
66 bool succedded, 63 bool succedded,
67 const std::string& printer_name, 64 const std::string& printer_name,
68 const printing::PrinterCapsAndDefaults& caps_and_defaults) {} 65 const printing::PrinterCapsAndDefaults& caps_and_defaults) {}
69 66
70 // Called when the printer capabilities and defaults have been 67 // Called when the printer capabilities and defaults have been
71 // retrieved successfully or if retrieval failed. 68 // retrieved successfully or if retrieval failed.
72 virtual void OnGetPrinterSemanticCapsAndDefaults( 69 virtual void OnGetPrinterSemanticCapsAndDefaults(
73 bool succedded, 70 bool succedded,
74 const std::string& printer_name, 71 const std::string& printer_name,
75 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {} 72 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {}
76 73
77 protected: 74 protected:
78 virtual ~Client() {} 75 virtual ~Client() {}
79 76
80 private: 77 private:
81 friend class base::RefCountedThreadSafe<Client>; 78 friend class base::RefCountedThreadSafe<Client>;
82 friend class ServiceUtilityProcessHost; 79 friend class ServiceUtilityProcessHost;
83 80
84 // Invoked when a metafile file is ready. 81 // Invoked when a metafile file is ready.
85 void MetafileAvailable(const base::FilePath& metafile_path, 82 void MetafileAvailable(double scale_factor, base::File file);
86 int highest_rendered_page_number,
87 double scale_factor);
88 83
89 DISALLOW_COPY_AND_ASSIGN(Client); 84 DISALLOW_COPY_AND_ASSIGN(Client);
90 }; 85 };
91 86
92 ServiceUtilityProcessHost(Client* client, 87 ServiceUtilityProcessHost(Client* client,
93 base::MessageLoopProxy* client_message_loop_proxy); 88 base::MessageLoopProxy* client_message_loop_proxy);
94 virtual ~ServiceUtilityProcessHost(); 89 virtual ~ServiceUtilityProcessHost();
95 90
96 // Starts a process to render the specified pages in the given PDF file into 91 // 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 92 // 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. 93 // pages than the specified page ranges, it will render as many as available.
99 bool StartRenderPDFPagesToMetafile( 94 bool StartRenderPDFPagesToMetafile(
100 const base::FilePath& pdf_path, 95 const base::FilePath& pdf_path,
101 const printing::PdfRenderSettings& render_settings, 96 const printing::PdfRenderSettings& render_settings);
102 const std::vector<printing::PageRange>& page_ranges);
103 97
104 // Starts a process to get capabilities and defaults for the specified 98 // Starts a process to get capabilities and defaults for the specified
105 // printer. Used on Windows to isolate the service process from printer driver 99 // 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 100 // crashes by executing this in a separate process. The process does not run
107 // in a sandbox. 101 // in a sandbox.
108 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); 102 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name);
109 103
110 // Starts a process to get capabilities and defaults for the specified 104 // Starts a process to get capabilities and defaults for the specified
111 // printer. Used on Windows to isolate the service process from printer driver 105 // 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 106 // crashes by executing this in a separate process. The process does not run
113 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults. 107 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
114 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name); 108 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
115 109
110 bool Send(IPC::Message* msg);
111
116 protected: 112 protected:
117 // Allows this method to be overridden for tests. 113 // Allows this method to be overridden for tests.
118 virtual base::FilePath GetUtilityProcessCmd(); 114 virtual base::FilePath GetUtilityProcessCmd();
119 115
120 // ChildProcessHostDelegate implementation: 116 // ChildProcessHostDelegate implementation:
121 virtual void OnChildDisconnected() OVERRIDE; 117 virtual void OnChildDisconnected() OVERRIDE;
122 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 118 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
123 virtual base::ProcessHandle GetHandle() const OVERRIDE; 119 virtual base::ProcessHandle GetHandle() const OVERRIDE;
124 120
125 private: 121 private:
126 // Starts a process. Returns true iff it succeeded. |exposed_dir| is the 122 // Starts a process. Returns true iff it succeeded.
127 // path to the exposed to the sandbox. This is ignored if |no_sandbox| is 123 bool StartProcess(bool no_sandbox);
128 // true.
129 bool StartProcess(bool no_sandbox, const base::FilePath& exposed_dir);
130 124
131 // Launch the child process synchronously. 125 // Launch the child process synchronously.
132 // TODO(sanjeevr): Determine whether we need to make the launch asynchronous. 126 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 127
139 base::ProcessHandle handle() const { return handle_; } 128 base::ProcessHandle handle() const { return handle_; }
140 129
130 void OnMetafileSpooled();
131 /*void ReplayCreateFileIfReady();
Lei Zhang 2014/09/15 21:49:53 dead code? (and in .cc file)
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 As I wrote before this part is not updated from pa
132 void FailReplyOnCreate();*/
133
141 // Messages handlers: 134 // Messages handlers:
142 void OnRenderPDFPagesToMetafilesSucceeded( 135 void OnRenderPDFPagesToMetafilesPageCount(int page_count) {};
Lei Zhang 2014/09/15 21:49:53 Don't you need the page count so you know how many
Vitaly Buka (NO REVIEWS) 2014/09/15 22:33:50 ditto On 2014/09/15 21:49:53, Lei Zhang wrote:
143 const std::vector<printing::PageRange>& page_ranges, 136 void OnRenderPDFPagesToMetafilesPageDone(bool success, double scale_factor);
144 double scale_factor);
145 void OnRenderPDFPagesToMetafileFailed();
146 void OnGetPrinterCapsAndDefaultsSucceeded( 137 void OnGetPrinterCapsAndDefaultsSucceeded(
147 const std::string& printer_name, 138 const std::string& printer_name,
148 const printing::PrinterCapsAndDefaults& caps_and_defaults); 139 const printing::PrinterCapsAndDefaults& caps_and_defaults);
149 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name); 140 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
150 void OnGetPrinterSemanticCapsAndDefaultsSucceeded( 141 void OnGetPrinterSemanticCapsAndDefaultsSucceeded(
151 const std::string& printer_name, 142 const std::string& printer_name,
152 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults); 143 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults);
153 void OnGetPrinterSemanticCapsAndDefaultsFailed( 144 void OnGetPrinterSemanticCapsAndDefaultsFailed(
154 const std::string& printer_name); 145 const std::string& printer_name);
155 146
156 scoped_ptr<content::ChildProcessHost> child_process_host_; 147 scoped_ptr<content::ChildProcessHost> child_process_host_;
157 base::ProcessHandle handle_; 148 base::ProcessHandle handle_;
158 // A pointer to our client interface, who will be informed of progress. 149 // A pointer to our client interface, who will be informed of progress.
159 scoped_refptr<Client> client_; 150 scoped_refptr<Client> client_;
160 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_; 151 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_;
161 bool waiting_for_reply_; 152 bool waiting_for_reply_;
162 // The base path to the temp file where the metafile will be written to. 153
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. 154 // Start time of operation.
167 base::Time start_time_; 155 base::Time start_time_;
168 156
157 // Output file for current page converted by utility process.
158 base::File emf_file_;
159
160 // Delayed reply for on request for new output file by utility process.
161 // We want to delay conversion if client is not fast enough.
162 IPC::Message* create_file_reply_msg_;
163
164 // Number in-progress files sent to client.
165 int number_of_emf_in_progress_;
166
167 base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_;
168
169 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); 169 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
170 }; 170 };
171 171
172 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ 172 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698