| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace shell { | 34 namespace shell { |
| 35 class InterfaceProvider; | 35 class InterfaceProvider; |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace content { | 38 namespace content { |
| 39 | 39 |
| 40 class BrowserChildProcessHostIterator; | 40 class BrowserChildProcessHostIterator; |
| 41 class BrowserChildProcessObserver; | 41 class BrowserChildProcessObserver; |
| 42 class BrowserMessageFilter; | 42 class BrowserMessageFilter; |
| 43 class MojoChildConnection; |
| 43 | 44 |
| 44 // Plugins/workers and other child processes that live on the IO thread use this | 45 // Plugins/workers and other child processes that live on the IO thread use this |
| 45 // class. RenderProcessHostImpl is the main exception that doesn't use this | 46 // class. RenderProcessHostImpl is the main exception that doesn't use this |
| 46 /// class because it lives on the UI thread. | 47 /// class because it lives on the UI thread. |
| 47 class CONTENT_EXPORT BrowserChildProcessHostImpl | 48 class CONTENT_EXPORT BrowserChildProcessHostImpl |
| 48 : public BrowserChildProcessHost, | 49 : public BrowserChildProcessHost, |
| 49 public NON_EXPORTED_BASE(ChildProcessHostDelegate), | 50 public NON_EXPORTED_BASE(ChildProcessHostDelegate), |
| 50 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 51 public base::win::ObjectWatcher::Delegate, | 52 public base::win::ObjectWatcher::Delegate, |
| 52 #endif | 53 #endif |
| 53 public ChildProcessLauncher::Client { | 54 public ChildProcessLauncher::Client { |
| 54 public: | 55 public: |
| 55 BrowserChildProcessHostImpl(content::ProcessType process_type, | 56 BrowserChildProcessHostImpl(content::ProcessType process_type, |
| 56 BrowserChildProcessHostDelegate* delegate, | 57 BrowserChildProcessHostDelegate* delegate, |
| 57 const std::string& mojo_child_token); | 58 const std::string& service_name); |
| 58 ~BrowserChildProcessHostImpl() override; | 59 ~BrowserChildProcessHostImpl() override; |
| 59 | 60 |
| 60 // Terminates all child processes and deletes each BrowserChildProcessHost | 61 // Terminates all child processes and deletes each BrowserChildProcessHost |
| 61 // instance. | 62 // instance. |
| 62 static void TerminateAll(); | 63 static void TerminateAll(); |
| 63 | 64 |
| 64 // Copies kEnableFeatures and kDisableFeatures to the command line. Generates | 65 // Copies kEnableFeatures and kDisableFeatures to the command line. Generates |
| 65 // them from the FeatureList override state, to take into account overrides | 66 // them from the FeatureList override state, to take into account overrides |
| 66 // from FieldTrials. | 67 // from FieldTrials. |
| 67 static void CopyFeatureAndFieldTrialFlags(base::CommandLine* cmd_line); | 68 static void CopyFeatureAndFieldTrialFlags(base::CommandLine* cmd_line); |
| 68 | 69 |
| 69 // BrowserChildProcessHost implementation: | 70 // BrowserChildProcessHost implementation: |
| 70 bool Send(IPC::Message* message) override; | 71 bool Send(IPC::Message* message) override; |
| 71 void Launch(SandboxedProcessLauncherDelegate* delegate, | 72 void Launch(SandboxedProcessLauncherDelegate* delegate, |
| 72 base::CommandLine* cmd_line, | 73 base::CommandLine* cmd_line, |
| 73 bool terminate_on_shutdown) override; | 74 bool terminate_on_shutdown) override; |
| 74 const ChildProcessData& GetData() const override; | 75 const ChildProcessData& GetData() const override; |
| 75 ChildProcessHost* GetHost() const override; | 76 ChildProcessHost* GetHost() const override; |
| 76 base::TerminationStatus GetTerminationStatus(bool known_dead, | 77 base::TerminationStatus GetTerminationStatus(bool known_dead, |
| 77 int* exit_code) override; | 78 int* exit_code) override; |
| 78 void SetName(const base::string16& name) override; | 79 void SetName(const base::string16& name) override; |
| 79 void SetHandle(base::ProcessHandle handle) override; | 80 void SetHandle(base::ProcessHandle handle) override; |
| 80 shell::InterfaceProvider* GetRemoteInterfaces() override; | |
| 81 | 81 |
| 82 // ChildProcessHostDelegate implementation: | 82 // ChildProcessHostDelegate implementation: |
| 83 bool CanShutdown() override; | 83 bool CanShutdown() override; |
| 84 void OnChildDisconnected() override; | 84 void OnChildDisconnected() override; |
| 85 const base::Process& GetProcess() const override; | 85 const base::Process& GetProcess() const override; |
| 86 shell::InterfaceProvider* GetRemoteInterfaces() override; |
| 86 bool OnMessageReceived(const IPC::Message& message) override; | 87 bool OnMessageReceived(const IPC::Message& message) override; |
| 87 void OnChannelConnected(int32_t peer_pid) override; | 88 void OnChannelConnected(int32_t peer_pid) override; |
| 88 void OnChannelError() override; | 89 void OnChannelError() override; |
| 89 void OnBadMessageReceived(const IPC::Message& message) override; | 90 void OnBadMessageReceived(const IPC::Message& message) override; |
| 90 | 91 |
| 91 // Terminates the process and logs an error after a bad message was received | 92 // Terminates the process and logs an error after a bad message was received |
| 92 // from the child process. | 93 // from the child process. |
| 93 void TerminateOnBadMessageReceived(uint32_t type); | 94 void TerminateOnBadMessageReceived(uint32_t type); |
| 94 | 95 |
| 95 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown | 96 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown |
| 96 void ForceShutdown(); | 97 void ForceShutdown(); |
| 97 | 98 |
| 98 // Callers can reduce the BrowserChildProcess' priority. | 99 // Callers can reduce the BrowserChildProcess' priority. |
| 99 void SetBackgrounded(bool backgrounded); | 100 void SetBackgrounded(bool backgrounded); |
| 100 | 101 |
| 101 // Adds an IPC message filter. | 102 // Adds an IPC message filter. |
| 102 void AddFilter(BrowserMessageFilter* filter); | 103 void AddFilter(BrowserMessageFilter* filter); |
| 103 | 104 |
| 104 static void HistogramBadMessageTerminated(int process_type); | 105 static void HistogramBadMessageTerminated(int process_type); |
| 105 | 106 |
| 106 BrowserChildProcessHostDelegate* delegate() const { return delegate_; } | 107 BrowserChildProcessHostDelegate* delegate() const { return delegate_; } |
| 107 | 108 |
| 109 MojoChildConnection* child_connection() const { |
| 110 return child_connection_.get(); |
| 111 } |
| 112 |
| 108 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList; | 113 typedef std::list<BrowserChildProcessHostImpl*> BrowserChildProcessList; |
| 109 private: | 114 private: |
| 110 friend class BrowserChildProcessHostIterator; | 115 friend class BrowserChildProcessHostIterator; |
| 111 friend class BrowserChildProcessObserver; | 116 friend class BrowserChildProcessObserver; |
| 112 | 117 |
| 113 static BrowserChildProcessList* GetIterator(); | 118 static BrowserChildProcessList* GetIterator(); |
| 114 | 119 |
| 115 static void AddObserver(BrowserChildProcessObserver* observer); | 120 static void AddObserver(BrowserChildProcessObserver* observer); |
| 116 static void RemoveObserver(BrowserChildProcessObserver* observer); | 121 static void RemoveObserver(BrowserChildProcessObserver* observer); |
| 117 | 122 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 129 const std::string& error); | 134 const std::string& error); |
| 130 | 135 |
| 131 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 132 // ObjectWatcher::Delegate implementation. | 137 // ObjectWatcher::Delegate implementation. |
| 133 void OnObjectSignaled(HANDLE object) override; | 138 void OnObjectSignaled(HANDLE object) override; |
| 134 #endif | 139 #endif |
| 135 | 140 |
| 136 ChildProcessData data_; | 141 ChildProcessData data_; |
| 137 BrowserChildProcessHostDelegate* delegate_; | 142 BrowserChildProcessHostDelegate* delegate_; |
| 138 std::unique_ptr<ChildProcessHost> child_process_host_; | 143 std::unique_ptr<ChildProcessHost> child_process_host_; |
| 139 const std::string mojo_child_token_; | 144 |
| 145 const std::string child_token_; |
| 146 std::unique_ptr<MojoChildConnection> child_connection_; |
| 140 | 147 |
| 141 std::unique_ptr<ChildProcessLauncher> child_process_; | 148 std::unique_ptr<ChildProcessLauncher> child_process_; |
| 142 | 149 |
| 143 PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_; | 150 PowerMonitorMessageBroadcaster power_monitor_message_broadcaster_; |
| 144 | 151 |
| 145 #if defined(OS_WIN) | 152 #if defined(OS_WIN) |
| 146 // Watches to see if the child process exits before the IPC channel has | 153 // Watches to see if the child process exits before the IPC channel has |
| 147 // been connected. Thereafter, its exit is determined by an error on the | 154 // been connected. Thereafter, its exit is determined by an error on the |
| 148 // IPC channel. | 155 // IPC channel. |
| 149 base::win::ObjectWatcher early_exit_watcher_; | 156 base::win::ObjectWatcher early_exit_watcher_; |
| 150 #endif | 157 #endif |
| 151 | 158 |
| 152 bool is_channel_connected_; | 159 bool is_channel_connected_; |
| 153 bool notify_child_disconnected_; | 160 bool notify_child_disconnected_; |
| 154 | 161 |
| 155 base::WeakPtrFactory<BrowserChildProcessHostImpl> weak_factory_; | 162 base::WeakPtrFactory<BrowserChildProcessHostImpl> weak_factory_; |
| 156 }; | 163 }; |
| 157 | 164 |
| 158 } // namespace content | 165 } // namespace content |
| 159 | 166 |
| 160 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ | 167 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_IMPL_H_ |
| OLD | NEW |