Geolocation: move polling policy to its own file.

This change permits cleaning up the dependencies in WifiDataProviderChromeOs, it was pulling in WifiDataProviderCommon not to derive it, but to use the polling policy. It doesn't actually use WifiDataProviderCommon::WlanApiInterface.

Review URL: https://chromiumcodereview.appspot.com/24041003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222069 0039d316-1c4b-4281-b951-d872f2087c98
parent 1d94eba8
...@@ -34,10 +34,10 @@ void WifiDataProviderChromeOs::StartDataProvider() { ...@@ -34,10 +34,10 @@ void WifiDataProviderChromeOs::StartDataProvider() {
DCHECK(polling_policy_ == NULL); DCHECK(polling_policy_ == NULL);
polling_policy_.reset( polling_policy_.reset(
new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds, new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds,
kNoChangePollingIntervalMilliseconds, kNoChangePollingIntervalMilliseconds,
kTwoNoChangePollingIntervalMilliseconds, kTwoNoChangePollingIntervalMilliseconds,
kNoWifiPollingIntervalMilliseconds>); kNoWifiPollingIntervalMilliseconds>);
ScheduleStart(); ScheduleStart();
} }
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_ #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_CHROMEOS_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "content/browser/geolocation/wifi_data_provider_common.h" #include "content/browser/geolocation/wifi_data_provider.h"
#include "content/browser/geolocation/wifi_polling_policy.h"
namespace content { namespace content {
...@@ -44,11 +45,8 @@ class CONTENT_EXPORT WifiDataProviderChromeOs ...@@ -44,11 +45,8 @@ class CONTENT_EXPORT WifiDataProviderChromeOs
// Get access point data from chromeos. // Get access point data from chromeos.
bool GetAccessPointData(WifiData::AccessPointDataSet* data); bool GetAccessPointData(WifiData::AccessPointDataSet* data);
// Underlying OS wifi API. (UI thread)
scoped_ptr<WifiDataProviderCommon::WlanApiInterface> wlan_api_;
// Controls the polling update interval. (client thread) // Controls the polling update interval. (client thread)
scoped_ptr<PollingPolicyInterface> polling_policy_; scoped_ptr<WifiPollingPolicy> polling_policy_;
// The latest wifi data. (client thread) // The latest wifi data. (client thread)
WifiData wifi_data_; WifiData wifi_data_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "content/browser/geolocation/wifi_data_provider.h" #include "content/browser/geolocation/wifi_data_provider.h"
#include "content/browser/geolocation/wifi_polling_policy.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace content { namespace content {
...@@ -19,45 +20,6 @@ namespace content { ...@@ -19,45 +20,6 @@ namespace content {
// Converts a MAC address stored as an array of uint8 to a string. // Converts a MAC address stored as an array of uint8 to a string.
string16 MacAddressAsString16(const uint8 mac_as_int[6]); string16 MacAddressAsString16(const uint8 mac_as_int[6]);
// Allows sharing and mocking of the update polling policy function.
class PollingPolicyInterface {
public:
virtual ~PollingPolicyInterface() {}
// Calculates the new polling interval for wiFi scans, given the previous
// interval and whether the last scan produced new results.
virtual void UpdatePollingInterval(bool scan_results_differ) = 0;
virtual int PollingInterval() = 0;
virtual int NoWifiInterval() = 0;
};
// Generic polling policy, constants are compile-time parameterized to allow
// tuning on a per-platform basis.
template<int DEFAULT_INTERVAL,
int NO_CHANGE_INTERVAL,
int TWO_NO_CHANGE_INTERVAL,
int NO_WIFI_INTERVAL>
class GenericPollingPolicy : public PollingPolicyInterface {
public:
GenericPollingPolicy() : polling_interval_(DEFAULT_INTERVAL) {}
// PollingPolicyInterface
virtual void UpdatePollingInterval(bool scan_results_differ) {
if (scan_results_differ) {
polling_interval_ = DEFAULT_INTERVAL;
} else if (polling_interval_ == DEFAULT_INTERVAL) {
polling_interval_ = NO_CHANGE_INTERVAL;
} else {
DCHECK(polling_interval_ == NO_CHANGE_INTERVAL ||
polling_interval_ == TWO_NO_CHANGE_INTERVAL);
polling_interval_ = TWO_NO_CHANGE_INTERVAL;
}
}
virtual int PollingInterval() { return polling_interval_; }
virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; }
private:
int polling_interval_;
};
// Base class to promote code sharing between platform specific wifi data // Base class to promote code sharing between platform specific wifi data
// providers. It's optional for specific platforms to derive this, but if they // providers. It's optional for specific platforms to derive this, but if they
// do polling behavior is taken care of by this base class, and all the platform // do polling behavior is taken care of by this base class, and all the platform
...@@ -88,7 +50,7 @@ class CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProviderImplBase { ...@@ -88,7 +50,7 @@ class CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProviderImplBase {
virtual WlanApiInterface* NewWlanApi() = 0; virtual WlanApiInterface* NewWlanApi() = 0;
// Returns ownership. // Returns ownership.
virtual PollingPolicyInterface* NewPollingPolicy() = 0; virtual WifiPollingPolicy* NewPollingPolicy() = 0;
private: private:
// Runs a scan. Calls the callbacks if new data is found. // Runs a scan. Calls the callbacks if new data is found.
...@@ -106,7 +68,7 @@ class CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProviderImplBase { ...@@ -106,7 +68,7 @@ class CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProviderImplBase {
scoped_ptr<WlanApiInterface> wlan_api_; scoped_ptr<WlanApiInterface> wlan_api_;
// Controls the polling update interval. // Controls the polling update interval.
scoped_ptr<PollingPolicyInterface> polling_policy_; scoped_ptr<WifiPollingPolicy> polling_policy_;
// Holder for delayed tasks; takes care of cleanup. // Holder for delayed tasks; takes care of cleanup.
base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_; base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_;
......
...@@ -42,7 +42,7 @@ class MockWlanApi : public WifiDataProviderCommon::WlanApiInterface { ...@@ -42,7 +42,7 @@ class MockWlanApi : public WifiDataProviderCommon::WlanApiInterface {
} }
}; };
class MockPollingPolicy : public PollingPolicyInterface { class MockPollingPolicy : public WifiPollingPolicy {
public: public:
MockPollingPolicy() { MockPollingPolicy() {
ON_CALL(*this,PollingInterval()) ON_CALL(*this,PollingInterval())
...@@ -87,7 +87,7 @@ class WifiDataProviderCommonWithMock : public WifiDataProviderCommon { ...@@ -87,7 +87,7 @@ class WifiDataProviderCommonWithMock : public WifiDataProviderCommon {
CHECK(new_wlan_api_ != NULL); CHECK(new_wlan_api_ != NULL);
return new_wlan_api_.release(); return new_wlan_api_.release();
} }
virtual PollingPolicyInterface* NewPollingPolicy() OVERRIDE { virtual WifiPollingPolicy* NewPollingPolicy() OVERRIDE {
CHECK(new_polling_policy_ != NULL); CHECK(new_polling_policy_ != NULL);
return new_polling_policy_.release(); return new_polling_policy_.release();
} }
......
...@@ -362,11 +362,11 @@ WifiDataProviderLinux::NewWlanApi() { ...@@ -362,11 +362,11 @@ WifiDataProviderLinux::NewWlanApi() {
return NULL; return NULL;
} }
PollingPolicyInterface* WifiDataProviderLinux::NewPollingPolicy() { WifiPollingPolicy* WifiDataProviderLinux::NewPollingPolicy() {
return new GenericPollingPolicy<kDefaultPollingIntervalMilliseconds, return new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds,
kNoChangePollingIntervalMilliseconds, kNoChangePollingIntervalMilliseconds,
kTwoNoChangePollingIntervalMilliseconds, kTwoNoChangePollingIntervalMilliseconds,
kNoWifiPollingIntervalMilliseconds>; kNoWifiPollingIntervalMilliseconds>;
} }
WifiDataProviderCommon::WlanApiInterface* WifiDataProviderCommon::WlanApiInterface*
......
...@@ -26,7 +26,7 @@ class CONTENT_EXPORT WifiDataProviderLinux : public WifiDataProviderCommon { ...@@ -26,7 +26,7 @@ class CONTENT_EXPORT WifiDataProviderLinux : public WifiDataProviderCommon {
// WifiDataProviderCommon // WifiDataProviderCommon
virtual WlanApiInterface* NewWlanApi() OVERRIDE; virtual WlanApiInterface* NewWlanApi() OVERRIDE;
virtual PollingPolicyInterface* NewPollingPolicy() OVERRIDE; virtual WifiPollingPolicy* NewPollingPolicy() OVERRIDE;
// For testing. // For testing.
WlanApiInterface* NewWlanApiForTesting(dbus::Bus* bus); WlanApiInterface* NewWlanApiForTesting(dbus::Bus* bus);
......
...@@ -184,11 +184,11 @@ MacWifiDataProvider::WlanApiInterface* MacWifiDataProvider::NewWlanApi() { ...@@ -184,11 +184,11 @@ MacWifiDataProvider::WlanApiInterface* MacWifiDataProvider::NewWlanApi() {
return NULL; return NULL;
} }
PollingPolicyInterface* MacWifiDataProvider::NewPollingPolicy() { WifiPollingPolicy* MacWifiDataProvider::NewPollingPolicy() {
return new GenericPollingPolicy<kDefaultPollingInterval, return new GenericWifiPollingPolicy<kDefaultPollingInterval,
kNoChangePollingInterval, kNoChangePollingInterval,
kTwoNoChangePollingInterval, kTwoNoChangePollingInterval,
kNoWifiPollingIntervalMilliseconds>; kNoWifiPollingIntervalMilliseconds>;
} }
} // namespace content } // namespace content
...@@ -21,7 +21,7 @@ class MacWifiDataProvider : public WifiDataProviderCommon { ...@@ -21,7 +21,7 @@ class MacWifiDataProvider : public WifiDataProviderCommon {
// WifiDataProviderCommon // WifiDataProviderCommon
virtual WlanApiInterface* NewWlanApi() OVERRIDE; virtual WlanApiInterface* NewWlanApi() OVERRIDE;
virtual PollingPolicyInterface* NewPollingPolicy() OVERRIDE; virtual WifiPollingPolicy* NewPollingPolicy() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(MacWifiDataProvider); DISALLOW_COPY_AND_ASSIGN(MacWifiDataProvider);
}; };
......
...@@ -178,11 +178,11 @@ WifiDataProviderCommon::WlanApiInterface* Win32WifiDataProvider::NewWlanApi() { ...@@ -178,11 +178,11 @@ WifiDataProviderCommon::WlanApiInterface* Win32WifiDataProvider::NewWlanApi() {
return WindowsNdisApi::Create(); return WindowsNdisApi::Create();
} }
PollingPolicyInterface* Win32WifiDataProvider::NewPollingPolicy() { WifiPollingPolicy* Win32WifiDataProvider::NewPollingPolicy() {
return new GenericPollingPolicy<kDefaultPollingInterval, return new GenericWifiPollingPolicy<kDefaultPollingInterval,
kNoChangePollingInterval, kNoChangePollingInterval,
kTwoNoChangePollingInterval, kTwoNoChangePollingInterval,
kNoWifiPollingIntervalMilliseconds>; kNoWifiPollingIntervalMilliseconds>;
} }
// Local classes and functions // Local classes and functions
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace content { namespace content {
class PollingPolicyInterface;
class CONTENT_EXPORT Win32WifiDataProvider : public WifiDataProviderCommon { class CONTENT_EXPORT Win32WifiDataProvider : public WifiDataProviderCommon {
public: public:
...@@ -20,7 +19,7 @@ class CONTENT_EXPORT Win32WifiDataProvider : public WifiDataProviderCommon { ...@@ -20,7 +19,7 @@ class CONTENT_EXPORT Win32WifiDataProvider : public WifiDataProviderCommon {
// WifiDataProviderCommon // WifiDataProviderCommon
virtual WlanApiInterface* NewWlanApi(); virtual WlanApiInterface* NewWlanApi();
virtual PollingPolicyInterface* NewPollingPolicy(); virtual WifiPollingPolicy* NewPollingPolicy();
DISALLOW_COPY_AND_ASSIGN(Win32WifiDataProvider); DISALLOW_COPY_AND_ASSIGN(Win32WifiDataProvider);
}; };
......
// Copyright 2013 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_POLLING_POLICY_H_
#define CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_
namespace content {
// Allows sharing and mocking of the update polling policy function.
class WifiPollingPolicy {
public:
WifiPollingPolicy() {}
virtual ~WifiPollingPolicy() {}
// Calculates the new polling interval for wiFi scans, given the previous
// interval and whether the last scan produced new results.
virtual void UpdatePollingInterval(bool scan_results_differ) = 0;
virtual int PollingInterval() = 0;
virtual int NoWifiInterval() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(WifiPollingPolicy);
};
// Generic polling policy, constants are compile-time parameterized to allow
// tuning on a per-platform basis.
template<int DEFAULT_INTERVAL,
int NO_CHANGE_INTERVAL,
int TWO_NO_CHANGE_INTERVAL,
int NO_WIFI_INTERVAL>
class GenericWifiPollingPolicy : public WifiPollingPolicy {
public:
GenericWifiPollingPolicy() : polling_interval_(DEFAULT_INTERVAL) {}
// WifiPollingPolicy
virtual void UpdatePollingInterval(bool scan_results_differ) {
if (scan_results_differ) {
polling_interval_ = DEFAULT_INTERVAL;
} else if (polling_interval_ == DEFAULT_INTERVAL) {
polling_interval_ = NO_CHANGE_INTERVAL;
} else {
DCHECK(polling_interval_ == NO_CHANGE_INTERVAL ||
polling_interval_ == TWO_NO_CHANGE_INTERVAL);
polling_interval_ = TWO_NO_CHANGE_INTERVAL;
}
}
virtual int PollingInterval() { return polling_interval_; }
virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; }
private:
int polling_interval_;
};
} // namespace content
#endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_
...@@ -570,6 +570,7 @@ ...@@ -570,6 +570,7 @@
'browser/geolocation/wifi_data_provider_mac.h', 'browser/geolocation/wifi_data_provider_mac.h',
'browser/geolocation/wifi_data_provider_win.cc', 'browser/geolocation/wifi_data_provider_win.cc',
'browser/geolocation/wifi_data_provider_win.h', 'browser/geolocation/wifi_data_provider_win.h',
'browser/geolocation/wifi_polling_policy.h',
'browser/gpu/browser_gpu_channel_host_factory.cc', 'browser/gpu/browser_gpu_channel_host_factory.cc',
'browser/gpu/browser_gpu_channel_host_factory.h', 'browser/gpu/browser_gpu_channel_host_factory.h',
'browser/gpu/compositor_util.cc', 'browser/gpu/compositor_util.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment