| 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 // Provides wifi scan API binding for chromeos, using proprietary APIs. | 5 // Provides wifi scan API binding for chromeos, using proprietary APIs. |
| 6 | 6 |
| 7 #include "device/geolocation/wifi_data_provider_chromeos.h" | 7 #include "device/geolocation/wifi_data_provider_chromeos.h" |
| 8 | 8 |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chromeos/network/geolocation_handler.h" | 15 #include "chromeos/network/geolocation_handler.h" |
| 16 #include "device/geolocation/wifi_data_provider_manager.h" | 16 #include "device/geolocation/wifi_data_provider_manager.h" |
| 17 | 17 |
| 18 namespace device { | 18 namespace device { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // The time periods between successive polls of the wifi data. | 22 // The time periods between successive polls of the wifi data. |
| 23 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s | 23 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s |
| 24 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins | 24 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins |
| 25 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins | 25 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins |
| 26 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s | 26 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 WifiDataProviderChromeOs::WifiDataProviderChromeOs() | 30 WifiDataProviderChromeOs::WifiDataProviderChromeOs() |
| 31 : started_(false), | 31 : started_(false), |
| 32 is_first_scan_complete_(false), | 32 is_first_scan_complete_(false), |
| 33 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 33 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 34 | 34 |
| 35 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { | 35 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() {} |
| 36 } | |
| 37 | 36 |
| 38 void WifiDataProviderChromeOs::StartDataProvider() { | 37 void WifiDataProviderChromeOs::StartDataProvider() { |
| 39 DCHECK(CalledOnClientThread()); | 38 DCHECK(CalledOnClientThread()); |
| 40 | 39 |
| 41 DCHECK(polling_policy_ == NULL); | 40 DCHECK(polling_policy_ == NULL); |
| 42 polling_policy_.reset( | 41 polling_policy_.reset( |
| 43 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds, | 42 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds, |
| 44 kNoChangePollingIntervalMilliseconds, | 43 kNoChangePollingIntervalMilliseconds, |
| 45 kTwoNoChangePollingIntervalMilliseconds, | 44 kTwoNoChangePollingIntervalMilliseconds, |
| 46 kNoWifiPollingIntervalMilliseconds>); | 45 kNoWifiPollingIntervalMilliseconds>); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 139 |
| 141 bool WifiDataProviderChromeOs::GetAccessPointData( | 140 bool WifiDataProviderChromeOs::GetAccessPointData( |
| 142 WifiData::AccessPointDataSet* result) { | 141 WifiData::AccessPointDataSet* result) { |
| 143 // If wifi isn't enabled, we've effectively completed the task. | 142 // If wifi isn't enabled, we've effectively completed the task. |
| 144 // Return true to indicate an empty access point list. | 143 // Return true to indicate an empty access point list. |
| 145 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled()) | 144 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled()) |
| 146 return true; | 145 return true; |
| 147 | 146 |
| 148 chromeos::WifiAccessPointVector access_points; | 147 chromeos::WifiAccessPointVector access_points; |
| 149 int64_t age_ms = 0; | 148 int64_t age_ms = 0; |
| 150 if (!chromeos::NetworkHandler::Get()->geolocation_handler()-> | 149 if (!chromeos::NetworkHandler::Get() |
| 151 GetWifiAccessPoints(&access_points, &age_ms)) { | 150 ->geolocation_handler() |
| 151 ->GetWifiAccessPoints(&access_points, &age_ms)) { |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 for (const auto& access_point : access_points) { | 154 for (const auto& access_point : access_points) { |
| 155 AccessPointData ap_data; | 155 AccessPointData ap_data; |
| 156 ap_data.mac_address = base::ASCIIToUTF16(access_point.mac_address); | 156 ap_data.mac_address = base::ASCIIToUTF16(access_point.mac_address); |
| 157 ap_data.radio_signal_strength = access_point.signal_strength; | 157 ap_data.radio_signal_strength = access_point.signal_strength; |
| 158 ap_data.channel = access_point.channel; | 158 ap_data.channel = access_point.channel; |
| 159 ap_data.signal_to_noise = access_point.signal_to_noise; | 159 ap_data.signal_to_noise = access_point.signal_to_noise; |
| 160 ap_data.ssid = base::UTF8ToUTF16(access_point.ssid); | 160 ap_data.ssid = base::UTF8ToUTF16(access_point.ssid); |
| 161 result->insert(ap_data); | 161 result->insert(ap_data); |
| 162 } | 162 } |
| 163 // If the age is significantly longer than our long polling time, assume the | 163 // If the age is significantly longer than our long polling time, assume the |
| 164 // data is stale and return false which will trigger a faster update. | 164 // data is stale and return false which will trigger a faster update. |
| 165 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2) | 165 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2) |
| 166 return false; | 166 return false; |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 WifiDataProvider* WifiDataProviderManager::DefaultFactoryFunction() { | 171 WifiDataProvider* WifiDataProviderManager::DefaultFactoryFunction() { |
| 172 return new WifiDataProviderChromeOs(); | 172 return new WifiDataProviderChromeOs(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace device | 175 } // namespace device |
| OLD | NEW |