Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chromeos / network / shill_property_util.h
1 // Copyright 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 #ifndef CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
6 #define CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11 #include "chromeos/chromeos_export.h"
12
13 namespace base {
14 class DictionaryValue;
15 class Value;
16 }
17
18 namespace chromeos {
19
20 class NetworkUIData;
21
22 namespace shill_property_util {
23
24 // Sets the |ssid| in |properties|.
25 CHROMEOS_EXPORT void SetSSID(const std::string ssid,
26                              base::DictionaryValue* properties);
27
28 // Returns the SSID from |properties| in UTF-8 encoding. If |unknown_encoding|
29 // is not NULL, it is set to whether the SSID is of unknown encoding.
30 CHROMEOS_EXPORT std::string GetSSIDFromProperties(
31     const base::DictionaryValue& properties,
32     bool* unknown_encoding);
33
34 // Returns the GUID (if available), SSID, or Name from |properties|. Only used
35 // for logging and debugging.
36 CHROMEOS_EXPORT std::string GetNetworkIdFromProperties(
37     const base::DictionaryValue& properties);
38
39   // Returns the name for the network represented by the Shill |properties|. For
40 // WiFi it refers to the HexSSID.
41 CHROMEOS_EXPORT std::string GetNameFromProperties(
42     const std::string& service_path,
43     const base::DictionaryValue& properties);
44
45 // Returns the UIData specified by |value|. Returns NULL if the value cannot be
46 // parsed.
47 scoped_ptr<NetworkUIData> GetUIDataFromValue(const base::Value& value);
48
49 // Returns the NetworkUIData parsed from the UIData property of
50 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns
51 // NULL.
52 scoped_ptr<NetworkUIData> GetUIDataFromProperties(
53     const base::DictionaryValue& shill_dictionary);
54
55 // Sets the UIData property in |shill_dictionary| to the serialization of
56 // |ui_data|.
57 void SetUIData(const NetworkUIData& ui_data,
58                base::DictionaryValue* shill_dictionary);
59
60 // Copy configuration properties required by Shill to identify a network.
61 // Only WiFi, VPN, Ethernet and EthernetEAP are supported. WiMax and Cellular
62 // are not supported. Returns true only if all required properties could be
63 // copied.
64 bool CopyIdentifyingProperties(const base::DictionaryValue& service_properties,
65                                base::DictionaryValue* dest);
66
67 // Compares the identifying configuration properties of |properties_a| and
68 // |properties_b|, returns true if they are identical. See also
69 // CopyIdentifyingProperties. Only WiFi, VPN, Ethernet and EthernetEAP are
70 // supported. WiMax and Cellular are not supported.
71 bool DoIdentifyingPropertiesMatch(const base::DictionaryValue& properties_a,
72                                   const base::DictionaryValue& properties_b);
73
74 // Returns true if |key| corresponds to a passphrase property.
75 bool IsPassphraseKey(const std::string& key);
76
77 }  // namespace shill_property_util
78
79 class CHROMEOS_EXPORT NetworkTypePattern {
80  public:
81   // Matches any network.
82   static NetworkTypePattern Default();
83
84   // Matches wireless (WiFi, cellular, etc.) networks
85   static NetworkTypePattern Wireless();
86
87   // Matches cellular or wimax networks.
88   static NetworkTypePattern Mobile();
89
90   // Matches non virtual networks.
91   static NetworkTypePattern NonVirtual();
92
93   // Matches ethernet networks (with or without EAP).
94   static NetworkTypePattern Ethernet();
95
96   static NetworkTypePattern WiFi();
97   static NetworkTypePattern Cellular();
98   static NetworkTypePattern VPN();
99   static NetworkTypePattern Wimax();
100
101   // Matches only networks of exactly the type |shill_network_type|, which must
102   // be one of the types defined in service_constants.h (e.g.
103   // shill::kTypeWifi).
104   // Note: Shill distinguishes Ethernet without EAP from Ethernet with EAP. If
105   // unsure, better use one of the matchers above.
106   static NetworkTypePattern Primitive(const std::string& shill_network_type);
107
108   bool Equals(const NetworkTypePattern& other) const;
109   bool MatchesType(const std::string& shill_network_type) const;
110
111   // Returns true if this pattern matches at least one network type that
112   // |other_pattern| matches (according to MatchesType). Thus MatchesPattern is
113   // symmetric and reflexive but not transitive.
114   // See the unit test for examples.
115   bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
116
117   std::string ToDebugString() const;
118
119  private:
120   explicit NetworkTypePattern(int pattern);
121
122   // The bit array of the matching network types.
123   int pattern_;
124
125   DISALLOW_ASSIGN(NetworkTypePattern);
126 };
127
128 }  // namespace chromeos
129
130 #endif  // CHROMEOS_NETWORK_SHILL_PROPERTY_UTIL_H_