diff options
Diffstat (limited to 'chrome/browser/geolocation/wifi_data_provider_common.h')
-rw-r--r-- | chrome/browser/geolocation/wifi_data_provider_common.h | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/chrome/browser/geolocation/wifi_data_provider_common.h b/chrome/browser/geolocation/wifi_data_provider_common.h index 9836b42..9d428f3 100644 --- a/chrome/browser/geolocation/wifi_data_provider_common.h +++ b/chrome/browser/geolocation/wifi_data_provider_common.h @@ -9,7 +9,9 @@ #include "base/logging.h" #include "base/string16.h" -#include "base/basictypes.h" +#include "base/task.h" +#include "base/thread.h" +#include "chrome/browser/geolocation/device_data_provider.h" // Converts a MAC address stored as an array of uint8 to a string. string16 MacAddressAsString16(const uint8 mac_as_int[6]); @@ -50,4 +52,71 @@ class GenericPollingPolicy : public PollingPolicyInterface { int polling_interval_; }; +// Base class to promote code sharing between platform specific wifi data +// providers. It's optional for specific platforms to derive this, but if they +// do threading and polling is taken care of by this base class, and all the +// platform need do is provide the underlying WLAN access API and policy policy, +// both of which will be create & accessed in the worker thread (only). +// Also designed this way to promotes ease of testing the cross-platform +// behavior w.r.t. polling & threading. +class WifiDataProviderCommon + : public WifiDataProviderImplBase, + private base::Thread { + public: + // Interface to abstract the low level data OS library call, and to allow + // mocking (hence public). + class WlanApiInterface { + public: + virtual ~WlanApiInterface() {} + // Gets wifi data for all visible access points. + virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0; + }; + + WifiDataProviderCommon(); + + // WifiDataProviderImplBase implementation + virtual bool StartDataProvider(); + virtual void StopDataProvider(); + virtual bool GetData(WifiData *data); + + protected: + virtual ~WifiDataProviderCommon(); + + // Returns ownership. Will be called from the worker thread. + virtual WlanApiInterface* NewWlanApi() = 0; + + // Returns ownership. Will be called from the worker thread. + virtual PollingPolicyInterface* NewPolicyPolicy() = 0; + + private: + // Thread implementation + virtual void Init(); + virtual void CleanUp(); + + // Task which run in the child thread. + void DoWifiScanTask(); + + // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. + void ScheduleNextScan(); + + WifiData wifi_data_; + Lock data_mutex_; + + // Whether we've successfully completed a scan for WiFi data (or the polling + // thread has terminated early). + bool is_first_scan_complete_; + + // Underlying OS wifi API. + scoped_ptr<WlanApiInterface> wlan_api_; + + // Controls the polling update interval. + scoped_ptr<PollingPolicyInterface> polling_policy_; + + // Holder for the tasks which run on the thread; takes care of cleanup. + ScopedRunnableMethodFactory<WifiDataProviderCommon> task_factory_; + + DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon); +}; + + #endif // CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ |