Chromium Code Reviews| Index: content/browser/geolocation/wifi_polling_policy.h |
| diff --git a/content/browser/geolocation/wifi_polling_policy.h b/content/browser/geolocation/wifi_polling_policy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94877d019a3f234158634f8ea7b44c30d6540784 |
| --- /dev/null |
| +++ b/content/browser/geolocation/wifi_polling_policy.h |
| @@ -0,0 +1,51 @@ |
| +// Copyright (c) 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 PollingPolicyInterface { |
|
bulach
2013/09/06 16:01:38
nit: jam@ complained that some of the device orien
Michael van Ouwerkerk
2013/09/06 19:05:01
Done.
|
| + 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; |
|
bulach
2013/09/06 16:01:38
nit: I think it needs a private: DISALLOW_COPY_AND
Michael van Ouwerkerk
2013/09/06 19:05:01
Done.
|
| +}; |
| + |
| +// 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 { |
|
bulach
2013/09/06 16:01:38
then this can become GenericWifiPollingPolicy?
Michael van Ouwerkerk
2013/09/06 19:05:01
Done.
|
| + 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_; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_ |