OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/android/resource_mapper.h" | |
6 | |
7 #include <map> | |
8 | |
9 #include "base/logging.h" | |
10 #include "grit/theme_resources.h" | |
11 | |
12 const int ResourceMapper::kMissingId = -1; | |
13 | |
14 namespace { | |
15 std::map<int, int> g_id_map; | |
Yaron
2013/05/20 20:54:25
Don't indent scope under namespace
gone
2013/05/20 21:28:04
Done.
| |
16 | |
17 // Create the mapping. IDs start at 0 to correspond to the array that gets | |
18 // built in the corresponding ResourceID Java class. | |
19 void ConstructMap() { | |
20 int next_id = 0; | |
Yaron
2013/05/20 20:54:25
How about DCHECK(g_id_map.empty());
gone
2013/05/20 21:28:04
Done.
| |
21 #define DEFINE_RESOURCE_ID(c_id,java_id) g_id_map[c_id] = next_id++; | |
22 #include "chrome/browser/android/resource_id.h" | |
23 #undef DEFINE_RESOURCE_ID | |
24 } | |
25 } | |
Yaron
2013/05/20 20:54:25
// namespace
gone
2013/05/20 21:28:04
Done.
| |
26 | |
27 int ResourceMapper::MapFromChromiumId(int resource_id) { | |
28 if (g_id_map.empty()) { | |
29 ConstructMap(); | |
30 } | |
31 | |
32 std::map<int, int>::iterator iterator = g_id_map.find(resource_id); | |
33 if (iterator != g_id_map.end()) { | |
34 return iterator->second; | |
35 } | |
36 | |
37 // The resource couldn't be found. | |
38 NOTREACHED(); | |
39 return kMissingId; | |
40 } | |
OLD | NEW |