| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/url_request/url_request_job_factory_impl.h" | 5 #include "net/url_request/url_request_job_factory_impl.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "net/base/load_flags.h" | 8 #include "net/base/load_flags.h" |
| 9 #include "net/url_request/url_request_interceptor.h" | 9 #include "net/url_request/url_request_interceptor.h" |
| 10 #include "net/url_request/url_request_job_manager.h" | 10 #include "net/url_request/url_request_job_manager.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 URLRequestInterceptor* g_interceptor_for_testing = NULL; | 17 URLRequestInterceptor* g_interceptor_for_testing = NULL; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} | 21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} |
| 22 | 22 |
| 23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() { | 23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() { |
| 24 STLDeleteValues(&protocol_handler_map_); | 24 STLDeleteValues(&protocol_handler_map_); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool URLRequestJobFactoryImpl::SetProtocolHandler( | 27 bool URLRequestJobFactoryImpl::SetProtocolHandler( |
| 28 const std::string& scheme, | 28 const std::string& scheme, |
| 29 ProtocolHandler* protocol_handler) { | 29 scoped_ptr<ProtocolHandler> protocol_handler) { |
| 30 DCHECK(CalledOnValidThread()); | 30 DCHECK(CalledOnValidThread()); |
| 31 | 31 |
| 32 if (!protocol_handler) { | 32 if (!protocol_handler) { |
| 33 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); | 33 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); |
| 34 if (it == protocol_handler_map_.end()) | 34 if (it == protocol_handler_map_.end()) |
| 35 return false; | 35 return false; |
| 36 | 36 |
| 37 delete it->second; | 37 delete it->second; |
| 38 protocol_handler_map_.erase(it); | 38 protocol_handler_map_.erase(it); |
| 39 return true; | 39 return true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 if (ContainsKey(protocol_handler_map_, scheme)) | 42 if (ContainsKey(protocol_handler_map_, scheme)) |
| 43 return false; | 43 return false; |
| 44 protocol_handler_map_[scheme] = protocol_handler; | 44 protocol_handler_map_[scheme] = protocol_handler.release(); |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler( | 48 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithProtocolHandler( |
| 49 const std::string& scheme, | 49 const std::string& scheme, |
| 50 URLRequest* request, | 50 URLRequest* request, |
| 51 NetworkDelegate* network_delegate) const { | 51 NetworkDelegate* network_delegate) const { |
| 52 DCHECK(CalledOnValidThread()); | 52 DCHECK(CalledOnValidThread()); |
| 53 if (g_interceptor_for_testing) { | 53 if (g_interceptor_for_testing) { |
| 54 URLRequestJob* job = g_interceptor_for_testing->MaybeInterceptRequest( | 54 URLRequestJob* job = g_interceptor_for_testing->MaybeInterceptRequest( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 void URLRequestJobFactoryImpl::SetInterceptorForTesting( | 111 void URLRequestJobFactoryImpl::SetInterceptorForTesting( |
| 112 URLRequestInterceptor* interceptor) { | 112 URLRequestInterceptor* interceptor) { |
| 113 DCHECK(!interceptor || !g_interceptor_for_testing); | 113 DCHECK(!interceptor || !g_interceptor_for_testing); |
| 114 | 114 |
| 115 g_interceptor_for_testing = interceptor; | 115 g_interceptor_for_testing = interceptor; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace net | 118 } // namespace net |
| OLD | NEW |