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

Side by Side Diff: chrome/browser/extensions/api/dial/discovery_network_monitor.h

Issue 2602593002: [chrome.dial] [WIP] Adds an API to get the active network ID. (Closed)
Patch Set: Outline API Created 3 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "net/base/ip_address.h"
13 #include "net/base/network_change_notifier.h"
14
15 using net::NetworkChangeNotifier;
16
17 namespace extensions {
18
19 // Represents a single network interface that can be used for discovery.
20 struct NetworkInfo {
21 public:
22 NetworkInfo();
23 ~NetworkInfo() = default;
24
25 // The index of the network interface.
26 uint32_t index = 0;
27 // The connection type. Must be CONNECTION_ETHERNET or CONNECTION_WIFI.
28 NetworkChangeNotifier::ConnectionType connection_type =
29 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN;
30 // The name of the network interface.
31 std::string name;
32 // A unique identifier for the network interface.
33 // For WiFi networks, this is the SSID.
34 // (TODO: How to get on Mac?)
35 // For Ethernet networks, this is the MAC address.
36 // (TODO: How to get?)
37 std::string network_id;
38 // The IP address that is currently assigned to the interface.
39 // Currently DIAL discovery is only supported over IPv4.
40 net::IPAddress ip_address;
41 };
42
43 // Tracks the set of active network interfaces that can be used for DIAL
44 // discovery. If the list of interfaces changes, then
45 // DiscoveryNetworkMonitor::Observer is called with the instance of the manager.
46 // Only one instance of this should be created per browser process.
47 class DiscoveryNetworkMonitor :
48 public net::NetworkChangeNotifier::NetworkChangeObserver {
49 public:
50
51 class Observer {
52 public:
53 // Called when the list of active networks has changed.
54 virtual void OnNetworksChanged(const DiscoveryNetworkMonitor& manager) = 0;
55
56 protected:
57 ~Observer() = default;
58 };
59
60 // TODO: Implement lazy singleton constructor.
61 DiscoveryNetworkMonitor();
62 ~DiscoveryNetworkMonitor() override;
63
64 void AddObserver(Observer *const observer) {}
65 void RemoveObserver(Observer *const observer) {}
66
67 // Returns the current list of active networks.
68 const std::vector<NetworkInfo>& getNetworks() const { return networks_; }
69
70 // Computes a stable string identifier from the list of active networks.
71 // Returns "disconnected" if there are no active networks or "unknown" if the
72 // identifier could not be computed.
73 const std::string getNetworkId() const { return std::string(); }
74
75 private:
76 std::vector<NetworkInfo> networks_;
77 base::ObserverList<Observer> observers_;
78
79 DISALLOW_COPY_AND_ASSIGN(DiscoveryNetworkMonitor);
80 };
81
82 } // namespace extensions
83
84 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DISCOVERY_NETWORK_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/dial/dial_api.cc ('k') | chrome/browser/extensions/api/dial/discovery_network_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698