| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 DEVICE_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | |
| 6 #define DEVICE_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | |
| 7 | |
| 8 #include <assert.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "base/logging.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/strings/string16.h" | |
| 17 #include "device/geolocation/geolocation_export.h" | |
| 18 #include "device/geolocation/wifi_data_provider.h" | |
| 19 #include "device/geolocation/wifi_polling_policy.h" | |
| 20 | |
| 21 namespace device { | |
| 22 | |
| 23 // Converts a MAC address stored as an array of uint8_t to a string. | |
| 24 base::string16 MacAddressAsString16(const uint8_t mac_as_int[6]); | |
| 25 | |
| 26 // Base class to promote code sharing between platform specific wifi data | |
| 27 // providers. It's optional for specific platforms to derive this, but if they | |
| 28 // do polling behavior is taken care of by this base class, and all the platform | |
| 29 // need do is provide the underlying WLAN access API and polling policy. | |
| 30 // Also designed this way for ease of testing the cross-platform behavior. | |
| 31 class DEVICE_GEOLOCATION_EXPORT WifiDataProviderCommon | |
| 32 : public WifiDataProvider { | |
| 33 public: | |
| 34 // Interface to abstract the low level data OS library call, and to allow | |
| 35 // mocking (hence public). | |
| 36 class WlanApiInterface { | |
| 37 public: | |
| 38 virtual ~WlanApiInterface() {} | |
| 39 // Gets wifi data for all visible access points. | |
| 40 virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0; | |
| 41 }; | |
| 42 | |
| 43 WifiDataProviderCommon(); | |
| 44 | |
| 45 // WifiDataProvider implementation | |
| 46 void StartDataProvider() override; | |
| 47 void StopDataProvider() override; | |
| 48 bool GetData(WifiData* data) override; | |
| 49 | |
| 50 protected: | |
| 51 ~WifiDataProviderCommon() override; | |
| 52 | |
| 53 // Returns ownership. | |
| 54 virtual WlanApiInterface* NewWlanApi() = 0; | |
| 55 | |
| 56 // Returns ownership. | |
| 57 virtual WifiPollingPolicy* NewPollingPolicy() = 0; | |
| 58 | |
| 59 private: | |
| 60 // Runs a scan. Calls the callbacks if new data is found. | |
| 61 void DoWifiScanTask(); | |
| 62 | |
| 63 // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. | |
| 64 void ScheduleNextScan(int interval); | |
| 65 | |
| 66 WifiData wifi_data_; | |
| 67 | |
| 68 // Whether we've successfully completed a scan for WiFi data. | |
| 69 bool is_first_scan_complete_; | |
| 70 | |
| 71 // Underlying OS wifi API. | |
| 72 std::unique_ptr<WlanApiInterface> wlan_api_; | |
| 73 | |
| 74 // Controls the polling update interval. | |
| 75 std::unique_ptr<WifiPollingPolicy> polling_policy_; | |
| 76 | |
| 77 // Holder for delayed tasks; takes care of cleanup. | |
| 78 base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon); | |
| 81 }; | |
| 82 | |
| 83 } // namespace device | |
| 84 | |
| 85 #endif // DEVICE_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | |
| OLD | NEW |