Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / android / resource_mapper.cc
blob545caf7140bffb34ef9b2890818ad70407c9b48f
1 // Copyright (c) 2013 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/android/resource_mapper.h"
7 #include <map>
9 #include "base/lazy_instance.h"
10 #include "base/logging.h"
11 #include "grit/components_scaled_resources.h"
12 #include "grit/theme_resources.h"
14 namespace {
16 typedef std::map<int, int> ResourceMap;
17 base::LazyInstance<ResourceMap>::Leaky g_id_map = LAZY_INSTANCE_INITIALIZER;
19 } // namespace
21 const int ResourceMapper::kMissingId = -1;
23 int ResourceMapper::MapFromChromiumId(int resource_id) {
24 if (g_id_map.Get().empty()) {
25 ConstructMap();
28 ResourceMap::iterator iterator = g_id_map.Get().find(resource_id);
29 if (iterator != g_id_map.Get().end()) {
30 return iterator->second;
33 // The resource couldn't be found.
34 NOTREACHED();
35 return kMissingId;
38 void ResourceMapper::ConstructMap() {
39 DCHECK(g_id_map.Get().empty());
40 int next_id = 0;
42 #define DEFINE_RESOURCE_ID(c_id,java_id) g_id_map.Get()[c_id] = next_id++;
43 #include "chrome/browser/android/resource_id.h"
44 #undef DEFINE_RESOURCE_ID