[M85 Dev][EFL] Fix errors to generate ninja files
[platform/framework/web/chromium-efl.git] / chrome / browser / resources_util.cc
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.
4
5 #include "chrome/browser/resources_util.h"
6
7 #include <stddef.h>
8
9 #include <utility>
10
11 #include "base/containers/flat_map.h"
12 #include "base/no_destructor.h"
13 #include "build/build_config.h"
14 #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"
17
18 #if defined(OS_CHROMEOS)
19 #include "ui/chromeos/resources/grit/ui_chromeos_resources_map.h"
20 #endif
21
22 namespace {
23
24 // A wrapper class that holds a map between resource strings and resource
25 // ids.  This is done so we can use base::NoDestructor which takes care of
26 // thread safety in initializing the map for us.
27 class ThemeMap {
28  public:
29   using StringIntMap = base::flat_map<std::string, int>;
30
31   ThemeMap() {
32     size_t storage_size =
33         kComponentsScaledResourcesSize + kThemeResourcesSize + kUiResourcesSize;
34 #if defined(OS_CHROMEOS)
35     storage_size += kUiChromeosResourcesSize;
36 #endif
37
38     // Construct in one-shot from a moved vector.
39     std::vector<StringIntMap::value_type> storage;
40     storage.reserve(storage_size);
41
42     for (size_t i = 0; i < kComponentsScaledResourcesSize; ++i) {
43       storage.emplace_back(kComponentsScaledResources[i].name,
44                            kComponentsScaledResources[i].value);
45     }
46     for (size_t i = 0; i < kThemeResourcesSize; ++i) {
47       storage.emplace_back(kThemeResources[i].name, kThemeResources[i].value);
48     }
49     for (size_t i = 0; i < kUiResourcesSize; ++i) {
50       storage.emplace_back(kUiResources[i].name, kUiResources[i].value);
51     }
52 #if defined(OS_CHROMEOS)
53     for (size_t i = 0; i < kUiChromeosResourcesSize; ++i) {
54       storage.emplace_back(kUiChromeosResources[i].name,
55                            kUiChromeosResources[i].value);
56     }
57 #endif
58
59     id_map_ = StringIntMap(std::move(storage));
60   }
61
62   int GetId(const std::string& resource_name) const {
63     auto it = id_map_.find(resource_name);
64     return it != id_map_.end() ? it->second : -1;
65   }
66
67  private:
68   StringIntMap id_map_;
69 };
70
71 ThemeMap& GetThemeIdsMap() {
72   static base::NoDestructor<ThemeMap> s;
73   return *s;
74 }
75
76 }  // namespace
77
78 int ResourcesUtil::GetThemeResourceId(const std::string& resource_name) {
79   return GetThemeIdsMap().GetId(resource_name);
80 }