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" |
| 21 #include "base/memory/singleton.h" |
| 22 #include "base/string16.h" |
20 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
21 #include "content/common/content_notification_types.h" | 24 #include "content/common/content_notification_types.h" |
22 #include "ipc/ipc_channel_proxy.h" | 25 #include "ipc/ipc_channel_proxy.h" |
23 | 26 |
24 class CommandLine; | 27 class CommandLine; |
25 class FilePath; | 28 class FilePath; |
26 | 29 |
27 namespace IPC { | 30 namespace IPC { |
28 class Message; | 31 class Message; |
29 } | 32 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF | 83 // The |flags| argument accepts one or more flags such as CHILD_ALLOW_SELF |
81 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL | 84 // and CHILD_ALLOW_HEAP_EXECUTION as defined above. Pass only CHILD_NORMAL |
82 // if none of these special behaviors are required. | 85 // if none of these special behaviors are required. |
83 // | 86 // |
84 // On failure, returns an empty FilePath. | 87 // On failure, returns an empty FilePath. |
85 static FilePath GetChildPath(int flags); | 88 static FilePath GetChildPath(int flags); |
86 | 89 |
87 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
88 // See comments in the cc file. This is a common hack needed for a process | 91 // See comments in the cc file. This is a common hack needed for a process |
89 // hosting a sandboxed child process. Hence it lives in this file. | 92 // hosting a sandboxed child process. Hence it lives in this file. |
90 static void PreCacheFont(LOGFONT font); | 93 static void PreCacheFont(LOGFONT font, int pid); |
| 94 static void ReleaseCachedFonts(int pid); |
91 #endif // defined(OS_WIN) | 95 #endif // defined(OS_WIN) |
92 | 96 |
93 // IPC::Message::Sender implementation. | 97 // IPC::Message::Sender implementation. |
94 virtual bool Send(IPC::Message* message); | 98 virtual bool Send(IPC::Message* message); |
95 | 99 |
96 // Adds an IPC message filter. A reference will be kept to the filter. | 100 // Adds an IPC message filter. A reference will be kept to the filter. |
97 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); | 101 void AddFilter(IPC::ChannelProxy::MessageFilter* filter); |
98 | 102 |
99 protected: | 103 protected: |
100 ChildProcessHost(); | 104 ChildProcessHost(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 146 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
143 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 147 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
144 virtual void OnChannelError() OVERRIDE; | 148 virtual void OnChannelError() OVERRIDE; |
145 private: | 149 private: |
146 ChildProcessHost* host_; | 150 ChildProcessHost* host_; |
147 DISALLOW_COPY_AND_ASSIGN(ListenerHook); | 151 DISALLOW_COPY_AND_ASSIGN(ListenerHook); |
148 }; | 152 }; |
149 | 153 |
150 ListenerHook listener_; | 154 ListenerHook listener_; |
151 | 155 |
| 156 #if defined (OS_WIN) |
| 157 class FontCache { |
| 158 public: |
| 159 static FontCache* GetInstance(); |
| 160 void PreCacheFont(LOGFONT font, int pid); |
| 161 void ReleaseCachedFonts(int pid); |
| 162 |
| 163 private: |
| 164 struct CacheElement { |
| 165 CacheElement(); |
| 166 ~CacheElement(); |
| 167 |
| 168 HFONT font_; |
| 169 HDC dc_; |
| 170 int ref_count_; |
| 171 }; |
| 172 friend struct DefaultSingletonTraits<FontCache>; |
| 173 |
| 174 FontCache(); |
| 175 ~FontCache(); |
| 176 |
| 177 std::map<string16, CacheElement> cache_; |
| 178 std::map<int, std::vector<string16> > pid_font_map_; |
| 179 base::Lock mutex_; |
| 180 |
| 181 DISALLOW_COPY_AND_ASSIGN(FontCache); |
| 182 }; |
| 183 #endif |
| 184 |
152 bool opening_channel_; // True while we're waiting the channel to be opened. | 185 bool opening_channel_; // True while we're waiting the channel to be opened. |
153 scoped_ptr<IPC::Channel> channel_; | 186 scoped_ptr<IPC::Channel> channel_; |
154 std::string channel_id_; | 187 std::string channel_id_; |
155 | 188 |
156 // Holds all the IPC message filters. Since this object lives on the IO | 189 // Holds all the IPC message filters. Since this object lives on the IO |
157 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 190 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
158 // manually. | 191 // manually. |
159 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 192 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
160 | 193 |
161 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 194 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
162 }; | 195 }; |
163 | 196 |
164 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 197 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
OLD | NEW |