1 // Copyright 2013 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.
5 #ifndef CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_
6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_
10 // Allows sharing and mocking of the update polling policy function.
11 class WifiPollingPolicy
{
13 WifiPollingPolicy() {}
14 virtual ~WifiPollingPolicy() {}
15 // Calculates the new polling interval for wiFi scans, given the previous
16 // interval and whether the last scan produced new results.
17 virtual void UpdatePollingInterval(bool scan_results_differ
) = 0;
18 virtual int PollingInterval() = 0;
19 virtual int NoWifiInterval() = 0;
22 DISALLOW_COPY_AND_ASSIGN(WifiPollingPolicy
);
25 // Generic polling policy, constants are compile-time parameterized to allow
26 // tuning on a per-platform basis.
27 template<int DEFAULT_INTERVAL
,
28 int NO_CHANGE_INTERVAL
,
29 int TWO_NO_CHANGE_INTERVAL
,
31 class GenericWifiPollingPolicy
: public WifiPollingPolicy
{
33 GenericWifiPollingPolicy() : polling_interval_(DEFAULT_INTERVAL
) {}
35 void UpdatePollingInterval(bool scan_results_differ
) override
{
36 if (scan_results_differ
) {
37 polling_interval_
= DEFAULT_INTERVAL
;
38 } else if (polling_interval_
== DEFAULT_INTERVAL
) {
39 polling_interval_
= NO_CHANGE_INTERVAL
;
41 DCHECK(polling_interval_
== NO_CHANGE_INTERVAL
||
42 polling_interval_
== TWO_NO_CHANGE_INTERVAL
);
43 polling_interval_
= TWO_NO_CHANGE_INTERVAL
;
46 int PollingInterval() override
{ return polling_interval_
; }
47 int NoWifiInterval() override
{ return NO_WIFI_INTERVAL
; }
50 int polling_interval_
;
53 } // namespace content
55 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_