scoped_user_manager.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2014 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 COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_
  5. #define COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_
  6. #include <memory>
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/user_manager/user_manager_export.h"
  9. namespace user_manager {
  10. class UserManager;
  11. // Helper class for unit tests. Initializes the UserManager singleton to the
  12. // given |user_manager| and tears it down again on destruction. If the singleton
  13. // had already been initialized, its previous value is restored after tearing
  14. // down |user_manager|.
  15. class USER_MANAGER_EXPORT ScopedUserManager {
  16. public:
  17. explicit ScopedUserManager(std::unique_ptr<UserManager> user_manager);
  18. ScopedUserManager(const ScopedUserManager&) = delete;
  19. ScopedUserManager& operator=(const ScopedUserManager&) = delete;
  20. ~ScopedUserManager();
  21. private:
  22. const std::unique_ptr<UserManager> user_manager_;
  23. raw_ptr<UserManager> previous_user_manager_ = nullptr;
  24. };
  25. } // namespace user_manager
  26. #endif // COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_