os_exchange_data_provider_factory.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 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 "ui/base/dragdrop/os_exchange_data_provider_factory.h"
  5. #include "base/notreached.h"
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FUCHSIA)
  8. #include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h"
  9. #include "ui/base/dragdrop/os_exchange_data_provider_non_backed.h"
  10. #elif BUILDFLAG(IS_APPLE)
  11. #include "ui/base/dragdrop/os_exchange_data_provider_builder_mac.h"
  12. #elif BUILDFLAG(IS_WIN)
  13. #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
  14. #endif
  15. namespace ui {
  16. // static
  17. std::unique_ptr<OSExchangeDataProvider>
  18. OSExchangeDataProviderFactory::CreateProvider() {
  19. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  20. // The instance can be nullptr in tests that do not instantiate the platform,
  21. // or on platforms that do not implement specific drag'n'drop. For them,
  22. // falling back to the Aura provider should be fine.
  23. if (auto* factory = OSExchangeDataProviderFactoryOzone::Instance()) {
  24. auto provider = factory->CreateProvider();
  25. if (provider)
  26. return provider;
  27. }
  28. return std::make_unique<OSExchangeDataProviderNonBacked>();
  29. #elif BUILDFLAG(IS_APPLE)
  30. return BuildOSExchangeDataProviderMac();
  31. #elif BUILDFLAG(IS_WIN)
  32. return std::make_unique<OSExchangeDataProviderWin>();
  33. #elif BUILDFLAG(IS_FUCHSIA)
  34. // TODO(crbug.com/980371): Implement OSExchangeDataProvider for Fuchsia.
  35. return std::make_unique<OSExchangeDataProviderNonBacked>();
  36. #else
  37. #error "Unknown operating system"
  38. #endif
  39. }
  40. } // namespace ui