Home | History | Annotate | Download | only in geolocation
      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.
      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 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;
     20 
     21  private:
     22   DISALLOW_COPY_AND_ASSIGN(WifiPollingPolicy);
     23 };
     24 
     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;
     44     }
     45   }
     46   virtual int PollingInterval() { return polling_interval_; }
     47   virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; }
     48 
     49  private:
     50   int polling_interval_;
     51 };
     52 
     53 }  // namespace content
     54 
     55 #endif  // CONTENT_BROWSER_GEOLOCATION_WIFI_POLLING_POLICY_H_
     56