| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/file/user_id_map.h" | 5 #include "services/file/user_id_map.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 | 10 |
| 11 namespace file { | 11 namespace file { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 base::LazyInstance<std::map<std::string, base::FilePath>> | 14 base::LazyInstance<std::map<std::string, base::FilePath>>::DestructorAtExit |
| 15 g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER; | 15 g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER; |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 void AssociateServiceUserIdWithUserDir(const std::string& user_id, | 18 void AssociateServiceUserIdWithUserDir(const std::string& user_id, |
| 19 const base::FilePath& user_dir) { | 19 const base::FilePath& user_dir) { |
| 20 g_user_id_to_data_dir.Get()[user_id] = user_dir; | 20 g_user_id_to_data_dir.Get()[user_id] = user_dir; |
| 21 } | 21 } |
| 22 | 22 |
| 23 void ForgetServiceUserIdUserDirAssociation(const std::string& user_id) { | 23 void ForgetServiceUserIdUserDirAssociation(const std::string& user_id) { |
| 24 auto it = g_user_id_to_data_dir.Get().find(user_id); | 24 auto it = g_user_id_to_data_dir.Get().find(user_id); |
| 25 if (it != g_user_id_to_data_dir.Get().end()) | 25 if (it != g_user_id_to_data_dir.Get().end()) |
| 26 g_user_id_to_data_dir.Get().erase(it); | 26 g_user_id_to_data_dir.Get().erase(it); |
| 27 } | 27 } |
| 28 | 28 |
| 29 base::FilePath GetUserDirForUserId(const std::string& user_id) { | 29 base::FilePath GetUserDirForUserId(const std::string& user_id) { |
| 30 auto it = g_user_id_to_data_dir.Get().find(user_id); | 30 auto it = g_user_id_to_data_dir.Get().find(user_id); |
| 31 DCHECK(it != g_user_id_to_data_dir.Get().end()); | 31 DCHECK(it != g_user_id_to_data_dir.Get().end()); |
| 32 return it->second; | 32 return it->second; |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace file | 35 } // namespace file |
| OLD | NEW |