Roll DEPS for PDFium to 19ae17578f99621100a26dac3e2c7c3dbf7c7cd1
[chromium-blink-merge.git] / content / browser / utility_process_host_impl.h
blobf988b8a96cdb756d1d0fbed4f9cca8b876f72971
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 CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
6 #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "content/public/browser/browser_child_process_host_delegate.h"
18 #include "content/public/browser/utility_process_host.h"
20 namespace base {
21 class SequencedTaskRunner;
22 class Thread;
25 namespace content {
26 class BrowserChildProcessHostImpl;
27 class InProcessChildThreadParams;
28 class MojoApplicationHost;
30 typedef base::Thread* (*UtilityMainThreadFactoryFunction)(
31 const InProcessChildThreadParams&);
33 class CONTENT_EXPORT UtilityProcessHostImpl
34 : public NON_EXPORTED_BASE(UtilityProcessHost),
35 public BrowserChildProcessHostDelegate {
36 public:
37 static void RegisterUtilityMainThreadFactory(
38 UtilityMainThreadFactoryFunction create);
40 UtilityProcessHostImpl(
41 const scoped_refptr<UtilityProcessHostClient>& client,
42 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner);
43 ~UtilityProcessHostImpl() override;
45 // UtilityProcessHost implementation:
46 bool Send(IPC::Message* message) override;
47 bool StartBatchMode() override;
48 void EndBatchMode() override;
49 void SetExposedDir(const base::FilePath& dir) override;
50 void EnableMDns() override;
51 void DisableSandbox() override;
52 #if defined(OS_WIN)
53 void ElevatePrivileges() override;
54 #endif
55 const ChildProcessData& GetData() override;
56 #if defined(OS_POSIX)
57 void SetEnv(const base::EnvironmentMap& env) override;
58 #endif
59 bool StartMojoMode() override;
60 ServiceRegistry* GetServiceRegistry() override;
61 void SetName(const base::string16& name) override;
63 void set_child_flags(int flags) { child_flags_ = flags; }
65 private:
66 // Starts a process if necessary. Returns true if it succeeded or a process
67 // has already been started via StartBatchMode().
68 bool StartProcess();
70 // BrowserChildProcessHost:
71 bool OnMessageReceived(const IPC::Message& message) override;
72 void OnProcessLaunchFailed() override;
73 void OnProcessCrashed(int exit_code) override;
74 void OnProcessLaunched() override;
76 // A pointer to our client interface, who will be informed of progress.
77 scoped_refptr<UtilityProcessHostClient> client_;
78 scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
79 // True when running in batch mode, i.e., StartBatchMode() has been called
80 // and the utility process will run until EndBatchMode().
81 bool is_batch_mode_;
83 base::FilePath exposed_dir_;
85 // Whether the utility process needs to perform presandbox initialization
86 // for mDNS.
87 bool is_mdns_enabled_;
89 // Whether to pass switches::kNoSandbox to the child.
90 bool no_sandbox_;
92 // Whether to launch the process with elevated privileges.
93 bool run_elevated_;
95 // Flags defined in ChildProcessHost with which to start the process.
96 int child_flags_;
98 base::EnvironmentMap env_;
100 bool started_;
102 // A user-visible name identifying this process. Used to indentify this
103 // process in the task manager.
104 base::string16 name_;
106 scoped_ptr<BrowserChildProcessHostImpl> process_;
108 // Used in single-process mode instead of process_.
109 scoped_ptr<base::Thread> in_process_thread_;
111 // Browser-side Mojo endpoint which sets up a Mojo channel with the child
112 // process and contains the browser's ServiceRegistry.
113 scoped_ptr<MojoApplicationHost> mojo_application_host_;
115 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl);
118 } // namespace content
120 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_