Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 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 | |
| 5 | #include "components/user_manager/scoped_user_manager.h" |
| 6 | |
| 7 | #include <utility> |
| 8 | |
| 9 | #include "base/logging.h" |
| 10 | #include "components/user_manager/user_manager.h" |
| 11 | |
| 12 | namespace user_manager { |
| 13 | |
| 14 | ScopedUserManager::ScopedUserManager(std::unique_ptr<UserManager> user_manager) |
| 15 | : user_manager_(std::move(user_manager)) { |
| 16 | if (UserManager::GetForTesting()) |
| 17 | UserManager::GetForTesting()->Shutdown(); |
| 18 | |
| 19 | previous_user_manager_ = UserManager::SetForTesting(user_manager_.get()); |
| 20 | } |
| 21 | |
| 22 | ScopedUserManager::~ScopedUserManager() { |
| 23 | DCHECK_EQ(UserManager::Get(), user_manager_.get()); |
| 24 | |
| 25 | // Shutdown and destroy current UserManager instance that we track. |
| 26 | UserManager::Get()->Shutdown(); |
| 27 | UserManager::Get()->Destroy(); |
| 28 | |
| 29 | UserManager::SetForTesting(previous_user_manager_); |
| 30 | } |
| 31 | |
| 32 | } // namespace user_manager |