diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 23:59:13 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 23:59:13 +0000 |
commit | 5f5f6562504bab1eeb29f0eb45f2cfe2f5b864d2 (patch) | |
tree | c681466229e5a1321a64c9914fee77f578f36d79 /content/browser | |
parent | d8837b3a398dc2911d1f84bbf8e6bf36ed3109d0 (diff) | |
download | chromium_src-5f5f6562504bab1eeb29f0eb45f2cfe2f5b864d2.zip chromium_src-5f5f6562504bab1eeb29f0eb45f2cfe2f5b864d2.tar.gz chromium_src-5f5f6562504bab1eeb29f0eb45f2cfe2f5b864d2.tar.bz2 |
Move the chromeos implementation of WifiDataProvider back to chrome, since it has chrome dependencies.
TBR=avi
Review URL: http://codereview.chromium.org/6975030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85697 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r-- | content/browser/DEPS | 3 | ||||
-rw-r--r-- | content/browser/geolocation/wifi_data_provider_chromeos.cc | 233 | ||||
-rw-r--r-- | content/browser/geolocation/wifi_data_provider_chromeos.h | 73 | ||||
-rw-r--r-- | content/browser/geolocation/wifi_data_provider_unittest_chromeos.cc | 78 |
4 files changed, 0 insertions, 387 deletions
diff --git a/content/browser/DEPS b/content/browser/DEPS index 73c78e0..41ae24c 100644 --- a/content/browser/DEPS +++ b/content/browser/DEPS @@ -14,9 +14,6 @@ include_rules = [ "+chrome/browser/browser_url_handler.h",
- "+chrome/browser/chromeos/cros/cros_library.h",
- "+chrome/browser/chromeos/cros/network_library.h",
-
"+chrome/browser/debugger/devtools_manager.h",
"+chrome/browser/debugger/devtools_netlog_observer.h",
diff --git a/content/browser/geolocation/wifi_data_provider_chromeos.cc b/content/browser/geolocation/wifi_data_provider_chromeos.cc deleted file mode 100644 index 68cc9be..0000000 --- a/content/browser/geolocation/wifi_data_provider_chromeos.cc +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) 2011 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 "content/browser/geolocation/wifi_data_provider_chromeos.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/network_library.h" -#include "content/browser/browser_thread.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 -const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s -} - -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* result) { - WifiAccessPointVector access_points; - if (!network_library_->GetWifiAccessPoints(&access_points)) - return false; - for (WifiAccessPointVector::const_iterator i = access_points.begin(); - i != access_points.end(); ++i) { - AccessPointData ap_data; - ap_data.mac_address = ASCIIToUTF16(i->mac_address); - ap_data.radio_signal_strength = i->signal_strength; - ap_data.channel = i->channel; - ap_data.signal_to_noise = i->signal_to_noise; - ap_data.ssid = UTF8ToUTF16(i->name); - result->insert(ap_data); - } - return !result->empty() || network_library_->wifi_enabled(); -} - -} // namespace -} // namespace chromeos - -template<> -WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { - return new WifiDataProviderChromeOs(); -} - -WifiDataProviderChromeOs::WifiDataProviderChromeOs() : - started_(false) { -} - -WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { -} - -bool WifiDataProviderChromeOs::StartDataProvider() { - DCHECK(CalledOnClientThread()); - - DCHECK(polling_policy_ == NULL); - polling_policy_.reset(NewPollingPolicy()); - DCHECK(polling_policy_ != NULL); - - ScheduleStart(); - return true; -} - -void WifiDataProviderChromeOs::StopDataProvider() { - DCHECK(CalledOnClientThread()); - - polling_policy_.reset(); - ScheduleStop(); -} - -bool WifiDataProviderChromeOs::GetData(WifiData* data) { - DCHECK(CalledOnClientThread()); - DCHECK(data); - *data = wifi_data_; - return is_first_scan_complete_; -} - -WifiDataProviderCommon::WlanApiInterface* - WifiDataProviderChromeOs::NewWlanApi(chromeos::NetworkLibrary* lib) { - return new chromeos::NetworkLibraryWlanApi(lib); -} - -WifiDataProviderCommon::WlanApiInterface* - WifiDataProviderChromeOs::NewWlanApi() { - chromeos::CrosLibrary* cros_lib = chromeos::CrosLibrary::Get(); - DCHECK(cros_lib); - if (!cros_lib->EnsureLoaded()) - return NULL; - return NewWlanApi(cros_lib->GetNetworkLibrary()); -} - -PollingPolicyInterface* WifiDataProviderChromeOs::NewPollingPolicy() { - return new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds, - kNoChangePollingIntervalMilliseconds, - kTwoNoChangePollingIntervalMilliseconds, - kNoWifiPollingIntervalMilliseconds>; -} - -void WifiDataProviderChromeOs::DoStartTaskOnUIThread() { - CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - wlan_api_.reset(NewWlanApi()); - if (wlan_api_ == NULL) { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidStartFailed)); - return; - } - DoWifiScanTaskOnUIThread(); -} - -void WifiDataProviderChromeOs::DoStopTaskOnUIThread() { - CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - wlan_api_.reset(); -} - -void WifiDataProviderChromeOs::DidStartFailed() { - CHECK(CalledOnClientThread()); - // Error! Can't do scans, so don't try and schedule one. - is_first_scan_complete_ = true; -} - -void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { - CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // This method could be scheduled after a DoStopTaskOnUIThread. - if (!wlan_api_.get()) - return; - - WifiData new_data; - - if (!wlan_api_->GetAccessPointData(&new_data.access_point_data)) { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidWifiScanTaskNoResults)); - } - else { - client_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &WifiDataProviderChromeOs::DidWifiScanTask, - new_data)); - } -} - -void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() { - DCHECK(CalledOnClientThread()); - // Schedule next scan if started (StopDataProvider could have been called - // in between DoWifiScanTaskOnUIThread and this method). - if (started_) - ScheduleNextScan(polling_policy_->NoWifiInterval()); - MaybeNotifyListeners(false); -} - -void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) { - DCHECK(CalledOnClientThread()); - bool update_available = wifi_data_.DiffersSignificantly(new_data); - wifi_data_ = new_data; - // Schedule next scan if started (StopDataProvider could have been called - // in between DoWifiScanTaskOnUIThread and this method). - if (started_) { - polling_policy_->UpdatePollingInterval(update_available); - ScheduleNextScan(polling_policy_->PollingInterval()); - } - MaybeNotifyListeners(update_available); -} - -void WifiDataProviderChromeOs::MaybeNotifyListeners(bool update_available) { - if (update_available || !is_first_scan_complete_) { - is_first_scan_complete_ = true; - NotifyListeners(); - } -} - -void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { - DCHECK(CalledOnClientThread()); - DCHECK(started_); - BrowserThread::PostDelayedTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread), - interval); -} - -void WifiDataProviderChromeOs::ScheduleStop() { - DCHECK(CalledOnClientThread()); - DCHECK(started_); - started_ = false; - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoStopTaskOnUIThread)); -} - -void WifiDataProviderChromeOs::ScheduleStart() { - DCHECK(CalledOnClientThread()); - DCHECK(!started_); - started_ = true; - // Perform first scan ASAP regardless of the polling policy. If this scan - // fails we'll retry at a rate in line with the polling policy. - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - NewRunnableMethod(this, - &WifiDataProviderChromeOs::DoStartTaskOnUIThread)); -} diff --git a/content/browser/geolocation/wifi_data_provider_chromeos.h b/content/browser/geolocation/wifi_data_provider_chromeos.h deleted file mode 100644 index e60ac96..0000000 --- a/content/browser/geolocation/wifi_data_provider_chromeos.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2011 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 CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ -#define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ -#pragma once - -#include "content/browser/geolocation/wifi_data_provider_common.h" - -namespace chromeos { -class NetworkLibrary; -} - -class WifiDataProviderChromeOs : public WifiDataProviderImplBase { - public: - WifiDataProviderChromeOs(); - - // WifiDataProviderImplBase - virtual bool StartDataProvider(); - virtual void StopDataProvider(); - virtual bool GetData(WifiData* data); - - // Allows injection of |lib| for testing. - static WifiDataProviderCommon::WlanApiInterface* NewWlanApi( - chromeos::NetworkLibrary* lib); - - private: - virtual ~WifiDataProviderChromeOs(); - - // UI thread - void DoWifiScanTaskOnUIThread(); // The polling task - void DoStartTaskOnUIThread(); - void DoStopTaskOnUIThread(); - - // Client thread - void DidWifiScanTaskNoResults(); - void DidWifiScanTask(const WifiData& new_data); - void MaybeNotifyListeners(bool update_available); - void DidStartFailed(); - - // WifiDataProviderCommon - virtual WifiDataProviderCommon::WlanApiInterface* NewWlanApi(); - virtual PollingPolicyInterface* NewPollingPolicy(); - - // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. - void ScheduleNextScan(int interval); - - // Will schedule starting of the scanning process. - void ScheduleStart(); - - // Will schedule stopping of the scanning process. - void ScheduleStop(); - - // Underlying OS wifi API. (UI thread) - scoped_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_; - - // Controls the polling update interval. (client thread) - scoped_ptr<PollingPolicyInterface> polling_policy_; - - // The latest wifi data. (client thread) - WifiData wifi_data_; - - // Whether we have strated the data provider. (client thread) - bool started_; - - // Whether we've successfully completed a scan for WiFi data. (client thread) - bool is_first_scan_complete_; - - DISALLOW_COPY_AND_ASSIGN(WifiDataProviderChromeOs); -}; - -#endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ diff --git a/content/browser/geolocation/wifi_data_provider_unittest_chromeos.cc b/content/browser/geolocation/wifi_data_provider_unittest_chromeos.cc deleted file mode 100644 index bd42286..0000000 --- a/content/browser/geolocation/wifi_data_provider_unittest_chromeos.cc +++ /dev/null @@ -1,78 +0,0 @@ -// 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 "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/cros/mock_network_library.h" -#include "content/browser/geolocation/wifi_data_provider_chromeos.h" -#include "testing/gtest/include/gtest/gtest.h" - -using ::testing::DoAll; -using ::testing::NotNull; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::SetArgumentPointee; - -namespace chromeos { - -class GeolocationChromeOsWifiDataProviderTest : public testing::Test { - protected: - GeolocationChromeOsWifiDataProviderTest() - : api_(WifiDataProviderChromeOs::NewWlanApi(&net_lib_)) { - } - - static WifiAccessPointVector MakeWifiAps(int ssids, int aps_per_ssid) { - WifiAccessPointVector ret; - for (int i = 0; i < ssids; ++i) { - for (int j = 0; j < aps_per_ssid; ++j) { - WifiAccessPoint ap; - ap.name = StringPrintf("SSID %d", i); - 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; - ret.push_back(ap); - } - } - return ret; - } - - chromeos::MockNetworkLibrary net_lib_; - scoped_ptr<WifiDataProviderCommon::WlanApiInterface> api_; - WifiData::AccessPointDataSet ap_data_; -}; - -TEST_F(GeolocationChromeOsWifiDataProviderTest, WifiPoweredOff) { - EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) - .WillOnce(Return(false)); - EXPECT_FALSE(api_->GetAccessPointData(&ap_data_)); - EXPECT_EQ(0u, ap_data_.size()); -} - -TEST_F(GeolocationChromeOsWifiDataProviderTest, NoAccessPointsInRange) { - EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) - .WillOnce(Return(true)); - EXPECT_CALL(net_lib_, wifi_enabled()) - .WillRepeatedly(Return(true)); - EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); - EXPECT_EQ(0u, ap_data_.size()); -} - -TEST_F(GeolocationChromeOsWifiDataProviderTest, GetOneAccessPoint) { - EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) - .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(1, 1)), Return(true))); - EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); - ASSERT_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) { - EXPECT_CALL(net_lib_, GetWifiAccessPoints(NotNull())) - .WillOnce(DoAll(SetArgumentPointee<0>(MakeWifiAps(3, 4)), Return(true))); - EXPECT_TRUE(api_->GetAccessPointData(&ap_data_)); - ASSERT_EQ(12u, ap_data_.size()); -} - -} // namespace chromeos |