Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / geolocation / wifi_polling_policy.h
blobf597e837e7e04263efe0c9fe4ea88b0502357012
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 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;
40 } else {
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; }
49 private:
50 int polling_interval_;
53 } // namespace content
55 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_