device_info_tracker.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2014 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_SYNC_DEVICE_INFO_DEVICE_INFO_TRACKER_H_
  5. #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_TRACKER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "components/sync_device_info/device_info.h"
  11. namespace sync_pb {
  12. enum SyncEnums_DeviceType : int;
  13. } // namespace sync_pb
  14. namespace syncer {
  15. // Interface for tracking synced DeviceInfo. This excludes sync-ing clients that
  16. // are not chromium-based.
  17. class DeviceInfoTracker {
  18. public:
  19. virtual ~DeviceInfoTracker() {}
  20. // Observer class for listening to device info changes.
  21. class Observer {
  22. public:
  23. // Called on any change in the device info list. If sync is enabled, it is
  24. // guaranteed that the method will be called at least once after browser
  25. // startup. There are several possible cases:
  26. // 1. The list has been changed during remote update (initial merge or
  27. // incremental).
  28. // 2. The list has been cleaned up when sync is stopped.
  29. // 3. The local device info has been changed and committed to the server.
  30. // 4. The list has been just loaded after browser startup from the
  31. // persistent storage. If the list is empty (e.g. due to mismatching cache
  32. // GUID or this is the first browser startup), it will be updated later
  33. // during the initial merge.
  34. virtual void OnDeviceInfoChange() = 0;
  35. };
  36. // Returns true when DeviceInfo datatype is enabled and syncing.
  37. virtual bool IsSyncing() const = 0;
  38. // Gets DeviceInfo the synced device with specified client ID.
  39. // Returns an empty unique_ptr if device with the given |client_id| hasn't
  40. // been synced.
  41. virtual std::unique_ptr<DeviceInfo> GetDeviceInfo(
  42. const std::string& client_id) const = 0;
  43. // Gets DeviceInfo for all synced devices (including the local one).
  44. virtual std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const = 0;
  45. // Registers an observer to be called on syncing any updated DeviceInfo.
  46. virtual void AddObserver(Observer* observer) = 0;
  47. // Unregisters an observer.
  48. virtual void RemoveObserver(Observer* observer) = 0;
  49. // Returns the count of active devices per device type. Deduping logic may be
  50. // used internally to prevent double counting for devices that disable sync
  51. // and reenable it, but callers should nevertheless consider this an upper
  52. // bound per type.
  53. virtual std::map<sync_pb::SyncEnums_DeviceType, int>
  54. CountActiveDevicesByType() const = 0;
  55. // A function to to allow tests to ensure active devices. If called when the
  56. // local device info provider is not initialized, will force update after
  57. // initialization.
  58. virtual void ForcePulseForTest() = 0;
  59. // Returns if the provided |cache_guid| is the current device cache_guid for
  60. // the current device or was of the recently used.
  61. virtual bool IsRecentLocalCacheGuid(const std::string& cache_guid) const = 0;
  62. };
  63. } // namespace syncer
  64. #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_TRACKER_H_