Index: content/browser/geolocation/wifi_data_provider_chromeos.cc |
diff --git a/content/browser/geolocation/wifi_data_provider_chromeos.cc b/content/browser/geolocation/wifi_data_provider_chromeos.cc |
index 555f7aef7c7f4bb409ba779129cff115a695e475..d98a63a0d050ff1608a9168839dcddd84069ef5c 100644 |
--- a/content/browser/geolocation/wifi_data_provider_chromeos.cc |
+++ b/content/browser/geolocation/wifi_data_provider_chromeos.cc |
@@ -9,6 +9,7 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/chromeos/cros/cros_library.h" |
#include "chrome/browser/chromeos/cros/network_library.h" |
+#include "content/browser/browser_thread.h" |
namespace { |
// The time periods between successive polls of the wifi data. |
@@ -72,12 +73,49 @@ WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { |
return new WifiDataProviderChromeOs(); |
} |
-WifiDataProviderChromeOs::WifiDataProviderChromeOs() { |
+WifiDataProviderChromeOs::WifiDataProviderChromeOs() : |
+ started_(false), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
} |
WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { |
} |
+bool WifiDataProviderChromeOs::StartDataProvider() { |
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
bulach
2011/03/15 18:37:51
hmm, not sure this would work.. afaict, this would
stevenjb
2011/03/16 01:06:26
As bulach@ suggests, this CHECK gets triggered on
|
+ DCHECK(!started_); |
+ started_ = true; |
+ |
+ wlan_api_.reset(NewWlanApi()); |
+ if (wlan_api_ == NULL) { |
+ // Error! Can't do scans, so don't try and schedule one. |
+ is_first_scan_complete_ = true; |
+ return false; |
+ } |
+ |
+ DCHECK(polling_policy_ == NULL); |
+ polling_policy_.reset(NewPollingPolicy()); |
+ DCHECK(polling_policy_ != NULL); |
+ |
+ // Perform first scan ASAP regardless of the polling policy. If this scan |
+ // fails we'll retry at a rate in line with the polling policy. |
+ ScheduleNextScan(0); |
+ return true; |
+} |
+ |
+void WifiDataProviderChromeOs::StopDataProvider() { |
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ started_ = false; |
+ wlan_api_.reset(); |
+ polling_policy_.reset(); |
+} |
+ |
+bool WifiDataProviderChromeOs::GetData(WifiData *data) { |
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ *data = wifi_data_; |
+ return is_first_scan_complete_; |
+} |
+ |
WifiDataProviderCommon::WlanApiInterface* |
WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) { |
return new chromeos::NetworkLibraryWlanApi(lib); |
@@ -98,3 +136,28 @@ PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() { |
kTwoNoChangePollingIntervalMilliseconds, |
kNoWifiPollingIntervalMilliseconds>; |
} |
+ |
+void WifiDataProviderChromeOs::DoWifiScanTask() { |
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ bool update_available = false; |
+ WifiData new_data; |
+ if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) { |
+ ScheduleNextScan(polling_policy_->NoWifiInterval()); |
+ } else { |
+ update_available = wifi_data_.DiffersSignificantly(new_data); |
+ wifi_data_ = new_data; |
+ polling_policy_->UpdatePollingInterval(update_available); |
+ ScheduleNextScan(polling_policy_->PollingInterval()); |
+ } |
+ if (update_available || !is_first_scan_complete_) { |
+ is_first_scan_complete_ = true; |
+ NotifyListeners(); |
+ } |
+} |
+ |
+void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { |
+ MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ task_factory_.NewRunnableMethod(&WifiDataProviderChromeOs::DoWifiScanTask), |
bulach
2011/03/15 18:37:51
nit: >80cols
|
+ interval); |
stevenjb
2011/03/16 01:06:26
I'm still unfamiliar with Chrome threading, but is
|
+} |