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

Unified Diff: chrome/browser/chromeos/cros_network_library.h

Issue 251099: Refactor cros library code into central location and have the UI elements obs... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/cros_library.cc ('k') | chrome/browser/chromeos/cros_network_library.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros_network_library.h
===================================================================
--- chrome/browser/chromeos/cros_network_library.h (revision 0)
+++ chrome/browser/chromeos/cros_network_library.h (revision 0)
@@ -0,0 +1,101 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
+
+#include <string>
+#include <vector>
+
+#include "base/observer_list.h"
+#include "base/singleton.h"
+#include "base/string16.h"
+#include "third_party/cros/chromeos_network.h"
+
+struct WifiNetwork {
+ WifiNetwork() : encrypted(false), encryption(chromeos::NONE), strength(0) {}
+ WifiNetwork(const std::string& ssid, bool encrypted,
+ chromeos::EncryptionType encryption, int strength)
+ : ssid(ssid),
+ encrypted(encrypted),
+ encryption(encryption),
+ strength(strength) { }
+
+ // WifiNetworks are sorted by ssids.
+ bool operator< (const WifiNetwork& other) const {
+ return ssid < other.ssid;
+ }
+
+ std::string ssid;
+ bool encrypted;
+ chromeos::EncryptionType encryption;
+ int strength;
+};
+typedef std::vector<WifiNetwork> WifiNetworkVector;
+
+// This class handles the interaction with the ChromeOS network library APIs.
+// Classes can add themselves as observers. Users can get an instance of this
+// library class like this: CrosNetworkLibrary::Get()
+class CrosNetworkLibrary {
+ public:
+ class Observer {
+ public:
+ virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0;
+ };
+
+ // This gets the singleton CrosNetworkLibrary
+ static CrosNetworkLibrary* Get();
+
+ // Returns true if the ChromeOS library was loaded.
+ static bool loaded();
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ bool ethernet_connected() const { return ethernet_connected_; }
+ const std::string& wifi_ssid() const { return wifi_ssid_; }
+ bool wifi_connecting() const { return wifi_connecting_; }
+ int wifi_strength() const { return wifi_strength_; }
+
+ // Returns the current list of wifi networks.
+ WifiNetworkVector GetWifiNetworks();
+
+ // Connect to the specified wireless network with password.
+ void ConnectToWifiNetwork(WifiNetwork network, const string16& password);
+
+ private:
+ friend struct DefaultSingletonTraits<CrosNetworkLibrary>;
+
+ CrosNetworkLibrary();
+ ~CrosNetworkLibrary() {}
+
+ // This method is called when there's a change in network status.
+ // This will notify all the Observers.
+ static void NetworkStatusChangedHandler(void* object,
+ const chromeos::ServiceInfo& service);
+
+ // Parse a ServiceInfo objects and update our status.
+ void ParseNetworkServiceInfo(const chromeos::ServiceInfo& service);
+
+ // Initialize the network status on startup.
+ void InitNetworkStatus();
+
+ ObserverList<Observer> observers_;
+
+ // Whether or not we are connected to the ethernet line.
+ bool ethernet_connected_;
+
+ // The current connected (or connecting) wireless ssid. Empty if none.
+ std::string wifi_ssid_;
+
+ // Whether or not we are connecting right now.
+ bool wifi_connecting_;
+
+ // The strength of the currently connected ssid.
+ int wifi_strength_;
+
+ DISALLOW_COPY_AND_ASSIGN(CrosNetworkLibrary);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
Property changes on: chrome/browser/chromeos/cros_network_library.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/chromeos/cros_library.cc ('k') | chrome/browser/chromeos/cros_network_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698