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 CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | |
6 #define CONTENT_BROWSER_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 "content/browser/geolocation/wifi_data_provider.h" | |
18 #include "content/browser/geolocation/wifi_polling_policy.h" | |
19 #include "content/common/content_export.h" | |
20 | |
21 namespace content { | |
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 CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProvider { | |
32 public: | |
33 // Interface to abstract the low level data OS library call, and to allow | |
34 // mocking (hence public). | |
35 class WlanApiInterface { | |
36 public: | |
37 virtual ~WlanApiInterface() {} | |
38 // Gets wifi data for all visible access points. | |
39 virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0; | |
40 }; | |
41 | |
42 WifiDataProviderCommon(); | |
43 | |
44 // WifiDataProvider implementation | |
45 void StartDataProvider() override; | |
46 void StopDataProvider() override; | |
47 bool GetData(WifiData* data) override; | |
48 | |
49 protected: | |
50 ~WifiDataProviderCommon() override; | |
51 | |
52 // Returns ownership. | |
53 virtual WlanApiInterface* NewWlanApi() = 0; | |
54 | |
55 // Returns ownership. | |
56 virtual WifiPollingPolicy* NewPollingPolicy() = 0; | |
57 | |
58 private: | |
59 // Runs a scan. Calls the callbacks if new data is found. | |
60 void DoWifiScanTask(); | |
61 | |
62 // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. | |
63 void ScheduleNextScan(int interval); | |
64 | |
65 WifiData wifi_data_; | |
66 | |
67 // Whether we've successfully completed a scan for WiFi data. | |
68 bool is_first_scan_complete_; | |
69 | |
70 // Underlying OS wifi API. | |
71 std::unique_ptr<WlanApiInterface> wlan_api_; | |
72 | |
73 // Controls the polling update interval. | |
74 std::unique_ptr<WifiPollingPolicy> polling_policy_; | |
75 | |
76 // Holder for delayed tasks; takes care of cleanup. | |
77 base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon); | |
80 }; | |
81 | |
82 } // namespace content | |
83 | |
84 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | |
OLD | NEW |