Gallery: remove default focus ring from selected item in thumbnail mode.
[chromium-blink-merge.git] / chrome / service / service_utility_process_host.h
blob18b561e9d26d835410808f7ba10ef8ed5c9ee513
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
3 // found in the LICENSE file.
5 #ifndef CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_
6 #define CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_
8 #include "build/build_config.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/common/child_process_host_delegate.h"
14 #include "ipc/ipc_platform_file.h"
16 namespace base {
17 class CommandLine;
18 class File;
19 class FilePath;
20 class ScopedTempDir;
21 } // namespace base
23 namespace content {
24 class ChildProcessHost;
27 namespace printing {
28 class MetafilePlayer;
29 class PdfRenderSettings;
30 struct PageRange;
31 struct PrinterCapsAndDefaults;
32 struct PrinterSemanticCapsAndDefaults;
33 } // namespace printing
35 // Acts as the service-side host to a utility child process. A
36 // utility process is a short-lived sandboxed process that is created to run
37 // a specific task.
38 class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
39 public:
40 // Consumers of ServiceUtilityProcessHost must implement this interface to
41 // get results back. All functions are called on the thread passed along
42 // to ServiceUtilityProcessHost.
43 class Client : public base::RefCountedThreadSafe<Client> {
44 public:
45 Client() {}
47 // Called when the child process died before a reply was receieved.
48 virtual void OnChildDied() {}
50 virtual void OnRenderPDFPagesToMetafilePageDone(
51 float scale_factor,
52 const printing::MetafilePlayer& emf) {}
54 // Called when at all pages in the PDF has been rendered.
55 virtual void OnRenderPDFPagesToMetafileDone(bool success) {}
57 // Called when the printer capabilities and defaults have been
58 // retrieved successfully or if retrieval failed.
59 virtual void OnGetPrinterCapsAndDefaults(
60 bool succedded,
61 const std::string& printer_name,
62 const printing::PrinterCapsAndDefaults& caps_and_defaults) {}
64 // Called when the printer capabilities and defaults have been
65 // retrieved successfully or if retrieval failed.
66 virtual void OnGetPrinterSemanticCapsAndDefaults(
67 bool succedded,
68 const std::string& printer_name,
69 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {}
71 protected:
72 virtual ~Client() {}
74 private:
75 friend class base::RefCountedThreadSafe<Client>;
76 friend class ServiceUtilityProcessHost;
78 // Invoked when a metafile file is ready.
79 // Returns true if metafile successfully loaded from |file|.
80 bool MetafileAvailable(float scale_factor, base::File file);
82 DISALLOW_COPY_AND_ASSIGN(Client);
85 ServiceUtilityProcessHost(Client* client,
86 base::SingleThreadTaskRunner* client_task_runner);
87 ~ServiceUtilityProcessHost() override;
89 // Starts a process to render the specified pages in the given PDF file into
90 // a metafile. Currently only implemented for Windows. If the PDF has fewer
91 // pages than the specified page ranges, it will render as many as available.
92 bool StartRenderPDFPagesToMetafile(
93 const base::FilePath& pdf_path,
94 const printing::PdfRenderSettings& render_settings);
96 // Starts a process to get capabilities and defaults for the specified
97 // printer. Used on Windows to isolate the service process from printer driver
98 // crashes by executing this in a separate process. The process does not run
99 // in a sandbox.
100 bool StartGetPrinterCapsAndDefaults(const std::string& printer_name);
102 // 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 // crashes by executing this in a separate process. The process does not run
105 // in a sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
106 bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
108 protected:
109 bool Send(IPC::Message* msg);
111 // Allows this method to be overridden for tests.
112 virtual base::FilePath GetUtilityProcessCmd();
114 // ChildProcessHostDelegate implementation:
115 void OnChildDisconnected() override;
116 bool OnMessageReceived(const IPC::Message& message) override;
117 const base::Process& GetProcess() const override;
119 private:
120 // Starts a process. Returns true iff it succeeded.
121 bool StartProcess(bool no_sandbox);
123 // Launch the child process synchronously.
124 bool Launch(base::CommandLine* cmd_line, bool no_sandbox);
126 base::ProcessHandle handle() const { return process_.Handle(); }
128 void OnMetafileSpooled(bool success);
129 void OnPDFToEmfFinished(bool success);
131 // Messages handlers:
132 void OnRenderPDFPagesToMetafilesPageCount(int page_count);
133 void OnRenderPDFPagesToMetafilesPageDone(bool success, float scale_factor);
134 void OnGetPrinterCapsAndDefaultsSucceeded(
135 const std::string& printer_name,
136 const printing::PrinterCapsAndDefaults& caps_and_defaults);
137 void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
138 void OnGetPrinterSemanticCapsAndDefaultsSucceeded(
139 const std::string& printer_name,
140 const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults);
141 void OnGetPrinterSemanticCapsAndDefaultsFailed(
142 const std::string& printer_name);
144 scoped_ptr<content::ChildProcessHost> child_process_host_;
145 base::Process process_;
146 // A pointer to our client interface, who will be informed of progress.
147 scoped_refptr<Client> client_;
148 scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_;
149 bool waiting_for_reply_;
151 // Start time of operation.
152 base::Time start_time_;
154 class PdfToEmfState;
155 scoped_ptr<PdfToEmfState> pdf_to_emf_state_;
157 base::WeakPtrFactory<ServiceUtilityProcessHost> weak_ptr_factory_;
159 DISALLOW_COPY_AND_ASSIGN(ServiceUtilityProcessHost);
162 #endif // CHROME_SERVICE_SERVICE_UTILITY_PROCESS_HOST_H_