| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMMON_CHILD_PROCESS_HOST_H_ | 5 #ifndef CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| 6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 6 #define CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include <map> | 11 #include <map> |
| 12 | 12 |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 | 14 |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #endif // defined(OS_WIN) | 17 #endif // defined(OS_WIN) |
| 18 | 18 |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
| 22 #include "base/shared_memory.h" |
| 22 #include "base/string16.h" | 23 #include "base/string16.h" |
| 23 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
| 24 #include "content/common/content_notification_types.h" | 25 #include "content/common/content_notification_types.h" |
| 25 #include "ipc/ipc_channel_proxy.h" | 26 #include "ipc/ipc_channel_proxy.h" |
| 26 | 27 |
| 27 class CommandLine; | 28 class CommandLine; |
| 28 class FilePath; | 29 class FilePath; |
| 29 | 30 |
| 30 namespace IPC { | 31 namespace IPC { |
| 31 class Message; | 32 class Message; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 static void PreCacheFont(LOGFONT font, int pid); | 94 static void PreCacheFont(LOGFONT font, int pid); |
| 94 static void ReleaseCachedFonts(int pid); | 95 static void ReleaseCachedFonts(int pid); |
| 95 #endif // defined(OS_WIN) | 96 #endif // defined(OS_WIN) |
| 96 | 97 |
| 97 // IPC::Message::Sender implementation. | 98 // IPC::Message::Sender implementation. |
| 98 virtual bool Send(IPC::Message* message); | 99 virtual bool Send(IPC::Message* message); |
| 99 | 100 |
| 100 // Adds an IPC message filter. A reference will be kept to the filter. | 101 // Adds an IPC message filter. A reference will be kept to the filter. |
| 101 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); | 102 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
| 102 | 103 |
| 104 // Public and static for reuse by RenderMessageFilter. |
| 105 static void OnAllocateSharedMemory( |
| 106 size_t buffer_size, base::ProcessHandle child_process, |
| 107 base::SharedMemoryHandle* handle); |
| 108 |
| 103 protected: | 109 protected: |
| 104 ChildProcessHost(); | 110 ChildProcessHost(); |
| 105 | 111 |
| 106 // Derived classes return true if it's ok to shut down the child process. | 112 // Derived classes return true if it's ok to shut down the child process. |
| 107 virtual bool CanShutdown() = 0; | 113 virtual bool CanShutdown() = 0; |
| 108 | 114 |
| 109 // Send the shutdown message to the child process. | 115 // Send the shutdown message to the child process. |
| 110 // Does not check if CanShutdown is true. | 116 // Does not check if CanShutdown is true. |
| 111 virtual void ForceShutdown(); | 117 virtual void ForceShutdown(); |
| 112 | 118 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 139 // Subclasses can implement specific notification methods. | 145 // Subclasses can implement specific notification methods. |
| 140 virtual void Notify(int type); | 146 virtual void Notify(int type); |
| 141 | 147 |
| 142 private: | 148 private: |
| 143 // By using an internal class as the IPC::Channel::Listener, we can intercept | 149 // By using an internal class as the IPC::Channel::Listener, we can intercept |
| 144 // OnMessageReceived/OnChannelConnected and do our own processing before | 150 // OnMessageReceived/OnChannelConnected and do our own processing before |
| 145 // calling the subclass' implementation. | 151 // calling the subclass' implementation. |
| 146 class ListenerHook : public IPC::Channel::Listener { | 152 class ListenerHook : public IPC::Channel::Listener { |
| 147 public: | 153 public: |
| 148 explicit ListenerHook(ChildProcessHost* host); | 154 explicit ListenerHook(ChildProcessHost* host); |
| 155 ~ListenerHook(); |
| 149 | 156 |
| 150 void Shutdown(); | 157 void Shutdown(); |
| 151 | 158 |
| 152 // IPC::Channel::Listener methods: | 159 // IPC::Channel::Listener methods: |
| 153 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 160 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 154 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 161 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 155 virtual void OnChannelError() OVERRIDE; | 162 virtual void OnChannelError() OVERRIDE; |
| 163 |
| 164 bool Send(IPC::Message* message) { return host_->Send(message); } |
| 165 |
| 156 private: | 166 private: |
| 167 void OnShutdownRequest(); |
| 168 void OnAllocateSharedMemory(size_t buffer_size, |
| 169 base::SharedMemoryHandle* handle); |
| 157 ChildProcessHost* host_; | 170 ChildProcessHost* host_; |
| 171 base::ProcessHandle peer_handle_; |
| 158 DISALLOW_COPY_AND_ASSIGN(ListenerHook); | 172 DISALLOW_COPY_AND_ASSIGN(ListenerHook); |
| 159 }; | 173 }; |
| 160 | 174 |
| 161 ListenerHook listener_; | 175 ListenerHook listener_; |
| 162 | 176 |
| 163 #if defined (OS_WIN) | 177 #if defined (OS_WIN) |
| 164 class FontCache { | 178 class FontCache { |
| 165 public: | 179 public: |
| 166 static FontCache* GetInstance(); | 180 static FontCache* GetInstance(); |
| 167 void PreCacheFont(LOGFONT font, int process_id); | 181 void PreCacheFont(LOGFONT font, int process_id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 195 | 209 |
| 196 // Holds all the IPC message filters. Since this object lives on the IO | 210 // Holds all the IPC message filters. Since this object lives on the IO |
| 197 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 211 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
| 198 // manually. | 212 // manually. |
| 199 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 213 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
| 200 | 214 |
| 201 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 215 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
| 202 }; | 216 }; |
| 203 | 217 |
| 204 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 218 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |