com_init_util.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 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 BASE_WIN_COM_INIT_UTIL_H_
  5. #define BASE_WIN_COM_INIT_UTIL_H_
  6. #include "base/base_export.h"
  7. #include "base/check_op.h"
  8. namespace base {
  9. namespace win {
  10. enum class ComApartmentType {
  11. // Uninitialized or has an unrecognized apartment type.
  12. NONE,
  13. // Single-threaded Apartment.
  14. STA,
  15. // Multi-threaded Apartment.
  16. MTA,
  17. };
  18. // Get the current apartment type.
  19. BASE_EXPORT ComApartmentType GetComApartmentTypeForThread();
  20. #if DCHECK_IS_ON()
  21. // DCHECKs if COM is not initialized on this thread as an STA or MTA.
  22. // |message| is optional and is used for the DCHECK if specified.
  23. BASE_EXPORT void AssertComInitialized(const char* message = nullptr);
  24. // DCHECKs if |apartment_type| is not the same as the current thread's apartment
  25. // type.
  26. BASE_EXPORT void AssertComApartmentType(ComApartmentType apartment_type);
  27. #else // DCHECK_IS_ON()
  28. inline void AssertComInitialized() {}
  29. inline void AssertComApartmentType(ComApartmentType apartment_type) {}
  30. #endif // DCHECK_IS_ON()
  31. } // namespace win
  32. } // namespace base
  33. #endif // BASE_WIN_COM_INIT_UTIL_H_