blob: 7dd7f4b70f904bc043c21deb64a314c8cd0ef8c5 [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
avib896c712015-12-26 02:10:437#include <stddef.h>
8
[email protected]c5212892010-09-08 06:30:339#include <utility>
10
[email protected]14c1c232013-06-11 17:52:4411#include "base/containers/hash_tables.h"
[email protected]80cc3f72009-04-24 18:06:0512#include "base/lazy_instance.h"
avib896c712015-12-26 02:10:4313#include "build/build_config.h"
thestig4a9b0ef2016-08-29 08:22:1214#include "chrome/grit/theme_resources_map.h"
15#include "components/grit/components_scaled_resources_map.h"
16#include "ui/resources/grit/ui_resources_map.h"
[email protected]80cc3f72009-04-24 18:06:0517
[email protected]cdd7bb82014-07-25 09:19:2618#if defined(OS_CHROMEOS)
thestig4a9b0ef2016-08-29 08:22:1219#include "ui/chromeos/resources/grit/ui_chromeos_resources_map.h"
[email protected]cdd7bb82014-07-25 09:19:2620#endif
21
[email protected]80cc3f72009-04-24 18:06:0522namespace {
23
24// A wrapper class that holds a hash_map between resource strings and resource
25// ids. This is done so we can use base::LazyInstance which takes care of
26// thread safety in initializing the hash_map for us.
27class ThemeMap {
28 public:
29 typedef base::hash_map<std::string, int> StringIntMap;
30
31 ThemeMap() {
droger2a6ab542015-10-09 16:10:2832 for (size_t i = 0; i < kComponentsScaledResourcesSize; ++i) {
33 id_map_[kComponentsScaledResources[i].name] =
34 kComponentsScaledResources[i].value;
35 }
[email protected]2a281332012-07-11 22:20:2336 for (size_t i = 0; i < kThemeResourcesSize; ++i)
[email protected]80cc3f72009-04-24 18:06:0537 id_map_[kThemeResources[i].name] = kThemeResources[i].value;
[email protected]1a4cb9d2013-01-09 05:35:2238 for (size_t i = 0; i < kUiResourcesSize; ++i)
39 id_map_[kUiResources[i].name] = kUiResources[i].value;
[email protected]cdd7bb82014-07-25 09:19:2640#if defined(OS_CHROMEOS)
41 for (size_t i = 0; i < kUiChromeosResourcesSize; ++i)
42 id_map_[kUiChromeosResources[i].name] = kUiChromeosResources[i].value;
43#endif
[email protected]80cc3f72009-04-24 18:06:0544 }
45
46 int GetId(const std::string& resource_name) {
47 StringIntMap::const_iterator it = id_map_.find(resource_name);
48 if (it == id_map_.end())
49 return -1;
50 return it->second;
51 }
52
53 private:
54 StringIntMap id_map_;
55};
56
scottmg5e65e3a2017-03-08 08:48:4657static base::LazyInstance<ThemeMap>::DestructorAtExit g_theme_ids =
58 LAZY_INSTANCE_INITIALIZER;
[email protected]80cc3f72009-04-24 18:06:0559
60} // namespace
61
[email protected]1faee3f02010-06-21 07:01:3462int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) {
[email protected]80cc3f72009-04-24 18:06:0563 return g_theme_ids.Get().GetId(resource_name);
64}