cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chromeos / network / network_util.h
blob47cdcde623357e8d6a918dec97de1c56a516e497
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.
5 #ifndef CHROMEOS_NETWORK_NETWORK_UTIL_H_
6 #define CHROMEOS_NETWORK_NETWORK_UTIL_H_
8 // This header is introduced to make it easy to switch from chromeos_network.cc
9 // to Chrome's own DBus code. crosbug.com/16557
10 // All calls to functions in chromeos_network.h should be made through
11 // functions provided by this header.
13 #include <string>
14 #include <vector>
16 #include "base/basictypes.h"
17 #include "base/callback.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/time/time.h"
20 #include "base/values.h"
21 #include "chromeos/chromeos_export.h"
23 namespace base {
24 class ListValue;
27 namespace chromeos {
29 class NetworkState;
30 class NetworkTypePattern;
32 // Struct for passing wifi access point data.
33 struct CHROMEOS_EXPORT WifiAccessPoint {
34 WifiAccessPoint();
35 ~WifiAccessPoint();
36 std::string ssid; // The ssid of the WiFi node if available.
37 std::string mac_address; // The mac address of the WiFi node.
38 base::Time timestamp; // Timestamp when this AP was detected.
39 int signal_strength; // Radio signal strength measured in dBm.
40 int signal_to_noise; // Current signal to noise ratio measured in dB.
41 int channel; // Wifi channel number.
44 // Struct for passing network scan result data.
45 struct CHROMEOS_EXPORT CellularScanResult {
46 CellularScanResult();
47 ~CellularScanResult();
48 std::string status; // The network's availability status. (One of "unknown",
49 // "available", "current", or "forbidden")
50 std::string network_id; // 3GPP operator code ("MCCMNC").
51 std::string short_name; // Short-format name of the operator.
52 std::string long_name; // Long-format name of the operator.
53 std::string technology; // Access technology.
56 typedef std::vector<WifiAccessPoint> WifiAccessPointVector;
58 // Describes whether there is an error and whether the error came from
59 // the local system or from the server implementing the connect
60 // method.
61 enum NetworkMethodErrorType {
62 NETWORK_METHOD_ERROR_NONE = 0,
63 NETWORK_METHOD_ERROR_LOCAL = 1,
64 NETWORK_METHOD_ERROR_REMOTE = 2,
67 // Callback for methods that initiate an operation and return no data.
68 typedef base::Callback<void(
69 const std::string& path,
70 NetworkMethodErrorType error,
71 const std::string& error_message)> NetworkOperationCallback;
73 namespace network_util {
75 // Converts a |prefix_length| to a netmask. (for IPv4 only)
76 // e.g. a |prefix_length| of 24 is converted to a netmask of "255.255.255.0".
77 // Invalid prefix lengths will return the empty string.
78 CHROMEOS_EXPORT std::string PrefixLengthToNetmask(int32 prefix_length);
80 // Converts a |netmask| to a prefixlen. (for IPv4 only)
81 // e.g. a |netmask| of 255.255.255.0 is converted to a prefixlen of 24
82 CHROMEOS_EXPORT int32 NetmaskToPrefixLength(const std::string& netmask);
84 // Returns |shill_mac_address| in aa:bb format.
85 CHROMEOS_EXPORT std::string FormattedMacAddress(
86 const std::string& shill_mac_address);
88 // Parses |list|, which contains DictionaryValues and returns a vector of
89 // CellularScanResult in |scan_results|. Returns false if parsing fails,
90 // in which case the contents of |scan_results| will be undefined.
91 CHROMEOS_EXPORT bool ParseCellularScanResults(
92 const base::ListValue& list, std::vector<CellularScanResult>* scan_results);
94 // Retrieves the ONC state dictionary for |network| using GetStateProperties.
95 // This includes properties from the corresponding NetworkState if it exists.
96 // Assumed to be called from the primary user profile.
97 CHROMEOS_EXPORT scoped_ptr<base::DictionaryValue> TranslateNetworkStateToONC(
98 const NetworkState* network);
100 // Retrieves the list of network services by passing |pattern|,
101 // |configured_only|, and |visible_only| to NetworkStateHandler::
102 // GetNetworkListByType(). Translates the result into a list of ONC
103 // dictionaries using TranslateShillServiceToONCPart. |limit| is used to limit
104 // the number of results.
105 CHROMEOS_EXPORT scoped_ptr<base::ListValue> TranslateNetworkListToONC(
106 NetworkTypePattern pattern,
107 bool configured_only,
108 bool visible_only,
109 int limit);
111 // Returns the Shill type corresponding to ONC |type| or an empty string if
112 // there is no match. Only valid for ethernet, wifi, wimax, cellular, and vpn.
113 CHROMEOS_EXPORT std::string TranslateONCTypeToShill(const std::string& type);
115 // Inverse of TranslateONCTypeToShill.
116 CHROMEOS_EXPORT std::string TranslateShillTypeToONC(const std::string& type);
118 } // namespace network_util
119 } // namespace chromeos
121 #endif // CHROMEOS_NETWORK_NETWORK_UTIL_H_