blob: 41f61f1c9593d8886f0e595cf5ce9501a0d3c66c [file] [log] [blame]
Xiyuan Xiadfe3a9f2017-11-13 21:46:261// 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
5#ifndef COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_
6#define COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_
7
8#include <memory>
9
10#include "base/macros.h"
11#include "components/user_manager/user_manager_export.h"
12
13namespace user_manager {
14
15class UserManager;
16
17// Helper class for unit tests. Initializes the UserManager singleton to the
18// given |user_manager| and tears it down again on destruction. If the singleton
19// had already been initialized, its previous value is restored after tearing
20// down |user_manager|.
21class USER_MANAGER_EXPORT ScopedUserManager {
22 public:
23 explicit ScopedUserManager(std::unique_ptr<UserManager> user_manager);
24 ~ScopedUserManager();
25
26 private:
27 const std::unique_ptr<UserManager> user_manager_;
28 UserManager* previous_user_manager_ = nullptr;
29
30 DISALLOW_COPY_AND_ASSIGN(ScopedUserManager);
31};
32
33} // namespace user_manager
34
35#endif // COMPONENTS_USER_MANAGER_SCOPED_USER_MANAGER_H_