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_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
6 #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #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"
21 class SequencedTaskRunner
;
26 class BrowserChildProcessHostImpl
;
27 class InProcessChildThreadParams
;
28 class MojoApplicationHost
;
30 typedef base::Thread
* (*UtilityMainThreadFactoryFunction
)(
31 const InProcessChildThreadParams
&);
33 class CONTENT_EXPORT UtilityProcessHostImpl
34 : public NON_EXPORTED_BASE(UtilityProcessHost
),
35 public BrowserChildProcessHostDelegate
{
37 static void RegisterUtilityMainThreadFactory(
38 UtilityMainThreadFactoryFunction create
);
40 UtilityProcessHostImpl(
41 const scoped_refptr
<UtilityProcessHostClient
>& client
,
42 const scoped_refptr
<base::SequencedTaskRunner
>& client_task_runner
);
43 ~UtilityProcessHostImpl() override
;
45 // UtilityProcessHost implementation:
46 base::WeakPtr
<UtilityProcessHost
> AsWeakPtr() override
;
47 bool Send(IPC::Message
* message
) override
;
48 bool StartBatchMode() override
;
49 void EndBatchMode() override
;
50 void SetExposedDir(const base::FilePath
& dir
) override
;
51 void EnableMDns() override
;
52 void DisableSandbox() override
;
54 void ElevatePrivileges() override
;
56 const ChildProcessData
& GetData() override
;
58 void SetEnv(const base::EnvironmentMap
& env
) override
;
60 bool StartMojoMode() override
;
61 ServiceRegistry
* GetServiceRegistry() override
;
62 void SetName(const base::string16
& name
) override
;
64 void set_child_flags(int flags
) { child_flags_
= flags
; }
67 // Starts a process if necessary. Returns true if it succeeded or a process
68 // has already been started via StartBatchMode().
71 // BrowserChildProcessHost:
72 bool OnMessageReceived(const IPC::Message
& message
) override
;
73 void OnProcessLaunchFailed() override
;
74 void OnProcessCrashed(int exit_code
) override
;
75 void OnProcessLaunched() override
;
77 // A pointer to our client interface, who will be informed of progress.
78 scoped_refptr
<UtilityProcessHostClient
> client_
;
79 scoped_refptr
<base::SequencedTaskRunner
> client_task_runner_
;
80 // True when running in batch mode, i.e., StartBatchMode() has been called
81 // and the utility process will run until EndBatchMode().
84 base::FilePath exposed_dir_
;
86 // Whether the utility process needs to perform presandbox initialization
88 bool is_mdns_enabled_
;
90 // Whether to pass switches::kNoSandbox to the child.
93 // Whether to launch the process with elevated privileges.
96 // Flags defined in ChildProcessHost with which to start the process.
99 base::EnvironmentMap env_
;
103 // A user-visible name identifying this process. Used to indentify this
104 // process in the task manager.
105 base::string16 name_
;
107 scoped_ptr
<BrowserChildProcessHostImpl
> process_
;
109 // Used in single-process mode instead of process_.
110 scoped_ptr
<base::Thread
> in_process_thread_
;
112 // Browser-side Mojo endpoint which sets up a Mojo channel with the child
113 // process and contains the browser's ServiceRegistry.
114 scoped_ptr
<MojoApplicationHost
> mojo_application_host_
;
116 // Used to vend weak pointers, and should always be declared last.
117 base::WeakPtrFactory
<UtilityProcessHostImpl
> weak_ptr_factory_
;
119 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl
);
122 } // namespace content
124 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_