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 | 12 |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 | 14 |
14 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
15 #include <windows.h> | 16 #include <windows.h> |
16 #endif // defined(OS_WIN) | 17 #endif // defined(OS_WIN) |
17 | 18 |
18 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "content/common/content_notification_types.h" | 21 #include "content/common/content_notification_types.h" |
21 #include "ipc/ipc_channel_proxy.h" | 22 #include "ipc/ipc_channel_proxy.h" |
22 | 23 |
23 class CommandLine; | 24 class CommandLine; |
24 class FilePath; | 25 class FilePath; |
25 | 26 |
26 namespace IPC { | 27 namespace IPC { |
27 class Message; | 28 class Message; |
28 } | 29 } |
29 | 30 |
31 #if defined(OS_WIN) | |
32 // Types used in PreCacheFont | |
rvargas (doing something else)
2011/09/13 23:40:30
Comments should end with period.
These are fairly
arthurhsu
2011/09/14 02:06:56
Done.
| |
33 typedef std::vector<std::wstring> FontNameVector; | |
34 typedef std::map<int, FontNameVector> PidToFontNames; | |
35 #endif // defined(OS_WIN) | |
36 | |
30 // Provides common functionality for hosting a child process and processing IPC | 37 // Provides common functionality for hosting a child process and processing IPC |
31 // messages between the host and the child process. Subclasses are responsible | 38 // messages between the host and the child process. Subclasses are responsible |
32 // for the actual launching and terminating of the child processes. | 39 // for the actual launching and terminating of the child processes. |
33 class ChildProcessHost : public IPC::Channel::Listener, | 40 class ChildProcessHost : public IPC::Channel::Listener, |
34 public IPC::Message::Sender { | 41 public IPC::Message::Sender { |
35 public: | 42 public: |
36 | 43 |
37 // These flags may be passed to GetChildPath in order to alter its behavior, | 44 // These flags may be passed to GetChildPath in order to alter its behavior, |
38 // causing it to return a child path more suited to a specific task. | 45 // causing it to return a child path more suited to a specific task. |
39 enum { | 46 enum { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF | 86 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF |
80 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL | 87 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL |
81 // if none of these special behaviors are required. | 88 // if none of these special behaviors are required. |
82 // | 89 // |
83 // On failure, returns an empty FilePath. | 90 // On failure, returns an empty FilePath. |
84 static FilePath GetChildPath(int flags); | 91 static FilePath GetChildPath(int flags); |
85 | 92 |
86 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
87 // See comments in the cc file. This is a common hack needed for a process | 94 // See comments in the cc file. This is a common hack needed for a process |
88 // hosting a sandboxed child process. Hence it lives in this file. | 95 // hosting a sandboxed child process. Hence it lives in this file. |
89 static void PreCacheFont(LOGFONT font); | 96 static void PreCacheFont(LOGFONT font, int pid); |
97 static void ReleaseCachedFont(int pid); | |
rvargas (doing something else)
2011/09/13 23:40:30
This doesn't release a font... releases all fonts
arthurhsu
2011/09/14 02:06:56
Done.
| |
90 #endif // defined(OS_WIN) | 98 #endif // defined(OS_WIN) |
91 | 99 |
92 // IPC::Message::Sender implementation. | 100 // IPC::Message::Sender implementation. |
93 virtual bool Send(IPC::Message* message); | 101 virtual bool Send(IPC::Message* message); |
94 | 102 |
95 // Adds an IPC message filter. A reference will be kept to the filter. | 103 // Adds an IPC message filter. A reference will be kept to the filter. |
96 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); | 104 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
97 | 105 |
98 protected: | 106 protected: |
99 ChildProcessHost(); | 107 ChildProcessHost(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 149 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
142 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 150 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
143 virtual void OnChannelError() OVERRIDE; | 151 virtual void OnChannelError() OVERRIDE; |
144 private: | 152 private: |
145 ChildProcessHost* host_; | 153 ChildProcessHost* host_; |
146 DISALLOW_COPY_AND_ASSIGN(ListenerHook); | 154 DISALLOW_COPY_AND_ASSIGN(ListenerHook); |
147 }; | 155 }; |
148 | 156 |
149 ListenerHook listener_; | 157 ListenerHook listener_; |
150 | 158 |
159 #if defined (OS_WIN) | |
160 class FontCache { | |
161 public: | |
162 FontCache() {} // Make Singleton<> happy. | |
rvargas (doing something else)
2011/09/13 23:40:30
friend struct DefaultSingletonTraits<FontCache>;
arthurhsu
2011/09/14 02:06:56
Done.
| |
163 ~FontCache() {} | |
164 | |
165 static FontCache* GetInstance(); | |
166 void PreCacheFont(LOGFONT font, int pid); | |
167 void ReleaseCachedFont(int pid); | |
168 | |
169 private: | |
170 struct CacheElement { | |
171 CacheElement(); | |
172 ~CacheElement(); | |
173 | |
174 HFONT font_; | |
175 HDC dc_; | |
176 int ref_count_; | |
177 }; | |
178 std::map<std::wstring, CacheElement> cache_; | |
179 PidToFontNames pid_font_map_; | |
180 base::Lock mutex_; | |
181 | |
182 DISALLOW_COPY_AND_ASSIGN(FontCache); | |
183 }; | |
184 #endif | |
185 | |
151 bool opening_channel_; // True while we're waiting the channel to be opened. | 186 bool opening_channel_; // True while we're waiting the channel to be opened. |
152 scoped_ptr<IPC::Channel> channel_; | 187 scoped_ptr<IPC::Channel> channel_; |
153 std::string channel_id_; | 188 std::string channel_id_; |
154 | 189 |
155 // Holds all the IPC message filters. Since this object lives on the IO | 190 // Holds all the IPC message filters. Since this object lives on the IO |
156 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 191 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
157 // manually. | 192 // manually. |
158 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 193 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
159 | 194 |
160 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 195 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
161 }; | 196 }; |
162 | 197 |
163 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 198 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
OLD | NEW |