| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/common/font_cache_dispatcher_win.h" | 5 #include "content/common/font_cache_dispatcher_win.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 namespace { | 16 namespace { |
| 17 typedef std::vector<base::string16> FontNameVector; | 17 typedef std::vector<base::string16> FontNameVector; |
| 18 typedef std::map<FontCacheDispatcher*, FontNameVector> DispatcherToFontNames; | 18 typedef std::map<FontCacheDispatcher*, FontNameVector> DispatcherToFontNames; |
| 19 | 19 |
| 20 class FontCache { | 20 class FontCache { |
| 21 public: | 21 public: |
| 22 static FontCache* GetInstance() { | 22 static FontCache* GetInstance() { return base::Singleton<FontCache>::get(); } |
| 23 return Singleton<FontCache>::get(); | |
| 24 } | |
| 25 | 23 |
| 26 void PreCacheFont(const LOGFONT& font, FontCacheDispatcher* dispatcher) { | 24 void PreCacheFont(const LOGFONT& font, FontCacheDispatcher* dispatcher) { |
| 27 // TODO(ananta): Remove ScopedTracker below once crbug.com/90127 is fixed. | 25 // TODO(ananta): Remove ScopedTracker below once crbug.com/90127 is fixed. |
| 28 tracked_objects::ScopedTracker tracking_profile( | 26 tracked_objects::ScopedTracker tracking_profile( |
| 29 FROM_HERE_WITH_EXPLICIT_FUNCTION("90127 FontCache::PreCacheFont")); | 27 FROM_HERE_WITH_EXPLICIT_FUNCTION("90127 FontCache::PreCacheFont")); |
| 30 | 28 |
| 31 base::AutoLock lock(mutex_); | 29 base::AutoLock lock(mutex_); |
| 32 | 30 |
| 33 // Fetch the font into memory. | 31 // Fetch the font into memory. |
| 34 // No matter the font is cached or not, we load it to avoid GDI swapping out | 32 // No matter the font is cached or not, we load it to avoid GDI swapping out |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (dc_) { | 114 if (dc_) { |
| 117 ReleaseDC(NULL, dc_); | 115 ReleaseDC(NULL, dc_); |
| 118 } | 116 } |
| 119 } | 117 } |
| 120 | 118 |
| 121 HFONT font_; | 119 HFONT font_; |
| 122 HGDIOBJ old_font_; | 120 HGDIOBJ old_font_; |
| 123 HDC dc_; | 121 HDC dc_; |
| 124 int ref_count_; | 122 int ref_count_; |
| 125 }; | 123 }; |
| 126 friend struct DefaultSingletonTraits<FontCache>; | 124 friend struct base::DefaultSingletonTraits<FontCache>; |
| 127 | 125 |
| 128 FontCache() { | 126 FontCache() { |
| 129 } | 127 } |
| 130 | 128 |
| 131 std::map<base::string16, CacheElement> cache_; | 129 std::map<base::string16, CacheElement> cache_; |
| 132 DispatcherToFontNames dispatcher_font_map_; | 130 DispatcherToFontNames dispatcher_font_map_; |
| 133 base::Lock mutex_; | 131 base::Lock mutex_; |
| 134 | 132 |
| 135 DISALLOW_COPY_AND_ASSIGN(FontCache); | 133 DISALLOW_COPY_AND_ASSIGN(FontCache); |
| 136 }; | 134 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 FontCache::GetInstance()->PreCacheFont(font, this); | 186 FontCache::GetInstance()->PreCacheFont(font, this); |
| 189 } | 187 } |
| 190 | 188 |
| 191 void FontCacheDispatcher::OnReleaseCachedFonts() { | 189 void FontCacheDispatcher::OnReleaseCachedFonts() { |
| 192 // Release cached fonts that requested from a pid by decrementing the ref | 190 // Release cached fonts that requested from a pid by decrementing the ref |
| 193 // count. When ref count is zero, the handles are released. | 191 // count. When ref count is zero, the handles are released. |
| 194 FontCache::GetInstance()->ReleaseCachedFonts(this); | 192 FontCache::GetInstance()->ReleaseCachedFonts(this); |
| 195 } | 193 } |
| 196 | 194 |
| 197 } // namespace content | 195 } // namespace content |
| OLD | NEW |