bootstrapping_device_lister.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1// Copyright 2014 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_LOCAL_DISCOVERY_WIFI_BOOTSTRAPPING_DEVICE_LISTER_H_
6#define CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_BOOTSTRAPPING_DEVICE_LISTER_H_
7
8#include <vector>
9
10#include "base/callback.h"
11#include "base/memory/weak_ptr.h"
12#include "chrome/browser/local_discovery/wifi/wifi_manager.h"
13
14namespace local_discovery {
15
16namespace wifi {
17
18struct BootstrappingDeviceDescription {
19  enum ConnectionStatus {
20    ONLINE,
21    OFFLINE,
22    CONNECTING,
23    NOT_CONFIGURED,
24    LOCAL_ONLY
25  };
26
27  BootstrappingDeviceDescription();
28  ~BootstrappingDeviceDescription();
29
30  std::string device_network_id;
31  std::string device_ssid;
32  std::string device_name;
33  std::string device_kind;
34  ConnectionStatus connection_status;
35};
36
37class BootstrappingDeviceLister : public NetworkListObserver {
38 public:
39  typedef base::Callback<
40      void(bool available, const BootstrappingDeviceDescription& description)>
41      UpdateCallback;
42
43  BootstrappingDeviceLister(WifiManager* wifi_manager,
44                            const UpdateCallback& update_callback);
45  virtual ~BootstrappingDeviceLister();
46
47  void Start();
48
49 private:
50  typedef std::vector<
51      std::pair<std::string /*ssid*/, std::string /*internal_name*/> >
52      ActiveDeviceList;
53
54  virtual void OnNetworkListChanged(
55      const std::vector<NetworkProperties>& ssids) OVERRIDE;
56
57  void UpdateChangedSSIDs(bool available,
58                          const ActiveDeviceList& changed,
59                          const ActiveDeviceList& original);
60
61  WifiManager* wifi_manager_;
62  UpdateCallback update_callback_;
63
64  bool started_;
65  ActiveDeviceList active_devices_;
66  base::WeakPtrFactory<BootstrappingDeviceLister> weak_factory_;
67};
68
69}  // namespace wifi
70
71}  // namespace local_discovery
72
73#endif  // CHROME_BROWSER_LOCAL_DISCOVERY_WIFI_BOOTSTRAPPING_DEVICE_LISTER_H_
74