Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: chrome/browser/resources_util.cc

Issue 10756018: Merge grd files in ui/resources and chrome/app/theme (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, *_standard.rc Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/hash_tables.h" 9 #include "base/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/theme_resources_standard_map.h"
13 12
14 namespace { 13 namespace {
15 14
16 // A wrapper class that holds a hash_map between resource strings and resource 15 // 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 16 // ids. This is done so we can use base::LazyInstance which takes care of
18 // thread safety in initializing the hash_map for us. 17 // thread safety in initializing the hash_map for us.
19 class ThemeMap { 18 class ThemeMap {
20 public: 19 public:
21 typedef base::hash_map<std::string, int> StringIntMap; 20 typedef base::hash_map<std::string, int> StringIntMap;
22 21
23 ThemeMap() { 22 ThemeMap() {
24 for (size_t i = 0; i < kThemeResourcesSize; ++i) { 23 for (size_t i = 0; i < kThemeResourcesSize; ++i)
25 id_map_[kThemeResources[i].name] = kThemeResources[i].value; 24 id_map_[kThemeResources[i].name] = kThemeResources[i].value;
26 }
27 for (size_t i = 0; i < kThemeResourcesStandardSize; ++i) {
28 id_map_[kThemeResourcesStandard[i].name] =
29 kThemeResourcesStandard[i].value;
30 }
31 } 25 }
32 26
33 int GetId(const std::string& resource_name) { 27 int GetId(const std::string& resource_name) {
34 StringIntMap::const_iterator it = id_map_.find(resource_name); 28 StringIntMap::const_iterator it = id_map_.find(resource_name);
35 if (it == id_map_.end()) 29 if (it == id_map_.end())
36 return -1; 30 return -1;
37 return it->second; 31 return it->second;
38 } 32 }
39 33
40 private: 34 private:
41 StringIntMap id_map_; 35 StringIntMap id_map_;
42 }; 36 };
43 37
44 static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER; 38 static base::LazyInstance<ThemeMap> g_theme_ids = LAZY_INSTANCE_INITIALIZER;
45 39
46 } // namespace 40 } // namespace
47 41
48 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) { 42 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) {
49 return g_theme_ids.Get().GetId(resource_name); 43 return g_theme_ids.Get().GetId(resource_name);
50 } 44 }
OLDNEW
« no previous file with comments | « chrome/browser/protector/session_startup_change.cc ('k') | chrome/browser/resources_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698