local_device_info_provider.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_LOCAL_DEVICE_INFO_PROVIDER_H_
  5. #define COMPONENTS_SYNC_DEVICE_INFO_LOCAL_DEVICE_INFO_PROVIDER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_list.h"
  9. #include "components/sync/base/model_type.h"
  10. #include "components/version_info/version_info.h"
  11. namespace syncer {
  12. class DeviceInfo;
  13. // Interface for providing sync specific information about the
  14. // local device.
  15. class LocalDeviceInfoProvider {
  16. public:
  17. virtual ~LocalDeviceInfoProvider() = default;
  18. virtual version_info::Channel GetChannel() const = 0;
  19. // Returns sync's representation of the local device info, or nullptr if the
  20. // device info is unavailable (e.g. Initialize() hasn't been called). The
  21. // returned object is fully owned by LocalDeviceInfoProvider; it must not be
  22. // freed by the caller and should not be stored.
  23. virtual const DeviceInfo* GetLocalDeviceInfo() const = 0;
  24. // Registers a callback to be called when local device info becomes available.
  25. // The callback will remain registered until the returned subscription is
  26. // destroyed, which must occur before the CallbackList is destroyed.
  27. [[nodiscard]] virtual base::CallbackListSubscription
  28. RegisterOnInitializedCallback(const base::RepeatingClosure& callback) = 0;
  29. };
  30. class MutableLocalDeviceInfoProvider : public LocalDeviceInfoProvider {
  31. public:
  32. // Initialize initializes the LocalDeviceInfoProvider using the given values.
  33. // The |device_info_restored_from_store| argument contains a previous
  34. // DeviceInfo loaded from the store and may be nullptr if unavailable. If
  35. // provided it is only used as a fallback and the provided arguments, and data
  36. // from the DeviceInfoSyncClient, take precedence.
  37. virtual void Initialize(
  38. const std::string& cache_guid,
  39. const std::string& client_name,
  40. const std::string& manufacturer_name,
  41. const std::string& model_name,
  42. const std::string& full_hardware_class,
  43. std::unique_ptr<DeviceInfo> device_info_restored_from_store) = 0;
  44. virtual void Clear() = 0;
  45. // Updates the local device's client name. Initialize() must be called before
  46. // calling this function.
  47. virtual void UpdateClientName(const std::string& client_name) = 0;
  48. };
  49. } // namespace syncer
  50. #endif // COMPONENTS_SYNC_DEVICE_INFO_LOCAL_DEVICE_INFO_PROVIDER_H_