Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ |
| 6 #define CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/basictypes.h" | 12 #include "base/task.h" |
| 13 #include "base/thread.h" | |
| 14 #include "chrome/browser/geolocation/device_data_provider.h" | |
| 13 | 15 |
| 14 // Converts a MAC address stored as an array of uint8 to a string. | 16 // Converts a MAC address stored as an array of uint8 to a string. |
| 15 string16 MacAddressAsString16(const uint8 mac_as_int[6]); | 17 string16 MacAddressAsString16(const uint8 mac_as_int[6]); |
| 16 | 18 |
| 17 // Allows sharing and mocking of the update polling policy function. | 19 // Allows sharing and mocking of the update polling policy function. |
| 18 class PollingPolicyInterface { | 20 class PollingPolicyInterface { |
| 19 public: | 21 public: |
| 20 virtual ~PollingPolicyInterface() {} | 22 virtual ~PollingPolicyInterface() {} |
| 21 // Calculates the new polling interval for wiFi scans, given the previous | 23 // Calculates the new polling interval for wiFi scans, given the previous |
| 22 // interval and whether the last scan produced new results. | 24 // interval and whether the last scan produced new results. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 43 polling_interval_ == TWO_NO_CHANGE_INTERVAL); | 45 polling_interval_ == TWO_NO_CHANGE_INTERVAL); |
| 44 polling_interval_ = TWO_NO_CHANGE_INTERVAL; | 46 polling_interval_ = TWO_NO_CHANGE_INTERVAL; |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 virtual int PollingInterval() { return polling_interval_; } | 49 virtual int PollingInterval() { return polling_interval_; } |
| 48 | 50 |
| 49 private: | 51 private: |
| 50 int polling_interval_; | 52 int polling_interval_; |
| 51 }; | 53 }; |
| 52 | 54 |
| 55 // Base class to promote code sharing between platform specific wifi data | |
| 56 // providers. It's optional for specific platforms to derive this, but if they | |
| 57 // do threading and polling is taken care of by this base class, and all the | |
| 58 // platform need do is provide the underlying WLAN access API and policy policy, | |
| 59 // both of which will be create & accessed in the worker thread (only). | |
| 60 // Also designed this way to promotes ease of testing the cross-platform | |
| 61 // behavior w.r.t. polling & threading. | |
| 62 class WifiDataProviderCommon | |
| 63 : public WifiDataProviderImplBase, | |
| 64 private base::Thread { | |
| 65 public: | |
| 66 // Interface to abstract the low level data OS library call, and to allow | |
| 67 // mocking (hence public). | |
| 68 class WlanApiInterface { | |
| 69 public: | |
| 70 virtual ~WlanApiInterface() {} | |
| 71 // Gets wifi data for all visible access points. | |
| 72 virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0; | |
| 73 }; | |
| 74 | |
| 75 WifiDataProviderCommon(); | |
| 76 | |
| 77 // WifiDataProviderImplBase implementation | |
| 78 virtual bool StartDataProvider(); | |
| 79 virtual void StopDataProvider(); | |
| 80 virtual bool GetData(WifiData *data); | |
| 81 | |
| 82 protected: | |
| 83 virtual ~WifiDataProviderCommon(); | |
| 84 | |
| 85 // Returns ownership. Will be called from the worker thread. | |
| 86 virtual WlanApiInterface* NewWlanApi() = 0; | |
| 87 | |
| 88 // Returns ownership. Will be called from the worker thread. | |
| 89 virtual PollingPolicyInterface* NewPolicyPolicy() = 0; | |
| 90 | |
| 91 private: | |
| 92 // Thread implementation | |
| 93 virtual void Init(); | |
| 94 virtual void CleanUp(); | |
| 95 | |
| 96 // Task which run in the child thread. | |
| 97 void DoWifiScanTask(); | |
| 98 | |
| 99 // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. | |
| 100 void ScheduleNextScan(); | |
| 101 | |
| 102 WifiData wifi_data_; | |
| 103 Lock data_mutex_; | |
| 104 | |
| 105 // Whether we've successfully completed a scan for WiFi data (or the polling | |
| 106 // thread has terminated early). | |
| 107 bool is_first_scan_complete_; | |
| 108 | |
| 109 // Underlying OS wifi API. | |
| 110 scoped_ptr<WlanApiInterface> wlan_api_; | |
| 111 | |
| 112 // Controls the polling update interval. | |
| 113 scoped_ptr<PollingPolicyInterface> polling_policy_; | |
| 114 | |
| 115 // Holder for the tasks which run on the thread; takes care of cleanup. | |
| 116 ScopedRunnableMethodFactory<WifiDataProviderCommon> task_factory_; | |
| 117 | |
| 118 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon); | |
| 119 }; | |
| 120 | |
|
jorlow
2010/02/14 22:09:27
2 newlines
joth
2010/02/15 11:28:54
Done.
| |
| 121 | |
| 53 #endif // CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ | 122 #endif // CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ |
| OLD | NEW |