Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / browser / utility_process_host.h
blob5fb2d1d97322342eccd8a445fda543d33bdfd0a8
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_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
6 #define CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_
8 #include "base/environment.h"
9 #include "base/process/launch.h"
10 #include "base/threading/thread.h"
11 #include "content/common/content_export.h"
12 #include "ipc/ipc_sender.h"
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
19 namespace content {
20 class ServiceRegistry;
21 class UtilityProcessHostClient;
22 struct ChildProcessData;
24 // This class acts as the browser-side host to a utility child process. A
25 // utility process is a short-lived process that is created to run a specific
26 // task. This class lives solely on the IO thread.
27 // If you need a single method call in the process, use StartFooBar(p).
28 // If you need multiple batches of work to be done in the process, use
29 // StartBatchMode(), then multiple calls to StartFooBar(p), then finish with
30 // EndBatchMode().
31 // If you need to call Mojo services, use StartMojoMode() to start the child
32 // process and GetServiceRegistry() to get the service registry to connect to
33 // the child's Mojo services.
35 // Note: If your class keeps a ptr to an object of this type, grab a weak ptr to
36 // avoid a use after free since this object is deleted synchronously but the
37 // client notification is asynchronous. See http://crbug.com/108871.
38 class UtilityProcessHost : public IPC::Sender {
39 public:
40 // Used to create a utility process. |client| is optional. If supplied it will
41 // be notified of incoming messages from the utility process.
42 // |client_task_runner| is required if |client| is supplied and is the task
43 // runner upon which |client| will be invoked.
44 CONTENT_EXPORT static UtilityProcessHost* Create(
45 const scoped_refptr<UtilityProcessHostClient>& client,
46 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner);
48 ~UtilityProcessHost() override {}
50 virtual base::WeakPtr<UtilityProcessHost> AsWeakPtr() = 0;
52 // Starts utility process in batch mode. Caller must call EndBatchMode()
53 // to finish the utility process.
54 virtual bool StartBatchMode() = 0;
56 // Ends the utility process. Must be called after StartBatchMode().
57 virtual void EndBatchMode() = 0;
59 // Allows a directory to be opened through the sandbox, in case it's needed by
60 // the operation.
61 virtual void SetExposedDir(const base::FilePath& dir) = 0;
63 // Perform presandbox initialization for mDNS.
64 virtual void EnableMDns() = 0;
66 // Make the process run without a sandbox.
67 virtual void DisableSandbox() = 0;
69 #if defined(OS_WIN)
70 // Make the process run elevated.
71 virtual void ElevatePrivileges() = 0;
72 #endif
74 // Returns information about the utility child process.
75 virtual const ChildProcessData& GetData() = 0;
77 #if defined(OS_POSIX)
78 virtual void SetEnv(const base::EnvironmentMap& env) = 0;
79 #endif
81 // Starts the utility process in Mojo mode.
82 virtual bool StartMojoMode() = 0;
84 // Returns the ServiceRegistry for this process. Will return nullptr if
85 // the process was not started with StartMojoMode().
86 virtual ServiceRegistry* GetServiceRegistry() = 0;
88 // Set the name of the process to appear in the task manager.
89 virtual void SetName(const base::string16& name) = 0;
92 }; // namespace content
94 #endif // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_