[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 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. | ||||
4 | |||||
[email protected] | a82af39 | 2012-02-24 04:40:20 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ |
6 | #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ | ||||
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
9 | #include <vector> | ||||
10 | |||||
11 | #include "base/basictypes.h" | ||||
12 | #include "base/compiler_specific.h" | ||||
13 | #include "base/memory/ref_counted.h" | ||||
[email protected] | b7b6387 | 2013-01-03 02:41:19 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
16 | #include "content/public/browser/browser_child_process_host_delegate.h" | ||||
17 | #include "content/public/browser/utility_process_host.h" | ||||
18 | |||||
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 19 | namespace base { |
20 | class SequencedTaskRunner; | ||||
21 | } | ||||
22 | |||||
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 23 | namespace content { |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 24 | class BrowserChildProcessHostImpl; |
25 | |||||
26 | class CONTENT_EXPORT UtilityProcessHostImpl | ||||
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 27 | : public NON_EXPORTED_BASE(UtilityProcessHost), |
28 | public BrowserChildProcessHostDelegate { | ||||
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 29 | public: |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 30 | UtilityProcessHostImpl(UtilityProcessHostClient* client, |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 31 | base::SequencedTaskRunner* client_task_runner); |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 32 | virtual ~UtilityProcessHostImpl(); |
33 | |||||
34 | // UtilityProcessHost implementation: | ||||
35 | virtual bool Send(IPC::Message* message) OVERRIDE; | ||||
36 | virtual bool StartBatchMode() OVERRIDE; | ||||
37 | virtual void EndBatchMode() OVERRIDE; | ||||
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 38 | virtual void SetExposedDir(const base::FilePath& dir) OVERRIDE; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 39 | virtual void DisableSandbox() OVERRIDE; |
40 | virtual void EnableZygote() OVERRIDE; | ||||
[email protected] | dc1571a15 | 2012-12-19 02:23:38 | [diff] [blame] | 41 | virtual const ChildProcessData& GetData() OVERRIDE; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 42 | #if defined(OS_POSIX) |
[email protected] | a82af39 | 2012-02-24 04:40:20 | [diff] [blame] | 43 | virtual void SetEnv(const base::EnvironmentVector& env) OVERRIDE; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 44 | #endif |
45 | |||||
46 | void set_child_flags(int flags) { child_flags_ = flags; } | ||||
47 | |||||
48 | private: | ||||
49 | // Starts a process if necessary. Returns true if it succeeded or a process | ||||
50 | // has already been started via StartBatchMode(). | ||||
51 | bool StartProcess(); | ||||
52 | |||||
53 | // BrowserChildProcessHost: | ||||
54 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | ||||
55 | virtual void OnProcessCrashed(int exit_code) OVERRIDE; | ||||
56 | |||||
57 | // A pointer to our client interface, who will be informed of progress. | ||||
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 58 | scoped_refptr<UtilityProcessHostClient> client_; |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 59 | scoped_refptr<base::SequencedTaskRunner> client_task_runner_; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 60 | // True when running in batch mode, i.e., StartBatchMode() has been called |
61 | // and the utility process will run until EndBatchMode(). | ||||
62 | bool is_batch_mode_; | ||||
63 | |||||
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 64 | base::FilePath exposed_dir_; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 65 | |
66 | // Whether to pass switches::kNoSandbox to the child. | ||||
67 | bool no_sandbox_; | ||||
68 | |||||
69 | // Flags defined in ChildProcessHost with which to start the process. | ||||
70 | int child_flags_; | ||||
71 | |||||
72 | // Launch the utility process from the zygote. Defaults to false. | ||||
73 | bool use_linux_zygote_; | ||||
74 | |||||
[email protected] | a82af39 | 2012-02-24 04:40:20 | [diff] [blame] | 75 | base::EnvironmentVector env_; |
[email protected] | c4f883a | 2012-02-03 17:02:07 | [diff] [blame] | 76 | |
77 | bool started_; | ||||
78 | |||||
79 | scoped_ptr<BrowserChildProcessHostImpl> process_; | ||||
80 | |||||
81 | DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl); | ||||
82 | }; | ||||
83 | |||||
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 84 | } // namespace content |
85 | |||||
[email protected] | a82af39 | 2012-02-24 04:40:20 | [diff] [blame] | 86 | #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ |