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

Unified Diff: device/geolocation/wifi_data_provider_chromeos.cc

Issue 2584733002: WifiDataProviderChromeOs: Call NetworkHandler from correct task runner. (Closed)
Patch Set: Rebase + Elim unnecessary headers Created 4 years 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
« no previous file with comments | « device/geolocation/wifi_data_provider_chromeos.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/geolocation/wifi_data_provider_chromeos.cc
diff --git a/device/geolocation/wifi_data_provider_chromeos.cc b/device/geolocation/wifi_data_provider_chromeos.cc
index aef72ae3758e120d044dffd04b63b34731e43536..c8bbbf347b45c9a0ad2cff2ebf309a07854f1155 100644
--- a/device/geolocation/wifi_data_provider_chromeos.cc
+++ b/device/geolocation/wifi_data_provider_chromeos.cc
@@ -9,12 +9,13 @@
#include <stdint.h>
#include "base/bind.h"
-#include "base/single_thread_task_runner.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/threading/thread_task_runner_handle.h"
#include "chromeos/network/geolocation_handler.h"
+#include "chromeos/network/network_handler.h"
#include "device/geolocation/wifi_data_provider_manager.h"
+using chromeos::NetworkHandler;
+
namespace device {
namespace {
@@ -28,16 +29,14 @@ const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s
} // namespace
WifiDataProviderChromeOs::WifiDataProviderChromeOs()
- : started_(false),
- is_first_scan_complete_(false),
- main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+ : started_(false), is_first_scan_complete_(false) {}
WifiDataProviderChromeOs::~WifiDataProviderChromeOs() {}
void WifiDataProviderChromeOs::StartDataProvider() {
DCHECK(CalledOnClientThread());
- DCHECK(polling_policy_ == NULL);
+ DCHECK(polling_policy_ == nullptr);
polling_policy_.reset(
new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds,
kNoChangePollingIntervalMilliseconds,
@@ -61,14 +60,7 @@ bool WifiDataProviderChromeOs::GetData(WifiData* data) {
return is_first_scan_complete_;
}
-void WifiDataProviderChromeOs::DoStartTaskOnUIThread() {
- CHECK(main_task_runner_->BelongsToCurrentThread());
- DoWifiScanTaskOnUIThread();
-}
-
-void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() {
- CHECK(main_task_runner_->BelongsToCurrentThread());
-
+void WifiDataProviderChromeOs::DoWifiScanTaskOnNetworkHandlerThread() {
// This method could be scheduled after a ScheduleStop.
if (!started_)
return;
@@ -89,7 +81,7 @@ void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() {
void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() {
DCHECK(CalledOnClientThread());
// Schedule next scan if started (StopDataProvider could have been called
- // in between DoWifiScanTaskOnUIThread and this method).
+ // in between DoWifiScanTaskOnNetworkHandlerThread and this method).
if (started_)
ScheduleNextScan(polling_policy_->NoWifiInterval());
}
@@ -99,7 +91,7 @@ void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) {
bool update_available = wifi_data_.DiffersSignificantly(new_data);
wifi_data_ = new_data;
// Schedule next scan if started (StopDataProvider could have been called
- // in between DoWifiScanTaskOnUIThread and this method).
+ // in between DoWifiScanTaskOnNetworkHandlerThread and this method).
if (started_) {
polling_policy_->UpdatePollingInterval(update_available);
ScheduleNextScan(polling_policy_->PollingInterval());
@@ -114,9 +106,15 @@ void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) {
void WifiDataProviderChromeOs::ScheduleNextScan(int interval) {
DCHECK(CalledOnClientThread());
DCHECK(started_);
- main_task_runner_->PostDelayedTask(
+ if (!NetworkHandler::IsInitialized()) {
+ LOG(ERROR) << "ScheduleNextScan called with uninitialized NetworkHandler";
+ return;
+ }
+ NetworkHandler::Get()->task_runner()->PostDelayedTask(
FROM_HERE,
- base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this),
+ base::Bind(
+ &WifiDataProviderChromeOs::DoWifiScanTaskOnNetworkHandlerThread,
+ this),
base::TimeDelta::FromMilliseconds(interval));
}
@@ -129,23 +127,31 @@ void WifiDataProviderChromeOs::ScheduleStop() {
void WifiDataProviderChromeOs::ScheduleStart() {
DCHECK(CalledOnClientThread());
DCHECK(!started_);
+ if (!NetworkHandler::IsInitialized()) {
+ LOG(ERROR) << "ScheduleStart called with uninitialized NetworkHandler";
+ return;
+ }
started_ = true;
// 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.
- main_task_runner_->PostTask(
+ NetworkHandler::Get()->task_runner()->PostTask(
FROM_HERE,
- base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this));
+ base::Bind(
+ &WifiDataProviderChromeOs::DoWifiScanTaskOnNetworkHandlerThread,
+ this));
}
bool WifiDataProviderChromeOs::GetAccessPointData(
WifiData::AccessPointDataSet* result) {
- // If in startup or shutdown, chromeos::NetworkHandler is uninitialized.
- if (!chromeos::NetworkHandler::IsInitialized())
+ // If in startup or shutdown, NetworkHandler is uninitialized.
+ if (!NetworkHandler::IsInitialized())
return false; // Data not ready.
+ DCHECK(NetworkHandler::Get()->task_runner()->BelongsToCurrentThread());
+
// If wifi isn't enabled, we've effectively completed the task.
chromeos::GeolocationHandler* const geolocation_handler =
- chromeos::NetworkHandler::Get()->geolocation_handler();
+ NetworkHandler::Get()->geolocation_handler();
if (!geolocation_handler || !geolocation_handler->wifi_enabled())
return true; // Access point list is empty, no more data.
« no previous file with comments | « device/geolocation/wifi_data_provider_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698