Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 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.


#include <string>
#include <vector>

#include "chrome/browser/chromeos/cros/network_library.h"

namespace chromeos {

// Represents list of currently available networks (Ethernet, Cellular, WiFi).
// TODO(nkostylev): Refactor network list which is also represented in
// NetworkMenuButton, InternetPageView.
class NetworkList  {
  enum NetworkType {
    NETWORK_EMPTY,      // Non-initialized network item.

  struct NetworkItem {
        : network_type(NETWORK_EMPTY),
          connected(false) {}
    NetworkItem(NetworkType network_type,
                const string16& label)
        : network_type(network_type),
          label(label) {}
    NetworkItem(NetworkType network_type,
                string16 label,
                WifiNetwork wifi_network,
                CellularNetwork cellular_network)
        : network_type(network_type),
          connected(false) {}

    NetworkType network_type;
    string16 label;      // string representation of the network (shown in UI).
    WifiNetwork wifi_network;
    CellularNetwork cellular_network;
    bool connected;

  virtual ~NetworkList() {}

  // True if network list is empty.
  bool IsEmpty() const {
    return networks_.empty();

  // Returns true, if specified network is currently connected.
  bool IsNetworkConnected(NetworkType type, const string16& id) const;

  // Returns true, if specified network is currently connected.
  bool IsNetworkConnecting(NetworkType type, const string16& id) const;

  // Returns network by it's type and ssid (Wifi) or id (Cellular).
  // If network is not available NULL is returned.
  const NetworkList::NetworkItem* GetNetworkById(NetworkType type,
                                                 const string16& id);

  // Returns network index by it's type and ssid (Wifi) or id (Cellular).
  // If network is not available -1 is returned.
  int GetNetworkIndexById(NetworkType type, const string16& id) const;

  // Returns number of networks.
  size_t GetNetworkCount() const {
    return networks_.size();

  // Returns network by index.
  NetworkList::NetworkItem* GetNetworkAt(int index);

  // Callback from NetworkLibrary.
  void NetworkChanged(chromeos::NetworkLibrary* network_lib);

  typedef std::vector<NetworkItem> NetworkItemVector;
  typedef std::vector<size_t> NetworkIndexVector;

  // Returns true if the specified network is in the list.
  bool IsInNetworkList(const NetworkIndexVector& list,
                       NetworkType type,
                       const string16& id) const;

  // Returns true if network is of the same type and id.
  bool IsSameNetwork(const NetworkList::NetworkItem* network,
                     NetworkType type,
                     const std::string& id) const;

  // Adds network index to the corresponding connected/connecting network list.
  // |index| - network index being processed
  void AddNetworkIndexToList(size_t index, bool connected, bool connecting);

  // Cached list of all available networks with their connection states.
  NetworkItemVector networks_;

  // Connected networks indexes.
  NetworkIndexVector connected_networks_;

  // Connecting networks indexes.
  NetworkIndexVector connecting_networks_;


}  // namespace chromeos


Generated by  Doxygen 1.6.0   Back to index