blob: d2a593d17add3aeb3be7980ab7b80c51ceb3bc85 [file] [log] [blame]
[email protected]2a281332012-07-11 22:20:231// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]80cc3f72009-04-24 18:06:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1faee3f02010-06-21 07:01:345#include "chrome/browser/resources_util.h"
[email protected]80cc3f72009-04-24 18:06:056
[email protected]c5212892010-09-08 06:30:337#include <utility>
8
[email protected]14c1c232013-06-11 17:52:449#include "base/containers/hash_tables.h"
[email protected]80cc3f72009-04-24 18:06:0510#include "base/lazy_instance.h"
[email protected]80cc3f72009-04-24 18:06:0511#include "grit/theme_resources_map.h"
[email protected]1a4cb9d2013-01-09 05:35:2212#include "grit/ui_resources_map.h"
[email protected]80cc3f72009-04-24 18:06:0513
[email protected]cdd7bb82014-07-25 09:19:2614#if defined(OS_CHROMEOS)
15#include "grit/ui_chromeos_resources_map.h"
16#endif
17
[email protected]80cc3f72009-04-24 18:06:0518namespace {
19
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.
23class ThemeMap {
24 public:
25 typedef base::hash_map<std::string, int> StringIntMap;
26
27 ThemeMap() {
[email protected]2a281332012-07-11 22:20:2328 for (size_t i = 0; i < kThemeResourcesSize; ++i)
[email protected]80cc3f72009-04-24 18:06:0529 id_map_[kThemeResources[i].name] = kThemeResources[i].value;
[email protected]1a4cb9d2013-01-09 05:35:2230 for (size_t i = 0; i < kUiResourcesSize; ++i)
31 id_map_[kUiResources[i].name] = kUiResources[i].value;
[email protected]cdd7bb82014-07-25 09:19:2632#if defined(OS_CHROMEOS)
33 for (size_t i = 0; i < kUiChromeosResourcesSize; ++i)
34 id_map_[kUiChromeosResources[i].name] = kUiChromeosResources[i].value;
35#endif
[email protected]80cc3f72009-04-24 18:06:0536 }
37
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;
43 }
44
45 private:
46 StringIntMap id_map_;
47};
48
[email protected]6de0fd1d2011-11-15 13:31:4949static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER;
[email protected]80cc3f72009-04-24 18:06:0550
51} // namespace
52
[email protected]1faee3f02010-06-21 07:01:3453int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) {
[email protected]80cc3f72009-04-24 18:06:0554 return g_theme_ids.Get().GetId(resource_name);
55}