| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 153 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 150 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 154 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 151 virtual void OnChannelError() OVERRIDE; | 155 virtual void OnChannelError() OVERRIDE; |
| 152 private: | 156 private: |
| 153 ChildProcessHost* host_; | 157 ChildProcessHost* host_; |
| 154 DISALLOW_COPY_AND_ASSIGN(ListenerHook); | 158 DISALLOW_COPY_AND_ASSIGN(ListenerHook); |
| 155 }; | 159 }; |
| 156 | 160 |
| 157 ListenerHook listener_; | 161 ListenerHook listener_; |
| 158 | 162 |
| 163 #if defined (OS_WIN) |
| 164 class FontCache { |
| 165 public: |
| 166 static FontCache* GetInstance(); |
| 167 void PreCacheFont(LOGFONT font, int process_id); |
| 168 void ReleaseCachedFonts(int process_id); |
| 169 |
| 170 private: |
| 171 struct CacheElement { |
| 172 CacheElement(); |
| 173 ~CacheElement(); |
| 174 |
| 175 HFONT font_; |
| 176 HDC dc_; |
| 177 int ref_count_; |
| 178 }; |
| 179 friend struct DefaultSingletonTraits<FontCache>; |
| 180 |
| 181 FontCache(); |
| 182 ~FontCache(); |
| 183 |
| 184 std::map<string16, CacheElement> cache_; |
| 185 std::map<int, std::vector<string16> > process_id_font_map_; |
| 186 base::Lock mutex_; |
| 187 |
| 188 DISALLOW_COPY_AND_ASSIGN(FontCache); |
| 189 }; |
| 190 #endif |
| 191 |
| 159 bool opening_channel_; // True while we're waiting the channel to be opened. | 192 bool opening_channel_; // True while we're waiting the channel to be opened. |
| 160 scoped_ptr<IPC::Channel> channel_; | 193 scoped_ptr<IPC::Channel> channel_; |
| 161 std::string channel_id_; | 194 std::string channel_id_; |
| 162 | 195 |
| 163 // Holds all the IPC message filters. Since this object lives on the IO | 196 // Holds all the IPC message filters. Since this object lives on the IO |
| 164 // thread, we don't have a IPC::ChannelProxy and so we manage filters | 197 // thread, we don't have a IPC::ChannelProxy and so we manage filters |
| 165 // manually. | 198 // manually. |
| 166 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; | 199 std::vector<scoped_refptr<IPC::ChannelProxy::MessageFilter> > filters_; |
| 167 | 200 |
| 168 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 201 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
| 169 }; | 202 }; |
| 170 | 203 |
| 171 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ | 204 #endif // CONTENT_COMMON_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |