Chromium Code Reviews| Index: content/common/font_config_ipc_linux.cc |
| diff --git a/content/common/font_config_ipc_linux.cc b/content/common/font_config_ipc_linux.cc |
| index fcb06ebac0def482978e79011532e8b59804bebd..ca3509a0ce4f750316f3c3654c5189ae2f2f332a 100644 |
| --- a/content/common/font_config_ipc_linux.cc |
| +++ b/content/common/font_config_ipc_linux.cc |
| @@ -23,13 +23,21 @@ |
| namespace content { |
| +class FontConfigIPC::FontMemoryStream |
| + : public SkMemoryStream, |
| + public base::SupportsWeakPtr<FontConfigIPC::FontMemoryStream> { |
|
Daniel Erat
2014/11/06 20:33:55
do you actually need SupportsWeakPtr here and the
Krzysztof Olczyk
2014/11/07 11:38:00
Yes, there was also the problem with the fact that
|
| + public: |
| + explicit FontMemoryStream(SkData* data) : SkMemoryStream(data) {} |
| + ~FontMemoryStream() override {} |
| +}; |
| + |
| // Return a stream from the file descriptor, or NULL on failure. |
| -SkStream* StreamFromFD(int fd) { |
| +FontConfigIPC::FontMemoryStream* FontConfigIPC::StreamFromFD(int fd) { |
| skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd)); |
| if (!data) { |
| return NULL; |
| } |
| - return new SkMemoryStream(data.get()); |
| + return new FontMemoryStream(data.get()); |
| } |
| void CloseFD(int fd) { |
| @@ -96,6 +104,13 @@ bool FontConfigIPC::matchFamilyName(const char familyName[], |
| SkStream* FontConfigIPC::openStream(const FontIdentity& identity) { |
| TRACE_EVENT0("sandbox_ipc", "FontConfigIPC::openStream"); |
| + |
| + auto stream_cache_it = font_stream_cache_.find(identity.fID); |
| + if (stream_cache_it != font_stream_cache_.end() && stream_cache_it->second) |
| + return stream_cache_it->second.get(); |
| + |
| + PurgeFontStreamCache(); |
| + |
| Pickle request; |
| request.WriteInt(METHOD_OPEN); |
| request.WriteUInt32(identity.fID); |
| @@ -119,10 +134,21 @@ SkStream* FontConfigIPC::openStream(const FontIdentity& identity) { |
| return NULL; |
| } |
| - SkStream* stream = StreamFromFD(result_fd); |
| + FontMemoryStream* stream = StreamFromFD(result_fd); |
| CloseFD(result_fd); |
| + font_stream_cache_[identity.fID] = base::AsWeakPtr(stream); |
| return stream; |
| } |
| +void FontConfigIPC::PurgeFontStreamCache() { |
| + auto stream_cache_it = font_stream_cache_.begin(); |
| + while (stream_cache_it != font_stream_cache_.end()) { |
| + if (!stream_cache_it->second) |
| + font_stream_cache_.erase(stream_cache_it++); |
| + else |
| + ++stream_cache_it; |
| + } |
| +} |
| + |
| } // namespace content |