Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / geolocation / wifi_polling_policy.h
blobc1df4d267ac6f23ea1bb6b16f9f8dd2091d6a17a
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_
8 namespace content {
10 // Allows sharing and mocking of the update polling policy function.
11 class WifiPollingPolicy {
12 public:
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;
21 private:
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,
30 int NO_WIFI_INTERVAL>
31 class GenericWifiPollingPolicy : public WifiPollingPolicy {
32 public:
33 GenericWifiPollingPolicy() : polling_interval_(DEFAULT_INTERVAL) {}
34 // WifiPollingPolicy
35 virtual void UpdatePollingInterval(bool scan_results_differ) {
36 if (scan_results_differ) {
37 polling_interval_ = DEFAULT_INTERVAL;
38 } else if (polling_interval_ == DEFAULT_INTERVAL) {
39 polling_interval_ = NO_CHANGE_INTERVAL;
40 } else {
41 DCHECK(polling_interval_ == NO_CHANGE_INTERVAL ||
42 polling_interval_ == TWO_NO_CHANGE_INTERVAL);
43 polling_interval_ = TWO_NO_CHANGE_INTERVAL;
46 virtual int PollingInterval() { return polling_interval_; }
47 virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; }
49 private:
50 int polling_interval_;
53 } // namespace content
55 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_