| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "device/geolocation/wifi_data_provider_common.h" | 5 #include "device/geolocation/wifi_data_provider_common.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 mac_as_int[3], mac_as_int[4], mac_as_int[5])); | 21 mac_as_int[3], mac_as_int[4], mac_as_int[5])); |
| 22 } | 22 } |
| 23 | 23 |
| 24 WifiDataProviderCommon::WifiDataProviderCommon() | 24 WifiDataProviderCommon::WifiDataProviderCommon() |
| 25 : is_first_scan_complete_(false), weak_factory_(this) {} | 25 : is_first_scan_complete_(false), weak_factory_(this) {} |
| 26 | 26 |
| 27 WifiDataProviderCommon::~WifiDataProviderCommon() {} | 27 WifiDataProviderCommon::~WifiDataProviderCommon() {} |
| 28 | 28 |
| 29 void WifiDataProviderCommon::StartDataProvider() { | 29 void WifiDataProviderCommon::StartDataProvider() { |
| 30 DCHECK(!wlan_api_); | 30 DCHECK(!wlan_api_); |
| 31 wlan_api_.reset(NewWlanApi()); | 31 wlan_api_ = CreateWlanApi(); |
| 32 if (!wlan_api_) { | 32 if (!wlan_api_) { |
| 33 // Error! Can't do scans, so don't try and schedule one. | 33 // Error! Can't do scans, so don't try and schedule one. |
| 34 is_first_scan_complete_ = true; | 34 is_first_scan_complete_ = true; |
| 35 return; | 35 return; |
| 36 } | 36 } |
| 37 | 37 |
| 38 DCHECK(!polling_policy_); | 38 DCHECK(!polling_policy_); |
| 39 polling_policy_.reset(NewPollingPolicy()); | 39 polling_policy_ = CreatePollingPolicy(); |
| 40 DCHECK(polling_policy_); | 40 DCHECK(polling_policy_); |
| 41 | 41 |
| 42 // Perform first scan ASAP regardless of the polling policy. If this scan | 42 // Perform first scan ASAP regardless of the polling policy. If this scan |
| 43 // fails we'll retry at a rate in line with the polling policy. | 43 // fails we'll retry at a rate in line with the polling policy. |
| 44 ScheduleNextScan(0); | 44 ScheduleNextScan(0); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void WifiDataProviderCommon::StopDataProvider() { | 47 void WifiDataProviderCommon::StopDataProvider() { |
| 48 wlan_api_.reset(); | 48 wlan_api_.reset(); |
| 49 polling_policy_.reset(); | 49 polling_policy_.reset(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 void WifiDataProviderCommon::ScheduleNextScan(int interval) { | 76 void WifiDataProviderCommon::ScheduleNextScan(int interval) { |
| 77 client_task_runner()->PostDelayedTask( | 77 client_task_runner()->PostDelayedTask( |
| 78 FROM_HERE, base::Bind(&WifiDataProviderCommon::DoWifiScanTask, | 78 FROM_HERE, base::Bind(&WifiDataProviderCommon::DoWifiScanTask, |
| 79 weak_factory_.GetWeakPtr()), | 79 weak_factory_.GetWeakPtr()), |
| 80 base::TimeDelta::FromMilliseconds(interval)); | 80 base::TimeDelta::FromMilliseconds(interval)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace device | 83 } // namespace device |
| OLD | NEW |