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 |
| 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); |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 explicit ListenerHook(ChildProcessHost* host); | 144 explicit ListenerHook(ChildProcessHost* host); |
137 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 145 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
138 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 146 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
139 virtual void OnChannelError() OVERRIDE; | 147 virtual void OnChannelError() OVERRIDE; |
140 private: | 148 private: |
141 ChildProcessHost* host_; | 149 ChildProcessHost* host_; |
142 }; | 150 }; |
143 | 151 |
144 ListenerHook listener_; | 152 ListenerHook listener_; |
145 | 153 |
| 154 #if defined (OS_WIN) |
| 155 class FontCache { |
| 156 public: |
| 157 FontCache() {} // Make Singleton<> happy. |
| 158 ~FontCache() {} |
| 159 |
| 160 static FontCache* GetInstance(); |
| 161 void PreCacheFont(LOGFONT font, int pid); |
| 162 void ReleaseCachedFont(int pid); |
| 163 |
| 164 private: |
| 165 struct CacheElement { |
| 166 CacheElement(); |
| 167 ~CacheElement(); |
| 168 |
| 169 HFONT font_; |
| 170 HDC dc_; |
| 171 int ref_count_; |
| 172 }; |
| 173 std::map<std::wstring, CacheElement> cache_; |
| 174 PidToFontNames pid_font_map_; |
| 175 base::Lock mutex_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(FontCache); |
| 178 }; |
| 179 #endif |
| 180 |
146 bool opening_channel_; // True while we're waiting the channel to be opened. | 181 bool opening_channel_; // True while we're waiting the channel to be opened. |
147 scoped_ptr<IPC::Channel> channel_; | 182 scoped_ptr<IPC::Channel> channel_; |
148 std::string channel_id_; | 183 std::string channel_id_; |
149 | 184 |
150 // Holds all the IPC message filters. Since this object lives on the IO | 185 // Holds all the IPC message filters. Since this object lives on the IO |
151 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 186 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
152 // manually. | 187 // manually. |
153 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 188 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
154 | 189 |
155 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 190 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
156 }; | 191 }; |
157 | 192 |
158 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 193 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
OLD | NEW |