local_device_info_provider_impl.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_IMPL_H_
  5. #define COMPONENTS_SYNC_DEVICE_INFO_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/callback_forward.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "base/sequence_checker.h"
  12. #include "components/sync/base/model_type.h"
  13. #include "components/sync_device_info/device_info.h"
  14. #include "components/sync_device_info/local_device_info_provider.h"
  15. #include "components/version_info/version_info.h"
  16. namespace syncer {
  17. class DeviceInfoSyncClient;
  18. class LocalDeviceInfoProviderImpl : public MutableLocalDeviceInfoProvider {
  19. public:
  20. LocalDeviceInfoProviderImpl(version_info::Channel channel,
  21. const std::string& version,
  22. const DeviceInfoSyncClient* sync_client);
  23. LocalDeviceInfoProviderImpl(const LocalDeviceInfoProviderImpl&) = delete;
  24. LocalDeviceInfoProviderImpl& operator=(const LocalDeviceInfoProviderImpl&) =
  25. delete;
  26. ~LocalDeviceInfoProviderImpl() override;
  27. // MutableLocalDeviceInfoProvider implementation.
  28. void Initialize(
  29. const std::string& cache_guid,
  30. const std::string& client_name,
  31. const std::string& manufacturer_name,
  32. const std::string& model_name,
  33. const std::string& full_hardware_class,
  34. std::unique_ptr<DeviceInfo> device_info_restored_from_store) override;
  35. void Clear() override;
  36. void UpdateClientName(const std::string& client_name) override;
  37. version_info::Channel GetChannel() const override;
  38. const DeviceInfo* GetLocalDeviceInfo() const override;
  39. base::CallbackListSubscription RegisterOnInitializedCallback(
  40. const base::RepeatingClosure& callback) override;
  41. private:
  42. // The channel (CANARY, DEV, BETA, etc.) of the current client.
  43. const version_info::Channel channel_;
  44. // The version string for the current client.
  45. const std::string version_;
  46. void ResetFullHardwareClassIfUmaDisabled() const;
  47. const raw_ptr<const DeviceInfoSyncClient> sync_client_;
  48. bool IsUmaEnabledOnCrOSDevice() const;
  49. // The |full_hardware_class| is stored in order to handle UMA toggles
  50. // during a users session. Tracking |full_hardware_class| in this class
  51. // ensures it's reset/retrieved correctly when GetLocalDeviceInfo() is called.
  52. std::string full_hardware_class_;
  53. std::unique_ptr<DeviceInfo> local_device_info_;
  54. base::RepeatingClosureList closure_list_;
  55. SEQUENCE_CHECKER(sequence_checker_);
  56. base::WeakPtrFactory<LocalDeviceInfoProviderImpl> weak_factory_{this};
  57. };
  58. } // namespace syncer
  59. #endif // COMPONENTS_SYNC_DEVICE_INFO_LOCAL_DEVICE_INFO_PROVIDER_IMPL_H_