| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Provides wifi scan API binding for chromeos, using proprietary APIs. | |
| 6 | |
| 7 #include "content/browser/geolocation/wifi_data_provider_chromeos.h" | |
| 8 | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 11 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 12 | |
| 13 namespace { | |
| 14 // The time periods between successive polls of the wifi data. | |
| 15 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s | |
| 16 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins | |
| 17 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins | |
| 18 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s | |
| 19 } | |
| 20 | |
| 21 namespace chromeos { | |
| 22 namespace { | |
| 23 // Wifi API binding to network_library.h, to allow reuse of the polling behavior | |
| 24 // defined in WifiDataProviderCommon. | |
| 25 class NetworkLibraryWlanApi : public WifiDataProviderCommon::WlanApiInterface { | |
| 26 public: | |
| 27 // Does not transfer ownership, |lib| must remain valid for lifetime of | |
| 28 // this object. | |
| 29 explicit NetworkLibraryWlanApi(NetworkLibrary* lib); | |
| 30 ~NetworkLibraryWlanApi(); | |
| 31 | |
| 32 // WifiDataProviderCommon::WlanApiInterface | |
| 33 bool GetAccessPointData(WifiData::AccessPointDataSet* data); | |
| 34 | |
| 35 private: | |
| 36 NetworkLibrary* network_library_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryWlanApi); | |
| 39 }; | |
| 40 | |
| 41 NetworkLibraryWlanApi::NetworkLibraryWlanApi(NetworkLibrary* lib) | |
| 42 : network_library_(lib) { | |
| 43 DCHECK(network_library_ != NULL); | |
| 44 } | |
| 45 | |
| 46 NetworkLibraryWlanApi::~NetworkLibraryWlanApi() { | |
| 47 } | |
| 48 | |
| 49 bool NetworkLibraryWlanApi::GetAccessPointData( | |
| 50 WifiData::AccessPointDataSet* result) { | |
| 51 WifiAccessPointVector access_points; | |
| 52 if (!network_library_->GetWifiAccessPoints(&access_points)) | |
| 53 return false; | |
| 54 for (WifiAccessPointVector::const_iterator i = access_points.begin(); | |
| 55 i != access_points.end(); ++i) { | |
| 56 AccessPointData ap_data; | |
| 57 ap_data.mac_address = ASCIIToUTF16(i->mac_address); | |
| 58 ap_data.radio_signal_strength = i->signal_strength; | |
| 59 ap_data.channel = i->channel; | |
| 60 ap_data.signal_to_noise = i->signal_to_noise; | |
| 61 ap_data.ssid = UTF8ToUTF16(i->name); | |
| 62 result->insert(ap_data); | |
| 63 } | |
| 64 return !result->empty() || network_library_->wifi_enabled(); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 } // namespace chromeos | |
| 69 | |
| 70 template<> | |
| 71 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { | |
| 72 return new WifiDataProviderChromeOs(); | |
| 73 } | |
| 74 | |
| 75 WifiDataProviderChromeOs::WifiDataProviderChromeOs() { | |
| 76 } | |
| 77 | |
| 78 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { | |
| 79 } | |
| 80 | |
| 81 WifiDataProviderCommon::WlanApiInterface* | |
| 82 WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) { | |
| 83 return new chromeos::NetworkLibraryWlanApi(lib); | |
| 84 } | |
| 85 | |
| 86 WifiDataProviderCommon::WlanApiInterface* | |
| 87 WifiDataProviderChromeOs::NewWlanApi() { | |
| 88 chromeos::CrosLibrary* cros_lib = chromeos::CrosLibrary::Get(); | |
| 89 DCHECK(cros_lib); | |
| 90 if (!cros_lib->EnsureLoaded()) | |
| 91 return NULL; | |
| 92 return NewWlanApi(cros_lib->GetNetworkLibrary()); | |
| 93 } | |
| 94 | |
| 95 PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() { | |
| 96 return new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds, | |
| 97 kNoChangePollingIntervalMilliseconds, | |
| 98 kTwoNoChangePollingIntervalMilliseconds, | |
| 99 kNoWifiPollingIntervalMilliseconds>; | |
| 100 } | |
| OLD | NEW |