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

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

Issue 23618026: NOT FOR SUBMIT: Remove NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months 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
(Empty)
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
7
8 #include <map>
9 #include <string>
10
11 #include "chrome/browser/chromeos/cros/enum_mapper.h"
12 #include "chrome/browser/chromeos/cros/network_library.h"
13
14 namespace base {
15 class DictionaryValue;
16 class Value;
17 }
18
19 namespace chromeos {
20
21 class NetworkDevice;
22
23 // This takes a Value of a particular form, and maps the keys in the dictionary
24 // to a NetworkDevice object to initialize it properly. Subclasses of this can
25 // then customize its methods to parse either Shill data or network setup
26 // information obtained from policy or setup file import depending on the
27 // EnumMapper supplied.
28 class NetworkDeviceParser {
29 public:
30 virtual ~NetworkDeviceParser();
31
32 virtual NetworkDevice* CreateDeviceFromInfo(
33 const std::string& device_path,
34 const base::DictionaryValue& info);
35 virtual bool UpdateDeviceFromInfo(const base::DictionaryValue& info,
36 NetworkDevice* device);
37 virtual bool UpdateStatus(const std::string& key,
38 const base::Value& value,
39 NetworkDevice* device,
40 PropertyIndex* index);
41
42 protected:
43 // The NetworkDeviceParser does not take ownership of the |mapper|.
44 explicit NetworkDeviceParser(const EnumMapper<PropertyIndex>* mapper);
45
46 // Creates new NetworkDevice based on device_path.
47 // Subclasses should override this method and set the correct parser for this
48 // network device if appropriate.
49 virtual NetworkDevice* CreateNewNetworkDevice(const std::string& device_path);
50
51 virtual bool ParseValue(PropertyIndex index,
52 const base::Value& value,
53 NetworkDevice* device) = 0;
54 virtual ConnectionType ParseType(const std::string& type) = 0;
55
56 const EnumMapper<PropertyIndex>& mapper() const {
57 return *mapper_;
58 }
59
60 private:
61 const EnumMapper<PropertyIndex>* mapper_;
62 DISALLOW_COPY_AND_ASSIGN(NetworkDeviceParser);
63 };
64
65 // This takes a Value of a particular form, and uses the keys in the
66 // dictionary to create Network (WiFiNetwork, EthernetNetwork, etc.)
67 // objects and initialize them properly. Subclasses of this can then
68 // customize its methods to parse other forms of input dictionaries.
69 class NetworkParser {
70 public:
71 virtual ~NetworkParser();
72
73 // Called when a new network is encountered. In addition to setting the
74 // members on the Network object, the Network's property_map_ variable
75 // will include all the property and corresponding value in |info|.
76 // Returns NULL upon failure.
77 virtual Network* CreateNetworkFromInfo(const std::string& service_path,
78 const base::DictionaryValue& info);
79
80 // Called when an existing network is has new information that needs
81 // to be updated. Network's property_map_ variable will be updated.
82 // Returns false upon failure.
83 virtual bool UpdateNetworkFromInfo(const base::DictionaryValue& info,
84 Network* network);
85
86 // Called when an individual attribute of an existing network has
87 // changed. |index| is a return value that supplies the appropriate
88 // property index for the given key. |index| is filled in even if
89 // the update fails. Network's property_map_ variable will be updated.
90 // Returns false upon failure.
91 virtual bool UpdateStatus(const std::string& key,
92 const base::Value& value,
93 Network* network,
94 PropertyIndex* index);
95
96 protected:
97 // The NetworkParser does not take ownership of the |mapper|.
98 explicit NetworkParser(const EnumMapper<PropertyIndex>* mapper);
99
100 // Creates new Network based on type and service_path.
101 // Subclasses should override this method and set the correct parser for this
102 // network if appropriate.
103 virtual Network* CreateNewNetwork(ConnectionType type,
104 const std::string& service_path);
105
106 // Parses the value and sets the appropriate field on Network.
107 virtual bool ParseValue(PropertyIndex index,
108 const base::Value& value,
109 Network* network);
110
111 virtual ConnectionType ParseType(const std::string& type) = 0;
112 virtual ConnectionType ParseTypeFromDictionary(
113 const base::DictionaryValue& info) = 0;
114
115 const EnumMapper<PropertyIndex>& mapper() const {
116 return *mapper_;
117 }
118
119 private:
120 const EnumMapper<PropertyIndex>* mapper_;
121 DISALLOW_COPY_AND_ASSIGN(NetworkParser);
122 };
123
124 } // namespace chromeos
125
126 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library_unittest.cc ('k') | chrome/browser/chromeos/cros/network_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698