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 "chrome/browser/resources_util.h" | 5 #include "chrome/browser/resources_util.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "grit/theme_resources_map.h" | 11 #include "grit/theme_resources_map.h" |
12 #include "grit/ui_resources_map.h" | 12 #include "grit/ui_resources_map.h" |
13 | 13 |
| 14 #if defined(OS_CHROMEOS) |
| 15 #include "grit/ui_chromeos_resources_map.h" |
| 16 #endif |
| 17 |
14 namespace { | 18 namespace { |
15 | 19 |
16 // A wrapper class that holds a hash_map between resource strings and resource | 20 // A wrapper class that holds a hash_map between resource strings and resource |
17 // ids. This is done so we can use base::LazyInstance which takes care of | 21 // ids. This is done so we can use base::LazyInstance which takes care of |
18 // thread safety in initializing the hash_map for us. | 22 // thread safety in initializing the hash_map for us. |
19 class ThemeMap { | 23 class ThemeMap { |
20 public: | 24 public: |
21 typedef base::hash_map<std::string, int> StringIntMap; | 25 typedef base::hash_map<std::string, int> StringIntMap; |
22 | 26 |
23 ThemeMap() { | 27 ThemeMap() { |
24 for (size_t i = 0; i < kThemeResourcesSize; ++i) | 28 for (size_t i = 0; i < kThemeResourcesSize; ++i) |
25 id_map_[kThemeResources[i].name] = kThemeResources[i].value; | 29 id_map_[kThemeResources[i].name] = kThemeResources[i].value; |
26 for (size_t i = 0; i < kUiResourcesSize; ++i) | 30 for (size_t i = 0; i < kUiResourcesSize; ++i) |
27 id_map_[kUiResources[i].name] = kUiResources[i].value; | 31 id_map_[kUiResources[i].name] = kUiResources[i].value; |
| 32 #if defined(OS_CHROMEOS) |
| 33 for (size_t i = 0; i < kUiChromeosResourcesSize; ++i) |
| 34 id_map_[kUiChromeosResources[i].name] = kUiChromeosResources[i].value; |
| 35 #endif |
28 } | 36 } |
29 | 37 |
30 int GetId(const std::string& resource_name) { | 38 int GetId(const std::string& resource_name) { |
31 StringIntMap::const_iterator it = id_map_.find(resource_name); | 39 StringIntMap::const_iterator it = id_map_.find(resource_name); |
32 if (it == id_map_.end()) | 40 if (it == id_map_.end()) |
33 return -1; | 41 return -1; |
34 return it->second; | 42 return it->second; |
35 } | 43 } |
36 | 44 |
37 private: | 45 private: |
38 StringIntMap id_map_; | 46 StringIntMap id_map_; |
39 }; | 47 }; |
40 | 48 |
41 static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER; | 49 static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER; |
42 | 50 |
43 } // namespace | 51 } // namespace |
44 | 52 |
45 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) { | 53 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) { |
46 return g_theme_ids.Get().GetId(resource_name); | 54 return g_theme_ids.Get().GetId(resource_name); |
47 } | 55 } |
OLD | NEW |