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