blob: 4c852584109164eeb490b077d19c0e269f574307 [file] [log] [blame]
[email protected]c4f883a2012-02-03 17:02:071// 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]a82af392012-02-24 04:40:205#ifndef CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
6#define CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
[email protected]c4f883a2012-02-03 17:02:077
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]b7b63872013-01-03 02:41:1914#include "base/memory/scoped_ptr.h"
[email protected]c4f883a2012-02-03 17:02:0715#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]7f8f24f2012-11-15 19:40:1419namespace base {
20class SequencedTaskRunner;
21}
22
[email protected]130757672012-10-24 00:26:1923namespace content {
[email protected]c4f883a2012-02-03 17:02:0724class BrowserChildProcessHostImpl;
25
26class CONTENT_EXPORT UtilityProcessHostImpl
[email protected]130757672012-10-24 00:26:1927 : public NON_EXPORTED_BASE(UtilityProcessHost),
28 public BrowserChildProcessHostDelegate {
[email protected]c4f883a2012-02-03 17:02:0729 public:
[email protected]130757672012-10-24 00:26:1930 UtilityProcessHostImpl(UtilityProcessHostClient* client,
[email protected]7f8f24f2012-11-15 19:40:1431 base::SequencedTaskRunner* client_task_runner);
[email protected]c4f883a2012-02-03 17:02:0732 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]2dec8ec2013-02-07 19:20:3438 virtual void SetExposedDir(const base::FilePath& dir) OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0739 virtual void DisableSandbox() OVERRIDE;
40 virtual void EnableZygote() OVERRIDE;
[email protected]dc1571a152012-12-19 02:23:3841 virtual const ChildProcessData& GetData() OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0742#if defined(OS_POSIX)
[email protected]a82af392012-02-24 04:40:2043 virtual void SetEnv(const base::EnvironmentVector& env) OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0744#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]130757672012-10-24 00:26:1958 scoped_refptr<UtilityProcessHostClient> client_;
[email protected]7f8f24f2012-11-15 19:40:1459 scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
[email protected]c4f883a2012-02-03 17:02:0760 // 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]2dec8ec2013-02-07 19:20:3464 base::FilePath exposed_dir_;
[email protected]c4f883a2012-02-03 17:02:0765
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]a82af392012-02-24 04:40:2075 base::EnvironmentVector env_;
[email protected]c4f883a2012-02-03 17:02:0776
77 bool started_;
78
79 scoped_ptr<BrowserChildProcessHostImpl> process_;
80
81 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl);
82};
83
[email protected]130757672012-10-24 00:26:1984} // namespace content
85
[email protected]a82af392012-02-24 04:40:2086#endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_