Cleanup BrowserPluginEmbedder
[chromium-blink-merge.git] / chrome / browser / resources_util.cc
blobd2a593d17add3aeb3be7980ab7b80c51ceb3bc85
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
3 // found in the LICENSE file.
5 #include "chrome/browser/resources_util.h"
7 #include <utility>
9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h"
11 #include "grit/theme_resources_map.h"
12 #include "grit/ui_resources_map.h"
14 #if defined(OS_CHROMEOS)
15 #include "grit/ui_chromeos_resources_map.h"
16 #endif
18 namespace {
20 // A wrapper class that holds a hash_map between resource strings and resource
21 // ids. This is done so we can use base::LazyInstance which takes care of
22 // thread safety in initializing the hash_map for us.
23 class ThemeMap {
24 public:
25 typedef base::hash_map<std::string, int> StringIntMap;
27 ThemeMap() {
28 for (size_t i = 0; i < kThemeResourcesSize; ++i)
29 id_map_[kThemeResources[i].name] = kThemeResources[i].value;
30 for (size_t i = 0; i < kUiResourcesSize; ++i)
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
38 int GetId(const std::string& resource_name) {
39 StringIntMap::const_iterator it = id_map_.find(resource_name);
40 if (it == id_map_.end())
41 return -1;
42 return it->second;
45 private:
46 StringIntMap id_map_;
49 static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER;
51 } // namespace
53 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) {
54 return g_theme_ids.Get().GetId(resource_name);