utility_process_host.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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
5#ifndef CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
6#define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
7
8#include "base/process_util.h"
9#include "content/common/content_export.h"
10#include "ipc/ipc_sender.h"
11
12namespace base {
13class FilePath;
14class SequencedTaskRunner;
15}
16
17namespace content {
18class UtilityProcessHostClient;
19struct ChildProcessData;
20
21// This class acts as the browser-side host to a utility child process.  A
22// utility process is a short-lived process that is created to run a specific
23// task.  This class lives solely on the IO thread.
24// If you need a single method call in the process, use StartFooBar(p).
25// If you need multiple batches of work to be done in the process, use
26// StartBatchMode(), then multiple calls to StartFooBar(p), then finish with
27// EndBatchMode().
28//
29// Note: If your class keeps a ptr to an object of this type, grab a weak ptr to
30// avoid a use after free since this object is deleted synchronously but the
31// client notification is asynchronous.  See http://crbug.com/108871.
32class UtilityProcessHost : public IPC::Sender,
33                           public base::SupportsWeakPtr<UtilityProcessHost> {
34 public:
35  // Used to create a utility process.
36  CONTENT_EXPORT static UtilityProcessHost* Create(
37      UtilityProcessHostClient* client,
38      base::SequencedTaskRunner* client_task_runner);
39
40  virtual ~UtilityProcessHost() {}
41
42  // Starts utility process in batch mode. Caller must call EndBatchMode()
43  // to finish the utility process.
44  virtual bool StartBatchMode() = 0;
45
46  // Ends the utility process. Must be called after StartBatchMode().
47  virtual void EndBatchMode() = 0;
48
49  // Allows a directory to be opened through the sandbox, in case it's needed by
50  // the operation.
51  virtual void SetExposedDir(const base::FilePath& dir) = 0;
52
53  // Allows a mdns to use network in sandbox.
54  virtual void EnableMDns() = 0;
55
56  // Make the process run without a sandbox.
57  virtual void DisableSandbox() = 0;
58
59  // If the sandbox is being used and we are on Linux, launch the process from
60  // the zygote. Can only be used for tasks that do not require FS access.
61  virtual void EnableZygote() = 0;
62
63  // Returns information about the utility child process.
64  virtual const ChildProcessData& GetData() = 0;
65
66#if defined(OS_POSIX)
67  virtual void SetEnv(const base::EnvironmentVector& env) = 0;
68#endif
69};
70
71};  // namespace content
72
73#endif  // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
74