| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/keyed_service/core/keyed_service_factory.h" | 5 #include "components/keyed_service/core/keyed_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } else { | 90 } else { |
| 91 service = BuildServiceInstanceFor(context); | 91 service = BuildServiceInstanceFor(context); |
| 92 } | 92 } |
| 93 | 93 |
| 94 Associate(context, std::move(service)); | 94 Associate(context, std::move(service)); |
| 95 return mapping_[context]; | 95 return mapping_[context]; |
| 96 } | 96 } |
| 97 | 97 |
| 98 void KeyedServiceFactory::Associate(base::SupportsUserData* context, | 98 void KeyedServiceFactory::Associate(base::SupportsUserData* context, |
| 99 std::unique_ptr<KeyedService> service) { | 99 std::unique_ptr<KeyedService> service) { |
| 100 DCHECK(!ContainsKey(mapping_, context)); | 100 DCHECK(!base::ContainsKey(mapping_, context)); |
| 101 mapping_.insert(std::make_pair(context, service.release())); | 101 mapping_.insert(std::make_pair(context, service.release())); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void KeyedServiceFactory::Disassociate(base::SupportsUserData* context) { | 104 void KeyedServiceFactory::Disassociate(base::SupportsUserData* context) { |
| 105 const auto& it = mapping_.find(context); | 105 const auto& it = mapping_.find(context); |
| 106 if (it != mapping_.end()) { | 106 if (it != mapping_.end()) { |
| 107 delete it->second; | 107 delete it->second; |
| 108 mapping_.erase(it); | 108 mapping_.erase(it); |
| 109 } | 109 } |
| 110 } | 110 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 132 SetTestingFactory(context, nullptr); | 132 SetTestingFactory(context, nullptr); |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) { | 135 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) { |
| 136 return testing_factories_.find(context) != testing_factories_.end(); | 136 return testing_factories_.find(context) != testing_factories_.end(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) { | 139 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) { |
| 140 GetServiceForContext(context, true); | 140 GetServiceForContext(context, true); |
| 141 } | 141 } |
| OLD | NEW |