wifi_data_provider_lacros.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2021 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_WIFI_DATA_PROVIDER_LACROS_H_
  5. #define SERVICES_DEVICE_GEOLOCATION_WIFI_DATA_PROVIDER_LACROS_H_
  6. #include <memory>
  7. #include "chromeos/crosapi/mojom/geolocation.mojom.h"
  8. #include "mojo/public/cpp/bindings/remote.h"
  9. #include "services/device/geolocation/wifi_data_provider.h"
  10. namespace base {
  11. class RetainingOneShotTimer;
  12. } // namespace base
  13. namespace device {
  14. // Implements the WifiDataProvider interface for the Lacros platform. Uses
  15. // polling to query the crosapi::GeolocationService for wifi access points
  16. // according to its WifiPollingPolicy.
  17. class WifiDataProviderLacros : public WifiDataProvider {
  18. public:
  19. WifiDataProviderLacros();
  20. WifiDataProviderLacros(const WifiDataProviderLacros&) = delete;
  21. WifiDataProviderLacros& operator=(const WifiDataProviderLacros&) = delete;
  22. // WifiDataProvider:
  23. void StartDataProvider() override;
  24. void StopDataProvider() override;
  25. bool DelayedByPolicy() override;
  26. bool GetData(WifiData* data) override;
  27. void ForceRescan() override;
  28. void DidWifiScanTaskForTesting(
  29. bool service_initialized,
  30. bool data_available,
  31. base::TimeDelta time_since_last_updated,
  32. std::vector<crosapi::mojom::AccessPointDataPtr> access_points);
  33. private:
  34. ~WifiDataProviderLacros() override;
  35. // Will schedule a scan; i.e. start the timer for a deferred DoWifiScanTask().
  36. void ScheduleNextScan(int interval_ms);
  37. // Makes a request to ash-chrome's GeolocationService for device access
  38. // points.
  39. void DoWifiScanTask();
  40. // Ash-chrome's GeolocationService calls back into this in response to the
  41. // service request in DoWifiScanTask().
  42. void DidWifiScanTask(
  43. bool service_initialized,
  44. bool data_available,
  45. base::TimeDelta time_since_last_updated,
  46. std::vector<crosapi::mojom::AccessPointDataPtr> access_points);
  47. // The latest wifi data.
  48. WifiData wifi_data_;
  49. // Whether we have started the data provider.
  50. bool started_ = false;
  51. // Whether we've successfully completed a scan for WiFi data.
  52. bool is_first_scan_complete_ = false;
  53. // Whether our first scan was delayed due to polling policy.
  54. bool first_scan_delayed_ = false;
  55. // Used to schedule the next DoWifiScanTask().
  56. base::RetainingOneShotTimer wifi_scan_timer_;
  57. // The remote connection to the geolocation service.
  58. mojo::Remote<crosapi::mojom::GeolocationService> geolocation_service_;
  59. // Holder for delayed tasks; takes care of cleanup.
  60. base::WeakPtrFactory<WifiDataProviderLacros> weak_factory_{this};
  61. };
  62. } // namespace device
  63. #endif // SERVICES_DEVICE_GEOLOCATION_WIFI_DATA_PROVIDER_LACROS_H_