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_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ 6 #define CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ 7 8 #include <string> 9 #include <vector> 10 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" 19 20 namespace base { 21 class SequencedTaskRunner; 22 class Thread; 23 } 24 25 namespace content { 26 class BrowserChildProcessHostImpl; 27 28 typedef base::Thread* (*UtilityMainThreadFactoryFunction)( 29 const std::string& id); 30 31 class CONTENT_EXPORT UtilityProcessHostImpl NON_EXPORTED_BASE(UtilityProcessHost)32 : public NON_EXPORTED_BASE(UtilityProcessHost), 33 public BrowserChildProcessHostDelegate { 34 public: 35 static void RegisterUtilityMainThreadFactory( 36 UtilityMainThreadFactoryFunction create); 37 38 UtilityProcessHostImpl(UtilityProcessHostClient* client, 39 base::SequencedTaskRunner* client_task_runner); 40 virtual ~UtilityProcessHostImpl(); 41 42 // UtilityProcessHost implementation: 43 virtual bool Send(IPC::Message* message) OVERRIDE; 44 virtual bool StartBatchMode() OVERRIDE; 45 virtual void EndBatchMode() OVERRIDE; 46 virtual void SetExposedDir(const base::FilePath& dir) OVERRIDE; 47 virtual void EnableMDns() OVERRIDE; 48 virtual void DisableSandbox() OVERRIDE; 49 #if defined(OS_WIN) 50 virtual void ElevatePrivileges() OVERRIDE; 51 #endif 52 virtual const ChildProcessData& GetData() OVERRIDE; 53 #if defined(OS_POSIX) 54 virtual void SetEnv(const base::EnvironmentMap& env) OVERRIDE; 55 #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; 66 virtual void OnProcessLaunchFailed() OVERRIDE; 67 virtual void OnProcessCrashed(int exit_code) OVERRIDE; 68 69 // A pointer to our client interface, who will be informed of progress. 70 scoped_refptr<UtilityProcessHostClient> client_; 71 scoped_refptr<base::SequencedTaskRunner> client_task_runner_; 72 // 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 76 base::FilePath exposed_dir_; 77 78 // Whether the utility process needs to perform presandbox initialization 79 // for mDNS. 80 bool is_mdns_enabled_; 81 82 // Whether to pass switches::kNoSandbox to the child. 83 bool no_sandbox_; 84 85 // Whether to launch the process with elevated privileges. 86 bool run_elevated_; 87 88 // Flags defined in ChildProcessHost with which to start the process. 89 int child_flags_; 90 91 base::EnvironmentMap env_; 92 93 bool started_; 94 95 scoped_ptr<BrowserChildProcessHostImpl> process_; 96 97 // Used in single-process mode instead of process_. 98 scoped_ptr<base::Thread> in_process_thread_; 99 100 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHostImpl); 101 }; 102 103 } // namespace content 104 105 #endif // CONTENT_BROWSER_UTILITY_PROCESS_HOST_IMPL_H_ 106