Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Unified Diff: content/browser/geolocation/wifi_data_provider_chromeos.cc

Issue 6696022: Refactor WifiDataProviderChromeOs to implement WifiDataProviderImplBase directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use the geolocation thread Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d7b88dc59c0a5fa62be42195e8f6a512cf6e2698 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) {
}
WifiDataProviderChromeOs::~WifiDataProviderChromeOs() {
}
+bool WifiDataProviderChromeOs::StartDataProvider() {
+ DCHECK(CalledOnClientThread());
+ 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() {
+ DCHECK(CalledOnClientThread());
+ started_ = false;
+ wlan_api_.reset();
+ polling_policy_.reset();
+}
+
+bool WifiDataProviderChromeOs::GetData(WifiData *data) {
bulach 2011/03/16 18:01:00 nit: WifiData* data
John Knottenbelt 2011/03/16 18:20:14 Done.
+ DCHECK(CalledOnClientThread());
+ DCHECK(data);
+ *data = wifi_data_;
+ return is_first_scan_complete_;
+}
+
WifiDataProviderCommon::WlanApiInterface*
WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) {
return new chromeos::NetworkLibraryWlanApi(lib);
@@ -98,3 +136,46 @@ PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() {
kTwoNoChangePollingIntervalMilliseconds,
kNoWifiPollingIntervalMilliseconds>;
}
+
+void WifiDataProviderChromeOs::DoWifiScanTask() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ scoped_ptr<WifiData> new_data(new WifiData);
+ if (!wlan_api_->GetAccessPointData(&new_data->access_point_data))
+ new_data.reset();
+
+ client_loop_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &WifiDataProviderChromeOs::DidWifiScanTask,
+ new_data.release()));
bulach 2011/03/16 18:01:00 heh, the thing is that whilst in flight, new_data
John Knottenbelt 2011/03/16 18:20:14 Done.
+}
+
+void WifiDataProviderChromeOs::DidWifiScanTask(WifiData* new_data) {
bulach 2011/03/16 18:01:00 and this can be come a const WifiData& new_data
John Knottenbelt 2011/03/16 18:20:14 Done.
+ DCHECK(CalledOnClientThread());
+ scoped_ptr<WifiData> delete_new_data(new_data);
+
+ bool update_available = false;
+ if (!new_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) {
+ DCHECK(CalledOnClientThread());
+ if (started_) {
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ NewRunnableMethod(this,
+ &WifiDataProviderChromeOs::DoWifiScanTask),
+ interval);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698