Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_ | |
| 6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_ | |
| 7 | |
| 8 namespace content { | |
| 9 | |
| 10 // Allows sharing and mocking of the update polling policy function. | |
| 11 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.
| |
| 12 public: | |
| 13 virtual ~PollingPolicyInterface() {} | |
| 14 // Calculates the new polling interval for wiFi scans, given the previous | |
| 15 // interval and whether the last scan produced new results. | |
| 16 virtual void UpdatePollingInterval(bool scan_results_differ) = 0; | |
| 17 virtual int PollingInterval() = 0; | |
| 18 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.
| |
| 19 }; | |
| 20 | |
| 21 // Generic polling policy, constants are compile-time parameterized to allow | |
| 22 // tuning on a per-platform basis. | |
| 23 template<int DEFAULT_INTERVAL, | |
| 24 int NO_CHANGE_INTERVAL, | |
| 25 int TWO_NO_CHANGE_INTERVAL, | |
| 26 int NO_WIFI_INTERVAL> | |
| 27 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.
| |
| 28 public: | |
| 29 GenericPollingPolicy() : polling_interval_(DEFAULT_INTERVAL) {} | |
| 30 // PollingPolicyInterface | |
| 31 virtual void UpdatePollingInterval(bool scan_results_differ) { | |
| 32 if (scan_results_differ) { | |
| 33 polling_interval_ = DEFAULT_INTERVAL; | |
| 34 } else if (polling_interval_ == DEFAULT_INTERVAL) { | |
| 35 polling_interval_ = NO_CHANGE_INTERVAL; | |
| 36 } else { | |
| 37 DCHECK(polling_interval_ == NO_CHANGE_INTERVAL || | |
| 38 polling_interval_ == TWO_NO_CHANGE_INTERVAL); | |
| 39 polling_interval_ = TWO_NO_CHANGE_INTERVAL; | |
| 40 } | |
| 41 } | |
| 42 virtual int PollingInterval() { return polling_interval_; } | |
| 43 virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; } | |
| 44 | |
| 45 private: | |
| 46 int polling_interval_; | |
| 47 }; | |
| 48 | |
| 49 } // namespace content | |
| 50 | |
| 51 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_ | |
| OLD | NEW |