| Index: chrome/browser/extensions/api/dial/discovery_network_monitor.h
|
| diff --git a/chrome/browser/extensions/api/dial/discovery_network_monitor.h b/chrome/browser/extensions/api/dial/discovery_network_monitor.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b77b672e9056268175e918a2ab76c29bffca9d1
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/dial/discovery_network_monitor.h
|
| @@ -0,0 +1,84 @@
|
| +// Copyright (c) 2016 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_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| +#include "net/base/ip_address.h"
|
| +#include "net/base/network_change_notifier.h"
|
| +
|
| +using net::NetworkChangeNotifier;
|
| +
|
| +namespace extensions {
|
| +
|
| +// Represents a single network interface that can be used for discovery.
|
| +struct NetworkInfo {
|
| + public:
|
| + NetworkInfo();
|
| + ~NetworkInfo() = default;
|
| +
|
| + // The index of the network interface.
|
| + uint32_t index = 0;
|
| + // The connection type. Must be CONNECTION_ETHERNET or CONNECTION_WIFI.
|
| + NetworkChangeNotifier::ConnectionType connection_type =
|
| + NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN;
|
| + // The name of the network interface.
|
| + std::string name;
|
| + // A unique identifier for the network interface.
|
| + // For WiFi networks, this is the SSID.
|
| + // (TODO: How to get on Mac?)
|
| + // For Ethernet networks, this is the MAC address.
|
| + // (TODO: How to get?)
|
| + std::string network_id;
|
| + // The IP address that is currently assigned to the interface.
|
| + // Currently DIAL discovery is only supported over IPv4.
|
| + net::IPAddress ip_address;
|
| +};
|
| +
|
| +// Tracks the set of active network interfaces that can be used for DIAL
|
| +// discovery. If the list of interfaces changes, then
|
| +// DiscoveryNetworkMonitor::Observer is called with the instance of the manager.
|
| +// Only one instance of this should be created per browser process.
|
| +class DiscoveryNetworkMonitor :
|
| + public net::NetworkChangeNotifier::NetworkChangeObserver {
|
| + public:
|
| +
|
| + class Observer {
|
| + public:
|
| + // Called when the list of active networks has changed.
|
| + virtual void OnNetworksChanged(const DiscoveryNetworkMonitor& manager) = 0;
|
| +
|
| + protected:
|
| + ~Observer() = default;
|
| + };
|
| +
|
| + // TODO: Implement lazy singleton constructor.
|
| + DiscoveryNetworkMonitor();
|
| + ~DiscoveryNetworkMonitor() override;
|
| +
|
| + void AddObserver(Observer *const observer) {}
|
| + void RemoveObserver(Observer *const observer) {}
|
| +
|
| + // Returns the current list of active networks.
|
| + const std::vector<NetworkInfo>& getNetworks() const { return networks_; }
|
| +
|
| + // Computes a stable string identifier from the list of active networks.
|
| + // Returns "disconnected" if there are no active networks or "unknown" if the
|
| + // identifier could not be computed.
|
| + const std::string getNetworkId() const { return std::string(); }
|
| +
|
| + private:
|
| + std::vector<NetworkInfo> networks_;
|
| + base::ObserverList<Observer> observers_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DiscoveryNetworkMonitor);
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
|
|
|