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

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

Issue 8774040: Don't make classes derive from ChildProcessHost, and instead have them use it through composition... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
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 #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 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/process.h"
17 #include "base/task.h" 19 #include "base/task.h"
18 #include "ipc/ipc_channel.h" 20 #include "ipc/ipc_channel.h"
19 #include "chrome/service/service_child_process_host.h" 21 #include "content/public/common/child_process_host_delegate.h"
20 #include "printing/pdf_render_settings.h" 22 #include "printing/pdf_render_settings.h"
21 23
24 class ChildProcessHost;
25 class CommandLine;
22 class ScopedTempDir; 26 class ScopedTempDir;
23 27
24 namespace base { 28 namespace base {
25 class MessageLoopProxy; 29 class MessageLoopProxy;
26 } // namespace base 30 } // namespace base
27 31
28 namespace printing { 32 namespace printing {
29 class Emf; 33 class Emf;
30 struct PageRange; 34 struct PageRange;
31 struct PrinterCapsAndDefaults; 35 struct PrinterCapsAndDefaults;
32 } // namespace printing 36 } // namespace printing
33 37
34 // Acts as the service-side host to a utility child process. A 38 // Acts as the service-side host to a utility child process. A
35 // utility process is a short-lived sandboxed process that is created to run 39 // utility process is a short-lived sandboxed process that is created to run
36 // a specific task. 40 // a specific task.
37 class ServiceUtilityProcessHost : public ServiceChildProcessHost { 41 class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
38 public: 42 public:
39 // Consumers of ServiceUtilityProcessHost must implement this interface to 43 // Consumers of ServiceUtilityProcessHost must implement this interface to
40 // get results back. All functions are called on the thread passed along 44 // get results back. All functions are called on the thread passed along
41 // to ServiceUtilityProcessHost. 45 // to ServiceUtilityProcessHost.
42 class Client : public base::RefCountedThreadSafe<Client> { 46 class Client : public base::RefCountedThreadSafe<Client> {
43 public: 47 public:
44 Client() {} 48 Client() {}
45 49
46 // Called when the child process died before a reply was receieved. 50 // Called when the child process died before a reply was receieved.
47 virtual void OnChildDied() {} 51 virtual void OnChildDied() {}
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Starts a process to get capabilities and defaults for the specified 98 // Starts a process to get capabilities and defaults for the specified
95 // 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
96 // 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
97 // in a sandbox. 101 // in a sandbox.
98 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name); 102 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name);
99 103
100 protected: 104 protected:
101 // Allows this method to be overridden for tests. 105 // Allows this method to be overridden for tests.
102 virtual FilePath GetUtilityProcessCmd(); 106 virtual FilePath GetUtilityProcessCmd();
103 107
104 // ChildProcessHost implementation. 108 // ChildProcessHostDelegate implementation:
105 virtual bool CanShutdown() OVERRIDE; 109 virtual bool CanShutdown() OVERRIDE;
106 virtual void OnChildDied() OVERRIDE; 110 virtual void OnChildDisconnected() OVERRIDE;
111 virtual void ShutdownStarted() OVERRIDE;
112 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
107 113
108 private: 114 private:
109 // Starts a process. Returns true iff it succeeded. |exposed_dir| is the 115 // Starts a process. Returns true iff it succeeded. |exposed_dir| is the
110 // path to the exposed to the sandbox. This is ignored if |no_sandbox| is 116 // path to the exposed to the sandbox. This is ignored if |no_sandbox| is
111 // true. 117 // true.
112 bool StartProcess(bool no_sandbox, const FilePath& exposed_dir); 118 bool StartProcess(bool no_sandbox, const FilePath& exposed_dir);
113 119
114 // IPC messages: 120 // Launch the child process synchronously.
115 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 121 // TODO(sanjeevr): Determine whether we need to make the launch asynchronous.
116 // Called when at least one page in the specified PDF has been rendered 122 // |exposed_dir| is the path to tbe exposed to the sandbox. This is ignored
117 // successfully into metafile_path_; 123 // if |no_sandbox| is true.
124 bool Launch(CommandLine* cmd_line,
125 bool no_sandbox,
126 const FilePath& exposed_dir);
127
128 base::ProcessHandle handle() const { return handle_; }
129
130 // Messages handlers:
118 void OnRenderPDFPagesToMetafileSucceeded(int highest_rendered_page_number); 131 void OnRenderPDFPagesToMetafileSucceeded(int highest_rendered_page_number);
119 // Called when PDF rendering failed.
120 void OnRenderPDFPagesToMetafileFailed(); 132 void OnRenderPDFPagesToMetafileFailed();
121 // Called when the printer capabilities and defaults have been
122 // retrieved successfully.
123 void OnGetPrinterCapsAndDefaultsSucceeded( 133 void OnGetPrinterCapsAndDefaultsSucceeded(
124 const std::string& printer_name, 134 const std::string& printer_name,
125 const printing::PrinterCapsAndDefaults& caps_and_defaults); 135 const printing::PrinterCapsAndDefaults& caps_and_defaults);
126 // Called when the printer capabilities and defaults could not be
127 // retrieved successfully.
128 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name); 136 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
129 137
138 scoped_ptr<ChildProcessHost> child_process_host_;
139 base::ProcessHandle handle_;
130 // A pointer to our client interface, who will be informed of progress. 140 // A pointer to our client interface, who will be informed of progress.
131 scoped_refptr<Client> client_; 141 scoped_refptr<Client> client_;
132 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_; 142 scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy_;
133 bool waiting_for_reply_; 143 bool waiting_for_reply_;
134 // The path to the temp file where the metafile will be written to. 144 // The path to the temp file where the metafile will be written to.
135 FilePath metafile_path_; 145 FilePath metafile_path_;
136 // The temporary folder created for the metafile. 146 // The temporary folder created for the metafile.
137 scoped_ptr<ScopedTempDir> scratch_metafile_dir_; 147 scoped_ptr<ScopedTempDir> scratch_metafile_dir_;
138 148
139 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost); 149 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
140 }; 150 };
141 151
142 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_ 152 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698