OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/font_family_cache.h" | 5 #include "chrome/browser/font_family_cache.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); | 62 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
63 std::string font = prefs_->GetString(pref_name.c_str()); | 63 std::string font = prefs_->GetString(pref_name.c_str()); |
64 base::string16 font16 = base::UTF8ToUTF16(font); | 64 base::string16 font16 = base::UTF8ToUTF16(font); |
65 | 65 |
66 // Lazily constructs the map if it doesn't already exist. | 66 // Lazily constructs the map if it doesn't already exist. |
67 ScriptFontMap& map = font_family_map_[map_name]; | 67 ScriptFontMap& map = font_family_map_[map_name]; |
68 map[script] = font16; | 68 map[script] = font16; |
69 | 69 |
70 // Register for profile preference changes. | 70 // Register for profile preference changes. |
71 profile_pref_registrar_.Add( | 71 profile_pref_registrar_.Add( |
72 pref_name.c_str(), | 72 pref_name, |
73 base::Bind(&FontFamilyCache::OnPrefsChanged, base::Unretained(this))); | 73 base::Bind(&FontFamilyCache::OnPrefsChanged, base::Unretained(this))); |
74 return font16; | 74 return font16; |
75 } | 75 } |
76 | 76 |
77 base::string16 FontFamilyCache::FetchAndCacheFont(const char* script, | 77 base::string16 FontFamilyCache::FetchAndCacheFont(const char* script, |
78 const char* map_name) { | 78 const char* map_name) { |
79 FontFamilyMap::const_iterator it = font_family_map_.find(map_name); | 79 FontFamilyMap::const_iterator it = font_family_map_.find(map_name); |
80 if (it != font_family_map_.end()) { | 80 if (it != font_family_map_.end()) { |
81 ScriptFontMap::const_iterator it2 = it->second.find(script); | 81 ScriptFontMap::const_iterator it2 = it->second.find(script); |
82 if (it2 != it->second.end()) | 82 if (it2 != it->second.end()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 if (pref_name.compare( | 115 if (pref_name.compare( |
116 map_name_length + delimiter_length, script_length, script) != 0) | 116 map_name_length + delimiter_length, script_length, script) != 0) |
117 continue; | 117 continue; |
118 | 118 |
119 // If the delimiter doesn't match, move on. | 119 // If the delimiter doesn't match, move on. |
120 if (pref_name[map_name_length] != delimiter) | 120 if (pref_name[map_name_length] != delimiter) |
121 continue; | 121 continue; |
122 | 122 |
123 // Clear the cache and the observer. | 123 // Clear the cache and the observer. |
124 map.erase(it2); | 124 map.erase(it2); |
125 profile_pref_registrar_.Remove(pref_name.c_str()); | 125 profile_pref_registrar_.Remove(pref_name); |
126 break; | 126 break; |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 void FontFamilyCache::Observe(int type, | 131 void FontFamilyCache::Observe(int type, |
132 const content::NotificationSource& source, | 132 const content::NotificationSource& source, |
133 const content::NotificationDetails& details) { | 133 const content::NotificationDetails& details) { |
134 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 134 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
135 profile_pref_registrar_.RemoveAll(); | 135 profile_pref_registrar_.RemoveAll(); |
136 } | 136 } |
OLD | NEW |