| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 return FetchFont(script, map_name); | 86 return FetchFont(script, map_name); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // There are ~1000 entries in the cache. Avoid unnecessary object construction, | 89 // There are ~1000 entries in the cache. Avoid unnecessary object construction, |
| 90 // including std::string. | 90 // including std::string. |
| 91 void FontFamilyCache::OnPrefsChanged(const std::string& pref_name) { | 91 void FontFamilyCache::OnPrefsChanged(const std::string& pref_name) { |
| 92 const size_t delimiter_length = 1; | 92 const size_t delimiter_length = 1; |
| 93 const char delimiter = '.'; | 93 const char delimiter = '.'; |
| 94 for (FontFamilyMap::iterator it = font_family_map_.begin(); | 94 for (auto& it : font_family_map_) { |
| 95 it != font_family_map_.end(); | 95 const char* map_name = it.first; |
| 96 ++it) { | |
| 97 const char* map_name = it->first; | |
| 98 size_t map_name_length = strlen(map_name); | 96 size_t map_name_length = strlen(map_name); |
| 99 | 97 |
| 100 // If the map name doesn't match, move on. | 98 // If the map name doesn't match, move on. |
| 101 if (pref_name.compare(0, map_name_length, map_name) != 0) | 99 if (pref_name.compare(0, map_name_length, map_name) != 0) |
| 102 continue; | 100 continue; |
| 103 | 101 |
| 104 ScriptFontMap& map = it->second; | 102 ScriptFontMap& map = it.second; |
| 105 for (ScriptFontMap::iterator it2 = map.begin(); it2 != map.end(); ++it2) { | 103 for (ScriptFontMap::iterator it2 = map.begin(); it2 != map.end(); ++it2) { |
| 106 const char* script = it2->first; | 104 const char* script = it2->first; |
| 107 size_t script_length = strlen(script); | 105 size_t script_length = strlen(script); |
| 108 | 106 |
| 109 // If the length doesn't match, move on. | 107 // If the length doesn't match, move on. |
| 110 if (pref_name.size() != | 108 if (pref_name.size() != |
| 111 map_name_length + script_length + delimiter_length) | 109 map_name_length + script_length + delimiter_length) |
| 112 continue; | 110 continue; |
| 113 | 111 |
| 114 // If the script doesn't match, move on. | 112 // If the script doesn't match, move on. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 } | 125 } |
| 128 } | 126 } |
| 129 } | 127 } |
| 130 | 128 |
| 131 void FontFamilyCache::Observe(int type, | 129 void FontFamilyCache::Observe(int type, |
| 132 const content::NotificationSource& source, | 130 const content::NotificationSource& source, |
| 133 const content::NotificationDetails& details) { | 131 const content::NotificationDetails& details) { |
| 134 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 132 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
| 135 profile_pref_registrar_.RemoveAll(); | 133 profile_pref_registrar_.RemoveAll(); |
| 136 } | 134 } |
| OLD | NEW |