active_devices_provider_impl.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 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 COMPONENTS_BROWSER_SYNC_ACTIVE_DEVICES_PROVIDER_IMPL_H_
  5. #define COMPONENTS_BROWSER_SYNC_ACTIVE_DEVICES_PROVIDER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/sequence_checker.h"
  11. #include "base/time/clock.h"
  12. #include "components/sync/driver/active_devices_provider.h"
  13. #include "components/sync_device_info/device_info_tracker.h"
  14. namespace browser_sync {
  15. class ActiveDevicesProviderImpl : public syncer::ActiveDevicesProvider,
  16. public syncer::DeviceInfoTracker::Observer {
  17. public:
  18. ActiveDevicesProviderImpl(syncer::DeviceInfoTracker* device_info_tracker,
  19. base::Clock* clock);
  20. ActiveDevicesProviderImpl(const ActiveDevicesProviderImpl&) = delete;
  21. ActiveDevicesProviderImpl& operator=(const ActiveDevicesProviderImpl&) =
  22. delete;
  23. ~ActiveDevicesProviderImpl() override;
  24. // syncer::ActiveDevicesProvider implementation.
  25. syncer::ActiveDevicesInvalidationInfo CalculateInvalidationInfo(
  26. const std::string& local_cache_guid) const override;
  27. void SetActiveDevicesChangedCallback(
  28. ActiveDevicesChangedCallback callback) override;
  29. // syncer::DeviceInfoTracker::Observer implementation.
  30. void OnDeviceInfoChange() override;
  31. private:
  32. std::vector<std::unique_ptr<syncer::DeviceInfo>>
  33. GetActiveDevicesSortedByUpdateTime() const;
  34. const raw_ptr<syncer::DeviceInfoTracker> device_info_tracker_;
  35. const raw_ptr<const base::Clock> clock_;
  36. ActiveDevicesChangedCallback callback_;
  37. SEQUENCE_CHECKER(sequence_checker_);
  38. };
  39. } // namespace browser_sync
  40. #endif // COMPONENTS_BROWSER_SYNC_ACTIVE_DEVICES_PROVIDER_IMPL_H_