Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: components/keyed_service/core/keyed_service_factory.cc

Issue 1165913002: [Cleanup] Used scoped pointers in KeyedServiceFactory's SetTestingFactory functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "components/keyed_service/core/dependency_manager.h" 10 #include "components/keyed_service/core/dependency_manager.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (it != mapping_.end()) 70 if (it != mapping_.end())
71 return it->second; 71 return it->second;
72 72
73 // Object not found. 73 // Object not found.
74 if (!create) 74 if (!create)
75 return nullptr; // And we're forbidden from creating one. 75 return nullptr; // And we're forbidden from creating one.
76 76
77 // Create new object. 77 // Create new object.
78 // Check to see if we have a per-context testing factory that we should use 78 // Check to see if we have a per-context testing factory that we should use
79 // instead of default behavior. 79 // instead of default behavior.
80 KeyedService* service = nullptr; 80 scoped_ptr<KeyedService> service;
81 const auto& jt = testing_factories_.find(context); 81 const auto& jt = testing_factories_.find(context);
82 if (jt != testing_factories_.end()) { 82 if (jt != testing_factories_.end()) {
83 if (jt->second) { 83 if (jt->second) {
84 if (!IsOffTheRecord(context)) 84 if (!IsOffTheRecord(context))
85 RegisterUserPrefsOnContextForTest(context); 85 RegisterUserPrefsOnContextForTest(context);
86 service = jt->second(context); 86 service = jt->second(context);
87 } 87 }
88 } else { 88 } else {
89 service = BuildServiceInstanceFor(context); 89 service = BuildServiceInstanceFor(context);
90 } 90 }
91 91
92 Associate(context, service); 92 Associate(context, service.Pass());
93 return service; 93 return mapping_[context];
94 } 94 }
95 95
96 void KeyedServiceFactory::Associate(base::SupportsUserData* context, 96 void KeyedServiceFactory::Associate(base::SupportsUserData* context,
97 KeyedService* service) { 97 scoped_ptr<KeyedService> service) {
98 DCHECK(!ContainsKey(mapping_, context)); 98 DCHECK(!ContainsKey(mapping_, context));
99 mapping_.insert(std::make_pair(context, service)); 99 mapping_.insert(std::make_pair(context, service.release()));
100 } 100 }
101 101
102 void KeyedServiceFactory::Disassociate(base::SupportsUserData* context) { 102 void KeyedServiceFactory::Disassociate(base::SupportsUserData* context) {
103 const auto& it = mapping_.find(context); 103 const auto& it = mapping_.find(context);
104 if (it != mapping_.end()) { 104 if (it != mapping_.end()) {
105 delete it->second; 105 delete it->second;
106 mapping_.erase(it); 106 mapping_.erase(it);
107 } 107 }
108 } 108 }
109 109
(...skipping 20 matching lines...) Expand all
130 SetTestingFactory(context, nullptr); 130 SetTestingFactory(context, nullptr);
131 } 131 }
132 132
133 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) { 133 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) {
134 return testing_factories_.find(context) != testing_factories_.end(); 134 return testing_factories_.find(context) != testing_factories_.end();
135 } 135 }
136 136
137 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) { 137 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) {
138 GetServiceForContext(context, true); 138 GetServiceForContext(context, true);
139 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698