| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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_LIBRARY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/observer_list.h" |
| 12 #include "base/singleton.h" |
| 13 #include "base/string16.h" |
| 14 #include "third_party/cros/chromeos_network.h" |
| 15 |
| 16 struct WifiNetwork { |
| 17 WifiNetwork() : encrypted(false), encryption(chromeos::NONE), strength(0) {} |
| 18 WifiNetwork(const std::string& ssid, bool encrypted, |
| 19 chromeos::EncryptionType encryption, int strength) |
| 20 : ssid(ssid), |
| 21 encrypted(encrypted), |
| 22 encryption(encryption), |
| 23 strength(strength) { } |
| 24 |
| 25 // WifiNetworks are sorted by ssids. |
| 26 bool operator< (const WifiNetwork& other) const { |
| 27 return ssid < other.ssid; |
| 28 } |
| 29 |
| 30 std::string ssid; |
| 31 bool encrypted; |
| 32 chromeos::EncryptionType encryption; |
| 33 int strength; |
| 34 }; |
| 35 typedef std::vector<WifiNetwork> WifiNetworkVector; |
| 36 |
| 37 // This class handles the interaction with the ChromeOS network library APIs. |
| 38 // Classes can add themselves as observers. Users can get an instance of this |
| 39 // library class like this: CrosNetworkLibrary::Get() |
| 40 class CrosNetworkLibrary { |
| 41 public: |
| 42 class Observer { |
| 43 public: |
| 44 virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0; |
| 45 }; |
| 46 |
| 47 // This gets the singleton CrosNetworkLibrary |
| 48 static CrosNetworkLibrary* Get(); |
| 49 |
| 50 // Returns true if the ChromeOS library was loaded. |
| 51 static bool loaded(); |
| 52 |
| 53 void AddObserver(Observer* observer); |
| 54 void RemoveObserver(Observer* observer); |
| 55 |
| 56 bool ethernet_connected() const { return ethernet_connected_; } |
| 57 const std::string& wifi_ssid() const { return wifi_ssid_; } |
| 58 bool wifi_connecting() const { return wifi_connecting_; } |
| 59 int wifi_strength() const { return wifi_strength_; } |
| 60 |
| 61 // Returns the current list of wifi networks. |
| 62 WifiNetworkVector GetWifiNetworks(); |
| 63 |
| 64 // Connect to the specified wireless network with password. |
| 65 void ConnectToWifiNetwork(WifiNetwork network, const string16& password); |
| 66 |
| 67 private: |
| 68 friend struct DefaultSingletonTraits<CrosNetworkLibrary>; |
| 69 |
| 70 CrosNetworkLibrary(); |
| 71 ~CrosNetworkLibrary() {} |
| 72 |
| 73 // This method is called when there's a change in network status. |
| 74 // This will notify all the Observers. |
| 75 static void NetworkStatusChangedHandler(void* object, |
| 76 const chromeos::ServiceInfo& service); |
| 77 |
| 78 // Parse a ServiceInfo objects and update our status. |
| 79 void ParseNetworkServiceInfo(const chromeos::ServiceInfo& service); |
| 80 |
| 81 // Initialize the network status on startup. |
| 82 void InitNetworkStatus(); |
| 83 |
| 84 ObserverList<Observer> observers_; |
| 85 |
| 86 // Whether or not we are connected to the ethernet line. |
| 87 bool ethernet_connected_; |
| 88 |
| 89 // The current connected (or connecting) wireless ssid. Empty if none. |
| 90 std::string wifi_ssid_; |
| 91 |
| 92 // Whether or not we are connecting right now. |
| 93 bool wifi_connecting_; |
| 94 |
| 95 // The strength of the currently connected ssid. |
| 96 int wifi_strength_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(CrosNetworkLibrary); |
| 99 }; |
| 100 |
| 101 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| OLD | NEW |