scoped_winrt_initializer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_SCOPED_WINRT_INITIALIZER_H_
  5. #define BASE_WIN_SCOPED_WINRT_INITIALIZER_H_
  6. #include <objbase.h>
  7. #include "base/base_export.h"
  8. #include "base/threading/thread_checker.h"
  9. #include "base/win/scoped_windows_thread_environment.h"
  10. namespace base {
  11. namespace win {
  12. // Initializes the Windows Runtime in the constructor and uninitalizes the
  13. // Windows Runtime in the destructor. As a side effect, COM is also initialized
  14. // as an MTA in the constructor and correspondingly uninitialized in the
  15. // destructor.
  16. //
  17. // Generally, you should only use this on Windows 8 or above. It is redundant
  18. // to use ScopedComInitializer in conjunction with ScopedWinrtInitializer.
  19. //
  20. // WARNING: This should only be used once per thread, ideally scoped to a
  21. // similar lifetime as the thread itself. You should not be using this in random
  22. // utility functions that make Windows Runtime calls -- instead ensure these
  23. // functions are running on a Windows Runtime supporting thread!
  24. class BASE_EXPORT ScopedWinrtInitializer
  25. : public ScopedWindowsThreadEnvironment {
  26. public:
  27. ScopedWinrtInitializer();
  28. ScopedWinrtInitializer(const ScopedWinrtInitializer&) = delete;
  29. ScopedWinrtInitializer& operator=(const ScopedWinrtInitializer&) = delete;
  30. ~ScopedWinrtInitializer() override;
  31. // ScopedWindowsThreadEnvironment:
  32. bool Succeeded() const override;
  33. private:
  34. const HRESULT hr_;
  35. THREAD_CHECKER(thread_checker_);
  36. };
  37. } // namespace win
  38. } // namespace base
  39. #endif // BASE_WIN_SCOPED_WINRT_INITIALIZER_H_