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

Side by Side Diff: chrome/browser/chromeos/cros/network_parser.h

Issue 8734013: Resubmit CL. See 8429004. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <map> 10 #include <map>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 template <typename EnumType> 45 template <typename EnumType>
46 class EnumMapper { 46 class EnumMapper {
47 public: 47 public:
48 struct Pair { 48 struct Pair {
49 const char* key; 49 const char* key;
50 const EnumType value; 50 const EnumType value;
51 }; 51 };
52 52
53 EnumMapper(const Pair* list, size_t num_entries, EnumType unknown) 53 EnumMapper(const Pair* list, size_t num_entries, EnumType unknown)
54 : unknown_value_(unknown) { 54 : unknown_value_(unknown) {
55 for (size_t i = 0; i < num_entries; ++i, ++list) 55 for (size_t i = 0; i < num_entries; ++i, ++list) {
56 enum_map_[list->key] = list->value; 56 enum_map_[list->key] = list->value;
57 inverse_enum_map_[list->value] = list->key;
58 }
57 } 59 }
58 60
59 EnumType Get(const std::string& type) const { 61 EnumType Get(const std::string& type) const {
60 EnumMapConstIter iter = enum_map_.find(type); 62 EnumMapConstIter iter = enum_map_.find(type);
61 if (iter != enum_map_.end()) 63 if (iter != enum_map_.end())
62 return iter->second; 64 return iter->second;
63 return unknown_value_; 65 return unknown_value_;
64 } 66 }
65 67
68 std::string GetKey(EnumType type) const {
69 InverseEnumMapConstIter iter = inverse_enum_map_.find(type);
70 if (iter != inverse_enum_map_.end())
71 return iter->second;
72 return std::string();
73 }
74
66 private: 75 private:
67 typedef typename std::map<std::string, EnumType> EnumMap; 76 typedef typename std::map<std::string, EnumType> EnumMap;
77 typedef typename std::map<EnumType, std::string> InverseEnumMap;
68 typedef typename EnumMap::const_iterator EnumMapConstIter; 78 typedef typename EnumMap::const_iterator EnumMapConstIter;
79 typedef typename InverseEnumMap::const_iterator InverseEnumMapConstIter;
69 EnumMap enum_map_; 80 EnumMap enum_map_;
81 InverseEnumMap inverse_enum_map_;
70 EnumType unknown_value_; 82 EnumType unknown_value_;
71 DISALLOW_COPY_AND_ASSIGN(EnumMapper); 83 DISALLOW_COPY_AND_ASSIGN(EnumMapper);
72 }; 84 };
73 85
74 // This takes a Value of a particular form, and maps the keys in the 86 // This takes a Value of a particular form, and maps the keys in the
75 // dictionary to a NetworkDevice object to initialize it properly. 87 // dictionary to a NetworkDevice object to initialize it properly.
76 // Subclasses of this can then customize its methods to parse either 88 // Subclasses of this can then customize its methods to parse either
77 // libcros (flimflam) data or network setup information obtained from 89 // libcros (flimflam) data or network setup information obtained from
78 // policy or setup file import depending on the EnumMapper supplied. 90 // policy or setup file import depending on the EnumMapper supplied.
79 class NetworkDeviceParser { 91 class NetworkDeviceParser {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 }; 126 };
115 127
116 // This takes a Value of a particular form, and uses the keys in the 128 // This takes a Value of a particular form, and uses the keys in the
117 // dictionary to create Network (WiFiNetwork, EthernetNetwork, etc.) 129 // dictionary to create Network (WiFiNetwork, EthernetNetwork, etc.)
118 // objects and initialize them properly. Subclasses of this can then 130 // objects and initialize them properly. Subclasses of this can then
119 // customize its methods to parse other forms of input dictionaries. 131 // customize its methods to parse other forms of input dictionaries.
120 class NetworkParser { 132 class NetworkParser {
121 public: 133 public:
122 virtual ~NetworkParser(); 134 virtual ~NetworkParser();
123 135
124 // Called when a new network is encountered. Returns NULL upon failure. 136 // Called when a new network is encountered. In addition to setting the
137 // members on the Network object, the Network's property_map_ variable
138 // will include all the property and corresponding value in |info|.
139 // Returns NULL upon failure.
125 virtual Network* CreateNetworkFromInfo(const std::string& service_path, 140 virtual Network* CreateNetworkFromInfo(const std::string& service_path,
126 const base::DictionaryValue& info); 141 const base::DictionaryValue& info);
127 142
128 // Called when an existing network is has new information that needs 143 // Called when an existing network is has new information that needs
129 // to be updated. Returns false upon failure. 144 // to be updated. Network's property_map_ variable will be updated.
145 // Returns false upon failure.
130 virtual bool UpdateNetworkFromInfo(const base::DictionaryValue& info, 146 virtual bool UpdateNetworkFromInfo(const base::DictionaryValue& info,
131 Network* network); 147 Network* network);
132 148
133 // Called when an individual attribute of an existing network has 149 // Called when an individual attribute of an existing network has
134 // changed. |index| is a return value that supplies the appropriate 150 // changed. |index| is a return value that supplies the appropriate
135 // property index for the given key. |index| is filled in even if 151 // property index for the given key. |index| is filled in even if
136 // the update fails. Returns false upon failure. 152 // the update fails. Network's property_map_ variable will be updated.
153 // Returns false upon failure.
137 virtual bool UpdateStatus(const std::string& key, 154 virtual bool UpdateStatus(const std::string& key,
138 const base::Value& value, 155 const base::Value& value,
139 Network* network, 156 Network* network,
140 PropertyIndex* index); 157 PropertyIndex* index);
141 158
142 protected: 159 protected:
143 // The NetworkParser does not take ownership of the |mapper|. 160 // The NetworkParser does not take ownership of the |mapper|.
144 explicit NetworkParser(const EnumMapper<PropertyIndex>* mapper); 161 explicit NetworkParser(const EnumMapper<PropertyIndex>* mapper);
145 162
146 // Creates new Network based on type and service_path. 163 // Creates new Network based on type and service_path.
(...skipping 16 matching lines...) Expand all
163 } 180 }
164 181
165 private: 182 private:
166 const EnumMapper<PropertyIndex>* mapper_; 183 const EnumMapper<PropertyIndex>* mapper_;
167 DISALLOW_COPY_AND_ASSIGN(NetworkParser); 184 DISALLOW_COPY_AND_ASSIGN(NetworkParser);
168 }; 185 };
169 186
170 } // namespace chromeos 187 } // namespace chromeos
171 188
172 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_ 189 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.cc ('k') | chrome/browser/chromeos/cros/network_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698