Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / public / browser / utility_process_host.h
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/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"
13
14 namespace base {
15 class FilePath;
16 class SequencedTaskRunner;
17 }
18
19 namespace content {
20 class UtilityProcessHostClient;
21 struct ChildProcessData;
22
23 // This class acts as the browser-side host to a utility child process.  A
24 // utility process is a short-lived process that is created to run a specific
25 // task.  This class lives solely on the IO thread.
26 // If you need a single method call in the process, use StartFooBar(p).
27 // If you need multiple batches of work to be done in the process, use
28 // StartBatchMode(), then multiple calls to StartFooBar(p), then finish with
29 // EndBatchMode().
30 //
31 // Note: If your class keeps a ptr to an object of this type, grab a weak ptr to
32 // avoid a use after free since this object is deleted synchronously but the
33 // client notification is asynchronous.  See http://crbug.com/108871.
34 class UtilityProcessHost : public IPC::Sender,
35                            public base::SupportsWeakPtr<UtilityProcessHost> {
36  public:
37   // Used to create a utility process.
38   CONTENT_EXPORT static UtilityProcessHost* Create(
39       UtilityProcessHostClient* client,
40       base::SequencedTaskRunner* client_task_runner);
41
42   virtual ~UtilityProcessHost() {}
43
44   // Starts utility process in batch mode. Caller must call EndBatchMode()
45   // to finish the utility process.
46   virtual bool StartBatchMode() = 0;
47
48   // Ends the utility process. Must be called after StartBatchMode().
49   virtual void EndBatchMode() = 0;
50
51   // Allows a directory to be opened through the sandbox, in case it's needed by
52   // the operation.
53   virtual void SetExposedDir(const base::FilePath& dir) = 0;
54
55   // Perform presandbox initialization for mDNS.
56   virtual void EnableMDns() = 0;
57
58   // Make the process run without a sandbox.
59   virtual void DisableSandbox() = 0;
60
61 #if defined(OS_WIN)
62   // Make the process run elevated.
63   virtual void ElevatePrivileges() = 0;
64 #endif
65
66   // Returns information about the utility child process.
67   virtual const ChildProcessData& GetData() = 0;
68
69 #if defined(OS_POSIX)
70   virtual void SetEnv(const base::EnvironmentMap& env) = 0;
71 #endif
72 };
73
74 };  // namespace content
75
76 #endif  // CONTENT_PUBLIC_BROWSER_UTILITY_PROCESS_HOST_H_