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