[Storage] Blob Storage Refactoring pt 1:
[chromium-blink-merge.git] / content / browser / utility_process_host_impl.h
blobc310e9b4bf0c200139ac587fc77bf41342ad8355
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;
28 typedef base::Thread* (*UtilityMainThreadFactoryFunction)(
29 const std::string& id);
31 class CONTENT_EXPORT UtilityProcessHostImpl
32 : public NON_EXPORTED_BASE(UtilityProcessHost),
33 public BrowserChildProcessHostDelegate {
34 public:
35 static void RegisterUtilityMainThreadFactory(
36 UtilityMainThreadFactoryFunction create);
38 UtilityProcessHostImpl(
39 const scoped_refptr<UtilityProcessHostClient>& client,
40 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner);
41 ~UtilityProcessHostImpl() override;
43 // UtilityProcessHost implementation:
44 bool Send(IPC::Message* message) override;
45 bool StartBatchMode() override;
46 void EndBatchMode() override;
47 void SetExposedDir(const base::FilePath& dir) override;
48 void EnableMDns() override;
49 void DisableSandbox() override;
50 #if defined(OS_WIN)
51 virtual void ElevatePrivileges() override;
52 #endif
53 const ChildProcessData& GetData() override;
54 #if defined(OS_POSIX)
55 void SetEnv(const base::EnvironmentMap& env) override;
56 #endif
58 void set_child_flags(int flags) { child_flags_ = flags; }
60 private:
61 // Starts a process if necessary. Returns true if it succeeded or a process
62 // has already been started via StartBatchMode().
63 bool StartProcess();
65 // BrowserChildProcessHost:
66 bool OnMessageReceived(const IPC::Message& message) override;
67 void OnProcessLaunchFailed() override;
68 void OnProcessCrashed(int exit_code) override;
70 // A pointer to our client interface, who will be informed of progress.
71 scoped_refptr<UtilityProcessHostClient> client_;
72 scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
73 // True when running in batch mode, i.e., StartBatchMode() has been called
74 // and the utility process will run until EndBatchMode().
75 bool is_batch_mode_;
77 base::FilePath exposed_dir_;
79 // Whether the utility process needs to perform presandbox initialization
80 // for mDNS.
81 bool is_mdns_enabled_;
83 // Whether to pass switches::kNoSandbox to the child.
84 bool no_sandbox_;
86 // Whether to launch the process with elevated privileges.
87 bool run_elevated_;
89 // Flags defined in ChildProcessHost with which to start the process.
90 int child_flags_;
92 base::EnvironmentMap env_;
94 bool started_;
96 scoped_ptr<BrowserChildProcessHostImpl> process_;
98 // Used in single-process mode instead of process_.
99 scoped_ptr<base::Thread> in_process_thread_;
101 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl);
104 } // namespace content
106 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_