| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/geolocation/wifi_data_provider_chromeos.h" | 7 #include "chrome/browser/geolocation/wifi_data_provider_chromeos.h" |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 11 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
| 12 #include "content/browser/browser_thread.h" | 12 #include "content/browser/browser_thread.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 // The time periods between successive polls of the wifi data. | 15 // The time periods between successive polls of the wifi data. |
| 16 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s | 16 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s |
| 17 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins | 17 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins |
| 18 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins | 18 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins |
| 19 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s | 19 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s |
| 20 |
| 21 WifiDataProviderImplBase* ChromeOSFactoryFunction() { |
| 22 return new WifiDataProviderChromeOs(); |
| 20 } | 23 } |
| 21 | 24 |
| 25 // This global class forces code that links in this file to use that as a data |
| 26 // provider instead of the default Linux provider. |
| 27 class RegisterChromeOSWifiDataProvider { |
| 28 public: |
| 29 RegisterChromeOSWifiDataProvider() { |
| 30 WifiDataProvider::SetFactory(ChromeOSFactoryFunction); |
| 31 } |
| 32 }; |
| 33 |
| 34 RegisterChromeOSWifiDataProvider g_force_chrome_os_provider; |
| 35 |
| 36 } // namespace |
| 37 |
| 22 namespace chromeos { | 38 namespace chromeos { |
| 23 namespace { | 39 namespace { |
| 24 // Wifi API binding to network_library.h, to allow reuse of the polling behavior | 40 // Wifi API binding to network_library.h, to allow reuse of the polling behavior |
| 25 // defined in WifiDataProviderCommon. | 41 // defined in WifiDataProviderCommon. |
| 26 class NetworkLibraryWlanApi : public WifiDataProviderCommon::WlanApiInterface { | 42 class NetworkLibraryWlanApi : public WifiDataProviderCommon::WlanApiInterface { |
| 27 public: | 43 public: |
| 28 // Does not transfer ownership, |lib| must remain valid for lifetime of | 44 // Does not transfer ownership, |lib| must remain valid for lifetime of |
| 29 // this object. | 45 // this object. |
| 30 explicit NetworkLibraryWlanApi(NetworkLibrary* lib); | 46 explicit NetworkLibraryWlanApi(NetworkLibrary* lib); |
| 31 ~NetworkLibraryWlanApi(); | 47 ~NetworkLibraryWlanApi(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 ap_data.signal_to_noise = i->signal_to_noise; | 77 ap_data.signal_to_noise = i->signal_to_noise; |
| 62 ap_data.ssid = UTF8ToUTF16(i->name); | 78 ap_data.ssid = UTF8ToUTF16(i->name); |
| 63 result->insert(ap_data); | 79 result->insert(ap_data); |
| 64 } | 80 } |
| 65 return !result->empty() || network_library_->wifi_enabled(); | 81 return !result->empty() || network_library_->wifi_enabled(); |
| 66 } | 82 } |
| 67 | 83 |
| 68 } // namespace | 84 } // namespace |
| 69 } // namespace chromeos | 85 } // namespace chromeos |
| 70 | 86 |
| 71 template<> | 87 WifiDataProviderChromeOs::WifiDataProviderChromeOs() : started_(false) { |
| 72 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { | |
| 73 return new WifiDataProviderChromeOs(); | |
| 74 } | |
| 75 | |
| 76 WifiDataProviderChromeOs::WifiDataProviderChromeOs() : | |
| 77 started_(false) { | |
| 78 } | 88 } |
| 79 | 89 |
| 80 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { | 90 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { |
| 81 } | 91 } |
| 82 | 92 |
| 83 bool WifiDataProviderChromeOs::StartDataProvider() { | 93 bool WifiDataProviderChromeOs::StartDataProvider() { |
| 84 DCHECK(CalledOnClientThread()); | 94 DCHECK(CalledOnClientThread()); |
| 85 | 95 |
| 86 DCHECK(polling_policy_ == NULL); | 96 DCHECK(polling_policy_ == NULL); |
| 87 polling_policy_.reset(NewPollingPolicy()); | 97 polling_policy_.reset(NewPollingPolicy()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 163 |
| 154 // This method could be scheduled after a DoStopTaskOnUIThread. | 164 // This method could be scheduled after a DoStopTaskOnUIThread. |
| 155 if (!wlan_api_.get()) | 165 if (!wlan_api_.get()) |
| 156 return; | 166 return; |
| 157 | 167 |
| 158 WifiData new_data; | 168 WifiData new_data; |
| 159 | 169 |
| 160 if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) { | 170 if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) { |
| 161 client_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 171 client_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 162 this, &WifiDataProviderChromeOs::DidWifiScanTaskNoResults)); | 172 this, &WifiDataProviderChromeOs::DidWifiScanTaskNoResults)); |
| 163 } | 173 } else { |
| 164 else { | |
| 165 client_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 174 client_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 166 this, &WifiDataProviderChromeOs::DidWifiScanTask, | 175 this, &WifiDataProviderChromeOs::DidWifiScanTask, |
| 167 new_data)); | 176 new_data)); |
| 168 } | 177 } |
| 169 } | 178 } |
| 170 | 179 |
| 171 void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() { | 180 void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() { |
| 172 DCHECK(CalledOnClientThread()); | 181 DCHECK(CalledOnClientThread()); |
| 173 // Schedule next scan if started (StopDataProvider could have been called | 182 // Schedule next scan if started (StopDataProvider could have been called |
| 174 // in between DoWifiScanTaskOnUIThread and this method). | 183 // in between DoWifiScanTaskOnUIThread and this method). |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 DCHECK(!started_); | 233 DCHECK(!started_); |
| 225 started_ = true; | 234 started_ = true; |
| 226 // Perform first scan ASAP regardless of the polling policy. If this scan | 235 // Perform first scan ASAP regardless of the polling policy. If this scan |
| 227 // fails we'll retry at a rate in line with the polling policy. | 236 // fails we'll retry at a rate in line with the polling policy. |
| 228 BrowserThread::PostTask( | 237 BrowserThread::PostTask( |
| 229 BrowserThread::UI, | 238 BrowserThread::UI, |
| 230 FROM_HERE, | 239 FROM_HERE, |
| 231 NewRunnableMethod(this, | 240 NewRunnableMethod(this, |
| 232 &WifiDataProviderChromeOs::DoStartTaskOnUIThread)); | 241 &WifiDataProviderChromeOs::DoStartTaskOnUIThread)); |
| 233 } | 242 } |
| OLD | NEW |