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

Unified Diff: chrome/browser/chromeos/cros/network_parser.h

Issue 8804020: Set onc_source UI data parameter when importing ONC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.cc ('k') | chrome/browser/chromeos/cros/network_ui_data.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/network_parser.h
diff --git a/chrome/browser/chromeos/cros/network_parser.h b/chrome/browser/chromeos/cros/network_parser.h
index a1a53e2161ce18d8a10f7c43fd9123bf1771c4da..6a61cdcba0550a4c6f2f676ced83013b43d322f9 100644
--- a/chrome/browser/chromeos/cros/network_parser.h
+++ b/chrome/browser/chromeos/cros/network_parser.h
@@ -6,10 +6,11 @@
#define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
#pragma once
-#include <string>
#include <map>
+#include <string>
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/cros/enum_mapper.h"
#include "chrome/browser/chromeos/cros/network_library.h"
namespace base {
@@ -21,68 +22,6 @@ namespace chromeos {
class NetworkDevice;
-// This turns an array of string-to-enum-value mappings into a class
-// that can cache the mapping and do quick lookups using an actual map
-// class. Usage is something like:
-//
-// const char kKey1[] = "key1";
-// const char kKey2[] = "key2";
-//
-// enum EnumFoo {
-// UNKNOWN = 0,
-// FOO = 1,
-// BAR = 2,
-// };
-//
-// const EnumMapper<EnumFoo>::Pair index_table[] = {
-// { kKey1, FOO },
-// { kKey2, BAR },
-// };
-//
-// EnumMapper<EnumFoo> mapper(index_table, arraysize(index_table), UNKNOWN);
-// EnumFoo value = mapper.Get(kKey1); // Returns FOO.
-// EnumFoo value = mapper.Get('boo'); // Returns UNKNOWN.
-template <typename EnumType>
-class EnumMapper {
- public:
- struct Pair {
- const char* key;
- const EnumType value;
- };
-
- EnumMapper(const Pair* list, size_t num_entries, EnumType unknown)
- : unknown_value_(unknown) {
- for (size_t i = 0; i < num_entries; ++i, ++list) {
- enum_map_[list->key] = list->value;
- inverse_enum_map_[list->value] = list->key;
- }
- }
-
- EnumType Get(const std::string& type) const {
- EnumMapConstIter iter = enum_map_.find(type);
- if (iter != enum_map_.end())
- return iter->second;
- return unknown_value_;
- }
-
- std::string GetKey(EnumType type) const {
- InverseEnumMapConstIter iter = inverse_enum_map_.find(type);
- if (iter != inverse_enum_map_.end())
- return iter->second;
- return std::string();
- }
-
- private:
- typedef typename std::map<std::string, EnumType> EnumMap;
- typedef typename std::map<EnumType, std::string> InverseEnumMap;
- typedef typename EnumMap::const_iterator EnumMapConstIter;
- typedef typename InverseEnumMap::const_iterator InverseEnumMapConstIter;
- EnumMap enum_map_;
- InverseEnumMap inverse_enum_map_;
- EnumType unknown_value_;
- DISALLOW_COPY_AND_ASSIGN(EnumMapper);
-};
-
// This takes a Value of a particular form, and maps the keys in the
// dictionary to a NetworkDevice object to initialize it properly.
// Subclasses of this can then customize its methods to parse either
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.cc ('k') | chrome/browser/chromeos/cros/network_ui_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698