diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 13:45:43 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-21 13:45:43 +0000 |
commit | 3cc2e593f52cc27ca6694b6ec33f769f6d2dbd52 (patch) | |
tree | 39bd70a7c63982c1fd76fb61fc91e4fc23d6ee16 | |
parent | 3fd9dae0d14e2a5ec30f738defb1811825740755 (diff) | |
download | chromium_src-3cc2e593f52cc27ca6694b6ec33f769f6d2dbd52.zip chromium_src-3cc2e593f52cc27ca6694b6ec33f769f6d2dbd52.tar.gz chromium_src-3cc2e593f52cc27ca6694b6ec33f769f6d2dbd52.tar.bz2 |
Adds wifi mac addresses and cell IDs to the corresponding network library classes.
Adds basic support to Chrome for using the wifi API, and basic test.
Does not yet provide concrete implementation of the underlying methods, this will be in follow-up CLs once I have ChromeOS device.
BUG=45671
TEST=GeolocationChromeOsWifiDataProviderTest.*
Review URL: http://codereview.chromium.org/2769007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50345 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/network_library.h | 52 | ||||
-rw-r--r-- | chrome/browser/geolocation/wifi_data_provider_chromeos.cc | 98 | ||||
-rw-r--r-- | chrome/browser/geolocation/wifi_data_provider_chromeos.h | 33 | ||||
-rw-r--r-- | chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc | 77 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 1 |
7 files changed, 278 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index cd4bd45..cc1194e 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -154,6 +154,19 @@ void WirelessNetwork::ConfigureFromService(const ServiceInfo& service) { } //////////////////////////////////////////////////////////////////////////////// +// CellularNetwork + +void CellularNetwork::Clear() { + WirelessNetwork::Clear(); + cell_towers_.clear(); +} + +void CellularNetwork::ConfigureFromService(const ServiceInfo& service) { + WirelessNetwork::ConfigureFromService(service); + // TODO(joth): Update |cell_towers_| once ChromeOS side is implemented. +} + +//////////////////////////////////////////////////////////////////////////////// // WifiNetwork void WifiNetwork::Clear() { @@ -162,6 +175,7 @@ void WifiNetwork::Clear() { passphrase_.clear(); identity_.clear(); cert_path_.clear(); + access_points_.clear(); } void WifiNetwork::ConfigureFromService(const ServiceInfo& service) { @@ -170,6 +184,7 @@ void WifiNetwork::ConfigureFromService(const ServiceInfo& service) { passphrase_ = service.passphrase; identity_ = service.identity; cert_path_ = service.cert_path; + // TODO(joth): Update |access_points_| once ChromeOS side is implemented. } std::string WifiNetwork::GetEncryptionString() { diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 1f00132..d68aeb2 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -101,15 +101,56 @@ class WirelessNetwork : public Network { class CellularNetwork : public WirelessNetwork { public: + struct CellTower { + enum RadioType { + RADIOTYPE_GSM, + RADIOTYPE_CDMA, + RADIOTYPE_WCDMA, + } radio_type; // GSM/WCDMA CDMA + int mobile_country_code; // MCC MCC + int mobile_network_code; // MNC SID + int location_area_code; // LAC NID + int cell_id; // CID BID + base::Time timestamp; // Timestamp when this cell was primary + int signal_strength; // Radio signal strength measured in dBm. + int timing_advance; // Represents the distance from the cell tower. Each + // unit is roughly 550 meters. + }; + typedef std::vector<CellTower> CellTowerVector; + CellularNetwork() : WirelessNetwork() {} explicit CellularNetwork(const ServiceInfo& service) : WirelessNetwork() { ConfigureFromService(service); } + // Returns list of recently visible cell towers for this network. If the + // network is not visible (e.g. if this object was obtained from a remembered + // networks call) then this list will be empty. + // TODO(joth): Provide implementation in NetworkLibraryImpl to fill this. + const std::vector<CellTower>& cell_towers() const { return cell_towers_; } + void set_cell_towers(const std::vector<CellTower>& cell_towers) { + cell_towers_ = cell_towers; + } + + // WirelessNetwork overrides. + virtual void Clear(); + virtual void ConfigureFromService(const ServiceInfo& service); + + protected: + std::vector<CellTower> cell_towers_; }; class WifiNetwork : public WirelessNetwork { public: + struct AccessPoint { + std::string mac_address; // The mac address of the WiFi node. + base::Time timestamp; // Timestamp when this AP was detected. + int signal_strength; // Radio signal strength measured in dBm. + int signal_to_noise; // Current signal to noise ratio measured in dB. + int channel; // Wifi channel number. + }; + typedef std::vector<AccessPoint> AccessPointVector; + WifiNetwork() : WirelessNetwork(), encryption_(SECURITY_NONE) {} @@ -136,6 +177,16 @@ class WifiNetwork : public WirelessNetwork { void set_cert_path(const std::string& cert_path) { cert_path_ = cert_path; } + // Returns list of recently visible access points (base stations) for this + // network. If the network is not visible (e.g. if this object was obtained + // from a remembered networks call) then this list will be empty. + // TODO(joth): Provide implementation in NetworkLibraryImpl to fill this. + const std::vector<AccessPoint>& access_points() const { + return access_points_; + } + void set_access_points(const std::vector<AccessPoint>& access_points) { + access_points_ = access_points; + } // WirelessNetwork overrides. virtual void Clear(); @@ -150,6 +201,7 @@ class WifiNetwork : public WirelessNetwork { std::string passphrase_; std::string identity_; std::string cert_path_; + std::vector<AccessPoint> access_points_; }; typedef std::vector<WifiNetwork> WifiNetworkVector; diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc new file mode 100644 index 0000000..41097d3 --- /dev/null +++ b/chrome/browser/geolocation/wifi_data_provider_chromeos.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Provides wifi scan API binding for chromeos, using proprietary APIs. + +#include "chrome/browser/geolocation/wifi_data_provider_chromeos.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/chromeos/cros/network_library.h" + +namespace { +// The time periods between successive polls of the wifi data. +const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s +const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins +const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins +} + +namespace chromeos { +namespace { +// Wifi API binding to network_library.h, to allow reuse of the polling behavior +// defined in WifiDataProviderCommon. +class NetworkLibraryWlanApi : public WifiDataProviderCommon::WlanApiInterface { + public: + // Does not transfer ownership, |lib| must remain valid for lifetime of + // this object. + explicit NetworkLibraryWlanApi(NetworkLibrary* lib); + ~NetworkLibraryWlanApi(); + + // WifiDataProviderCommon::WlanApiInterface + bool GetAccessPointData(WifiData::AccessPointDataSet* data); + + private: + NetworkLibrary* network_library_; + + DISALLOW_COPY_AND_ASSIGN(NetworkLibraryWlanApi); +}; + +NetworkLibraryWlanApi::NetworkLibraryWlanApi(NetworkLibrary* lib) + : network_library_(lib) { + DCHECK(network_library_ != NULL); +} + +NetworkLibraryWlanApi::~NetworkLibraryWlanApi() { +} + +bool NetworkLibraryWlanApi::GetAccessPointData( + WifiData::AccessPointDataSet* data) { + const WifiNetworkVector& networks = network_library_->wifi_networks(); + for (WifiNetworkVector::const_iterator i = networks.begin(); + i != networks.end(); ++i) { + for (WifiNetwork::AccessPointVector::const_iterator j = + i->access_points().begin(); j != i->access_points().end(); ++j) { + AccessPointData ap_data; + ap_data.mac_address = ASCIIToUTF16(j->mac_address); + ap_data.radio_signal_strength = j->signal_strength; + ap_data.channel = j->channel; + ap_data.signal_to_noise = j->signal_to_noise; + ap_data.ssid = UTF8ToUTF16(i->name()); + data->insert(ap_data); + } + } + return !data->empty() || network_library_->wifi_available(); +} + +} // namespace +} // namespace chromeos + +template<> +WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { + return new WifiDataProviderChromeOs(); +} + +WifiDataProviderChromeOs::WifiDataProviderChromeOs() { +} + +WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { +} + +WifiDataProviderCommon::WlanApiInterface* + WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) { + return new chromeos::NetworkLibraryWlanApi(lib); +} + +WifiDataProviderCommon::WlanApiInterface* + WifiDataProviderChromeOs::NewWlanApi() { + if (network_library_ == NULL) { + network_library_.reset(new chromeos::NetworkLibraryImpl()); + // TODO(joth): Check net_lib loaded ok, if not return NULL. + } + return NewWlanApi(network_library_.get()); +} + +PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() { + return new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds, + kNoChangePollingIntervalMilliseconds, + kTwoNoChangePollingIntervalMilliseconds>; +} diff --git a/chrome/browser/geolocation/wifi_data_provider_chromeos.h b/chrome/browser/geolocation/wifi_data_provider_chromeos.h new file mode 100644 index 0000000..0e041e9 --- /dev/null +++ b/chrome/browser/geolocation/wifi_data_provider_chromeos.h @@ -0,0 +1,33 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ +#define CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ + +#include "chrome/browser/geolocation/wifi_data_provider_common.h" + +#include "base/scoped_ptr.h" + +namespace chromeos { class NetworkLibrary; } + +class WifiDataProviderChromeOs : public WifiDataProviderCommon { + public: + WifiDataProviderChromeOs(); + + // Allows injection of |lib| for testing. + static WlanApiInterface* NewWlanApi(chromeos::NetworkLibrary* lib); + + private: + virtual ~WifiDataProviderChromeOs(); + + // WifiDataProviderCommon + virtual WlanApiInterface* NewWlanApi(); + virtual PollingPolicyInterface* NewPollingPolicy(); + + scoped_ptr<chromeos::NetworkLibrary> network_library_; + + DISALLOW_COPY_AND_ASSIGN(WifiDataProviderChromeOs); +}; + +#endif // CHROME_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ diff --git a/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc b/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc new file mode 100644 index 0000000..ca31a21 --- /dev/null +++ b/chrome/browser/geolocation/wifi_data_provider_unittest_chromeos.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/geolocation/wifi_data_provider_chromeos.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/chromeos/cros/mock_network_library.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::Return; +using ::testing::ReturnRef; + +namespace chromeos { + +class GeolocationChromeOsWifiDataProviderTest : public testing::Test { + protected: + GeolocationChromeOsWifiDataProviderTest() + : api_(WifiDataProviderChromeOs::NewWlanApi(&net_lib_)){} + virtual void SetUp() { + EXPECT_CALL(net_lib_, wifi_networks()) + .WillOnce(ReturnRef(wifi_network_data_)); + } + void AddWifiAps(int ssids, int aps_per_ssid) { + for (int i = 0; i < ssids; ++i) { + WifiNetwork network; + network.set_name(StringPrintf("SSID %d", i)); + std::vector<WifiNetwork::AccessPoint> aps; + for (int j = 0; j < aps_per_ssid; ++j) { + WifiNetwork::AccessPoint ap; + ap.channel = i * 10 + j; + ap.mac_address = StringPrintf("%02X:%02X:%02X:%02X:%02X:%02X", + i, j, 3, 4, 5, 6); + ap.signal_strength = j; + ap.signal_to_noise = i; + aps.push_back(ap); + } + network.set_access_points(aps); + wifi_network_data_.push_back(network); + } + } + + chromeos::MockNetworkLibrary net_lib_; + scoped_ptr<WifiDataProviderCommon::WlanApiInterface> api_; + WifiNetworkVector wifi_network_data_; + WifiData::AccessPointDataSet ap_data_; +}; + +TEST_F(GeolocationChromeOsWifiDataProviderTest, NoWifiAvailable) { + EXPECT_CALL(net_lib_, wifi_available()) + .WillRepeatedly(Return(false)); + EXPECT_FALSE(api_->GetAccessPointData(&ap_data_)); + EXPECT_EQ(0u, ap_data_.size()); +} + +TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPointsInRange) { + EXPECT_CALL(net_lib_, wifi_available()) + .WillRepeatedly(Return(true)); + EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); + EXPECT_EQ(0u, ap_data_.size()); +} + +TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) { + AddWifiAps(1, 1); + EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); + EXPECT_EQ(1u, ap_data_.size()); + EXPECT_EQ("00:00:03:04:05:06", UTF16ToUTF8(ap_data_.begin()->mac_address)); + EXPECT_EQ("SSID 0", UTF16ToUTF8(ap_data_.begin()->ssid)); +} + +TEST_F(GeolocationChromeOsWifiDataProviderTest, GetManyAccessPoints) { + AddWifiAps(3, 4); + EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); + EXPECT_EQ(12u, ap_data_.size()); +} + +} // namespace chromeos diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2165a4f..1408310 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1257,6 +1257,8 @@ 'browser/geolocation/network_location_request.cc', 'browser/geolocation/network_location_request.h', 'browser/geolocation/osx_wifi.h', + 'browser/geolocation/wifi_data_provider_chromeos.cc', + 'browser/geolocation/wifi_data_provider_chromeos.h', 'browser/geolocation/wifi_data_provider_common.cc', 'browser/geolocation/wifi_data_provider_common.h', 'browser/geolocation/wifi_data_provider_corewlan_mac.mm', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 23443c3..1bd2739 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -798,6 +798,7 @@ 'browser/geolocation/location_arbitrator_unittest.cc', 'browser/geolocation/network_location_provider_unittest.cc', 'browser/geolocation/wifi_data_provider_common_unittest.cc', + 'browser/geolocation/wifi_data_provider_unittest_chromeos.cc', 'browser/geolocation/wifi_data_provider_unittest_win.cc', 'browser/global_keyboard_shortcuts_mac_unittest.mm', 'browser/google_update_settings_unittest.cc', |