host_settings.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "remoting/base/host_settings.h"
  5. #include "base/no_destructor.h"
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_APPLE) || (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS))
  8. #include "remoting/base/file_host_settings.h"
  9. #endif // BUILDFLAG(IS_LINUX)
  10. #if BUILDFLAG(IS_WIN)
  11. #include "remoting/base/host_settings_win.h"
  12. #endif // defined (OS_WIN)
  13. namespace remoting {
  14. namespace {
  15. class EmptyHostSettings : public HostSettings {
  16. public:
  17. std::string GetString(const HostSettingKey key,
  18. const std::string& default_value) const override {
  19. return default_value;
  20. }
  21. void SetString(const HostSettingKey key, const std::string& value) override {}
  22. void InitializeInstance() override {}
  23. };
  24. } // namespace
  25. // static
  26. void HostSettings::Initialize() {
  27. GetInstance()->InitializeInstance();
  28. }
  29. HostSettings::HostSettings() = default;
  30. HostSettings::~HostSettings() = default;
  31. // static
  32. HostSettings* HostSettings::GetInstance() {
  33. #if BUILDFLAG(IS_APPLE) || (BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS))
  34. static base::NoDestructor<FileHostSettings> instance(
  35. FileHostSettings::GetSettingsFilePath());
  36. #elif BUILDFLAG(IS_WIN)
  37. static base::NoDestructor<HostSettingsWin> instance;
  38. #else
  39. // HostSettings is currently neither implemented nor used on other platforms.
  40. static base::NoDestructor<EmptyHostSettings> instance;
  41. #endif
  42. return instance.get();
  43. }
  44. } // namespace remoting