xref: /aosp_15_r20/external/cronet/base/win/com_init_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_WIN_COM_INIT_UTIL_H_
6 #define BASE_WIN_COM_INIT_UTIL_H_
7 
8 #include "base/base_export.h"
9 #include "base/check_op.h"
10 
11 namespace base {
12 namespace win {
13 
14 enum class ComApartmentType {
15   // Uninitialized or has an unrecognized apartment type.
16   NONE,
17   // Single-threaded Apartment.
18   STA,
19   // Multi-threaded Apartment.
20   MTA,
21 };
22 
23 // Get the current apartment type.
24 BASE_EXPORT ComApartmentType GetComApartmentTypeForThread();
25 
26 #if DCHECK_IS_ON()
27 
28 // DCHECKs if COM is not initialized on this thread as an STA or MTA.
29 // |message| is optional and is used for the DCHECK if specified.
30 BASE_EXPORT void AssertComInitialized(const char* message = nullptr);
31 
32 // DCHECKs if |apartment_type| is not the same as the current thread's apartment
33 // type.
34 BASE_EXPORT void AssertComApartmentType(ComApartmentType apartment_type);
35 
36 #else   // DCHECK_IS_ON()
AssertComInitialized()37 inline void AssertComInitialized() {}
AssertComApartmentType(ComApartmentType apartment_type)38 inline void AssertComApartmentType(ComApartmentType apartment_type) {}
39 #endif  // DCHECK_IS_ON()
40 
41 }  // namespace win
42 }  // namespace base
43 
44 #endif  // BASE_WIN_COM_INIT_UTIL_H_
45