Chromium Code Reviews| 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 int ResourceMapper::MapFromChromiumID(int resource_id) { | |
|
Yaron
2013/05/17 22:36:16
So every time you map and id you reconstruct the m
gone
2013/05/20 18:48:10
Done. Would it make more sense as a static member
| |
| 15 // Create the mapping. IDs start at 0 to correspond to the array that gets | |
| 16 // built in the corresponding ResourceID Java class. | |
| 17 std::map<int, int> id_map; | |
| 18 int next_id = 0; | |
| 19 #define DEFINE_RESOURCE_ID(c_id,java_id) id_map[c_id] = next_id++; | |
| 20 #include "chrome/browser/android/resource_id.h" | |
| 21 #undef DEFINE_RESOURCE_ID | |
| 22 | |
| 23 // Search the map for the ID. | |
| 24 std::map<int, int>::iterator iterator = id_map.find(resource_id); | |
| 25 if (iterator == id_map.end()) { | |
| 26 // The resource couldn't be found. | |
| 27 NOTREACHED(); | |
| 28 return kMissingID; | |
| 29 } else { | |
| 30 return iterator->second; | |
| 31 } | |
| 32 } | |
| OLD | NEW |