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> | |
12 | 11 |
13 #include "build/build_config.h" | 12 #include "build/build_config.h" |
14 | 13 |
15 #if defined(OS_WIN) | |
16 #include <windows.h> | |
17 #endif // defined(OS_WIN) | |
18 | |
19 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
20 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
21 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
22 #include "base/shared_memory.h" | 17 #include "base/shared_memory.h" |
23 #include "base/string16.h" | 18 #include "base/string16.h" |
24 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
25 #include "ipc/ipc_channel_proxy.h" | 20 #include "ipc/ipc_channel_proxy.h" |
26 | 21 |
27 class FilePath; | 22 class FilePath; |
28 | 23 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // the default child process pathname will be returned. On most platforms, | 73 // the default child process pathname will be returned. On most platforms, |
79 // this will be the same as the currently-executing process. | 74 // this will be the same as the currently-executing process. |
80 // | 75 // |
81 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF | 76 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF |
82 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL | 77 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL |
83 // if none of these special behaviors are required. | 78 // if none of these special behaviors are required. |
84 // | 79 // |
85 // On failure, returns an empty FilePath. | 80 // On failure, returns an empty FilePath. |
86 static FilePath GetChildPath(int flags); | 81 static FilePath GetChildPath(int flags); |
87 | 82 |
88 #if defined(OS_WIN) | |
89 // See comments in the cc file. This is a common hack needed for a process | |
90 // hosting a sandboxed child process. Hence it lives in this file. | |
91 static void PreCacheFont(LOGFONT font, int pid); | |
92 static void ReleaseCachedFonts(int pid); | |
93 #endif // defined(OS_WIN) | |
94 | |
95 // IPC::Message::Sender implementation. | 83 // IPC::Message::Sender implementation. |
96 virtual bool Send(IPC::Message* message) OVERRIDE; | 84 virtual bool Send(IPC::Message* message) OVERRIDE; |
97 | 85 |
98 // Adds an IPC message filter. A reference will be kept to the filter. | 86 // Adds an IPC message filter. A reference will be kept to the filter. |
99 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); | 87 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
100 | 88 |
101 // Public and static for reuse by RenderMessageFilter. | 89 // Public and static for reuse by RenderMessageFilter. |
102 static void OnAllocateSharedMemory( | 90 static void OnAllocateSharedMemory( |
103 uint32 buffer_size, base::ProcessHandle child_process, | 91 uint32 buffer_size, base::ProcessHandle child_process, |
104 base::SharedMemoryHandle* handle); | 92 base::SharedMemoryHandle* handle); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void OnShutdownRequest(); | 146 void OnShutdownRequest(); |
159 void OnAllocateSharedMemory(uint32 buffer_size, | 147 void OnAllocateSharedMemory(uint32 buffer_size, |
160 base::SharedMemoryHandle* handle); | 148 base::SharedMemoryHandle* handle); |
161 ChildProcessHost* host_; | 149 ChildProcessHost* host_; |
162 base::ProcessHandle peer_handle_; | 150 base::ProcessHandle peer_handle_; |
163 DISALLOW_COPY_AND_ASSIGN(ListenerHook); | 151 DISALLOW_COPY_AND_ASSIGN(ListenerHook); |
164 }; | 152 }; |
165 | 153 |
166 ListenerHook listener_; | 154 ListenerHook listener_; |
167 | 155 |
168 #if defined (OS_WIN) | |
169 class FontCache { | |
170 public: | |
171 static FontCache* GetInstance(); | |
172 void PreCacheFont(LOGFONT font, int process_id); | |
173 void ReleaseCachedFonts(int process_id); | |
174 | |
175 private: | |
176 struct CacheElement { | |
177 CacheElement(); | |
178 ~CacheElement(); | |
179 | |
180 HFONT font_; | |
181 HDC dc_; | |
182 int ref_count_; | |
183 }; | |
184 friend struct DefaultSingletonTraits<FontCache>; | |
185 | |
186 FontCache(); | |
187 ~FontCache(); | |
188 | |
189 std::map<string16, CacheElement> cache_; | |
190 std::map<int, std::vector<string16> > process_id_font_map_; | |
191 base::Lock mutex_; | |
192 | |
193 DISALLOW_COPY_AND_ASSIGN(FontCache); | |
194 }; | |
195 #endif | |
196 | |
197 bool opening_channel_; // True while we're waiting the channel to be opened. | 156 bool opening_channel_; // True while we're waiting the channel to be opened. |
198 scoped_ptr<IPC::Channel> channel_; | 157 scoped_ptr<IPC::Channel> channel_; |
199 std::string channel_id_; | 158 std::string channel_id_; |
200 | 159 |
201 // Holds all the IPC message filters. Since this object lives on the IO | 160 // Holds all the IPC message filters. Since this object lives on the IO |
202 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 161 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
203 // manually. | 162 // manually. |
204 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 163 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
205 | 164 |
206 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 165 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
207 }; | 166 }; |
208 | 167 |
209 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 168 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
OLD | NEW |