blob: 84866551a3bffc21991ee5882d47afc387ed9c6d [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"
[email protected]b345c482013-08-30 18:00:3913#include "base/files/file_path.h"
[email protected]c4f883a2012-02-03 17:02:0714#include "base/memory/ref_counted.h"
[email protected]b7b63872013-01-03 02:41:1915#include "base/memory/scoped_ptr.h"
[email protected]c4f883a2012-02-03 17:02:0716#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"
19
[email protected]7f8f24f2012-11-15 19:40:1420namespace base {
21class SequencedTaskRunner;
[email protected]d7a2d892013-08-16 07:45:3622class Thread;
[email protected]7f8f24f2012-11-15 19:40:1423}
24
[email protected]130757672012-10-24 00:26:1925namespace content {
[email protected]c4f883a2012-02-03 17:02:0726class BrowserChildProcessHostImpl;
[email protected]c4f883a2012-02-03 17:02:0727
[email protected]683f4272014-04-17 20:42:1828typedef base::Thread* (*UtilityMainThreadFactoryFunction)(
29 const std::string& id);
30
[email protected]c4f883a2012-02-03 17:02:0731class CONTENT_EXPORT UtilityProcessHostImpl
[email protected]130757672012-10-24 00:26:1932 : public NON_EXPORTED_BASE(UtilityProcessHost),
33 public BrowserChildProcessHostDelegate {
[email protected]c4f883a2012-02-03 17:02:0734 public:
[email protected]683f4272014-04-17 20:42:1835 static void RegisterUtilityMainThreadFactory(
36 UtilityMainThreadFactoryFunction create);
37
[email protected]130757672012-10-24 00:26:1938 UtilityProcessHostImpl(UtilityProcessHostClient* client,
[email protected]7f8f24f2012-11-15 19:40:1439 base::SequencedTaskRunner* client_task_runner);
[email protected]c4f883a2012-02-03 17:02:0740 virtual ~UtilityProcessHostImpl();
41
42 // UtilityProcessHost implementation:
43 virtual bool Send(IPC::Message* message) OVERRIDE;
44 virtual bool StartBatchMode() OVERRIDE;
45 virtual void EndBatchMode() OVERRIDE;
[email protected]2dec8ec2013-02-07 19:20:3446 virtual void SetExposedDir(const base::FilePath& dir) OVERRIDE;
[email protected]809d34b2013-07-20 11:51:5347 virtual void EnableMDns() OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0748 virtual void DisableSandbox() OVERRIDE;
[email protected]fa01e472014-02-11 14:45:3549#if defined(OS_WIN)
50 virtual void ElevatePrivileges() OVERRIDE;
51#endif
[email protected]dc1571a152012-12-19 02:23:3852 virtual const ChildProcessData& GetData() OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0753#if defined(OS_POSIX)
[email protected]b345c482013-08-30 18:00:3954 virtual void SetEnv(const base::EnvironmentMap& env) OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0755#endif
56
57 void set_child_flags(int flags) { child_flags_ = flags; }
58
59 private:
60 // Starts a process if necessary. Returns true if it succeeded or a process
61 // has already been started via StartBatchMode().
62 bool StartProcess();
63
64 // BrowserChildProcessHost:
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
[email protected]fa01e472014-02-11 14:45:3566 virtual void OnProcessLaunchFailed() OVERRIDE;
[email protected]c4f883a2012-02-03 17:02:0767 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
68
69 // A pointer to our client interface, who will be informed of progress.
[email protected]130757672012-10-24 00:26:1970 scoped_refptr<UtilityProcessHostClient> client_;
[email protected]7f8f24f2012-11-15 19:40:1471 scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
[email protected]c4f883a2012-02-03 17:02:0772 // True when running in batch mode, i.e., StartBatchMode() has been called
73 // and the utility process will run until EndBatchMode().
74 bool is_batch_mode_;
75
[email protected]2dec8ec2013-02-07 19:20:3476 base::FilePath exposed_dir_;
[email protected]c4f883a2012-02-03 17:02:0777
[email protected]dc120e72013-11-05 04:36:5178 // Whether the utility process needs to perform presandbox initialization
79 // for mDNS.
[email protected]809d34b2013-07-20 11:51:5380 bool is_mdns_enabled_;
81
[email protected]c4f883a2012-02-03 17:02:0782 // Whether to pass switches::kNoSandbox to the child.
83 bool no_sandbox_;
84
[email protected]fa01e472014-02-11 14:45:3585 // Whether to launch the process with elevated privileges.
86 bool run_elevated_;
[email protected]fa01e472014-02-11 14:45:3587
[email protected]c4f883a2012-02-03 17:02:0788 // Flags defined in ChildProcessHost with which to start the process.
89 int child_flags_;
90
[email protected]b345c482013-08-30 18:00:3991 base::EnvironmentMap env_;
[email protected]c4f883a2012-02-03 17:02:0792
93 bool started_;
94
95 scoped_ptr<BrowserChildProcessHostImpl> process_;
96
[email protected]6d057a0c2013-07-09 21:12:0797 // Used in single-process mode instead of process_.
[email protected]d7a2d892013-08-16 07:45:3698 scoped_ptr<base::Thread> in_process_thread_;
[email protected]6d057a0c2013-07-09 21:12:0799
[email protected]c4f883a2012-02-03 17:02:07100 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl);
101};
102
[email protected]130757672012-10-24 00:26:19103} // namespace content
104
[email protected]a82af392012-02-24 04:40:20105#endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_