position_cache.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2018 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. #ifndef SERVICES_DEVICE_GEOLOCATION_POSITION_CACHE_H_
  5. #define SERVICES_DEVICE_GEOLOCATION_POSITION_CACHE_H_
  6. #include <cstddef>
  7. namespace device {
  8. namespace mojom {
  9. class Geoposition;
  10. } // namespace mojom
  11. struct WifiData;
  12. // Cache of recently resolved locations, keyed by the set of unique WiFi APs
  13. // used in the network query.
  14. class PositionCache {
  15. public:
  16. virtual ~PositionCache() = default;
  17. // Caches the current position response for the current set of cell ID and
  18. // WiFi data. In the case of the cache exceeding an implementation-defined
  19. // maximum size this will evict old entries in FIFO orderer of being added.
  20. virtual void CachePosition(const WifiData& wifi_data,
  21. const mojom::Geoposition& position) = 0;
  22. // Searches for a cached position response for the current set of data.
  23. // Returns nullptr if the position is not in the cache, or the cached
  24. // position if available. Ownership remains with the cache. Do not store
  25. // the pointer, treat it as an iterator into the cache's internals.
  26. virtual const mojom::Geoposition* FindPosition(
  27. const WifiData& wifi_data) const = 0;
  28. // Returns the number of cached position responses stored in the cache.
  29. virtual size_t GetPositionCacheSize() const = 0;
  30. // Returns most recently used position, or an invalid Geoposition if
  31. // SetLastUsedNetworkPosition wasn't called yet.
  32. virtual const mojom::Geoposition& GetLastUsedNetworkPosition() const = 0;
  33. // Stores the most recently used position.
  34. virtual void SetLastUsedNetworkPosition(
  35. const mojom::Geoposition& position) = 0;
  36. };
  37. } // namespace device
  38. #endif // SERVICES_DEVICE_GEOLOCATION_POSITION_CACHE_H_