| 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 "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/url_request/url_request_job_manager.h" | 10 #include "net/url_request/url_request_job_manager.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} | 14 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} |
| 15 | 15 |
| 16 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() { | 16 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() { |
| 17 STLDeleteValues(&protocol_handler_map_); | 17 STLDeleteValues(&protocol_handler_map_); |
| 18 STLDeleteElements(&interceptors_); | 18 STLDeleteElements(&interceptors_); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool URLRequestJobFactoryImpl::SetProtocolHandler( | |
| 22 const std::string& scheme, | |
| 23 ProtocolHandler* protocol_handler) { | |
| 24 DCHECK(CalledOnValidThread()); | |
| 25 | |
| 26 if (!protocol_handler) { | |
| 27 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); | |
| 28 if (it == protocol_handler_map_.end()) | |
| 29 return false; | |
| 30 | |
| 31 delete it->second; | |
| 32 protocol_handler_map_.erase(it); | |
| 33 return true; | |
| 34 } | |
| 35 | |
| 36 if (ContainsKey(protocol_handler_map_, scheme)) | |
| 37 return false; | |
| 38 protocol_handler_map_[scheme] = protocol_handler; | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 void URLRequestJobFactoryImpl::AddInterceptor(Interceptor* interceptor) { | |
| 43 DCHECK(CalledOnValidThread()); | |
| 44 CHECK(interceptor); | |
| 45 | |
| 46 interceptors_.push_back(interceptor); | |
| 47 } | |
| 48 | |
| 49 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithInterceptor( | 21 URLRequestJob* URLRequestJobFactoryImpl::MaybeCreateJobWithInterceptor( |
| 50 URLRequest* request, NetworkDelegate* network_delegate) const { | 22 URLRequest* request, NetworkDelegate* network_delegate) const { |
| 51 DCHECK(CalledOnValidThread()); | 23 DCHECK(CalledOnValidThread()); |
| 52 URLRequestJob* job = NULL; | 24 URLRequestJob* job = NULL; |
| 53 | 25 |
| 54 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 26 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
| 55 InterceptorList::const_iterator i; | 27 InterceptorList::const_iterator i; |
| 56 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 28 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
| 57 job = (*i)->MaybeIntercept(request, network_delegate); | 29 job = (*i)->MaybeIntercept(request, network_delegate); |
| 58 if (job) | 30 if (job) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 92 } |
| 121 | 93 |
| 122 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { | 94 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { |
| 123 if (!url.is_valid()) { | 95 if (!url.is_valid()) { |
| 124 // We handle error cases. | 96 // We handle error cases. |
| 125 return true; | 97 return true; |
| 126 } | 98 } |
| 127 return IsHandledProtocol(url.scheme()); | 99 return IsHandledProtocol(url.scheme()); |
| 128 } | 100 } |
| 129 | 101 |
| 102 bool URLRequestJobFactoryImpl::SetProtocolHandler( |
| 103 const std::string& scheme, |
| 104 ProtocolHandler* protocol_handler) { |
| 105 DCHECK(CalledOnValidThread()); |
| 106 |
| 107 if (!protocol_handler) { |
| 108 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); |
| 109 if (it == protocol_handler_map_.end()) |
| 110 return false; |
| 111 |
| 112 delete it->second; |
| 113 protocol_handler_map_.erase(it); |
| 114 return true; |
| 115 } |
| 116 |
| 117 if (ContainsKey(protocol_handler_map_, scheme)) |
| 118 return false; |
| 119 protocol_handler_map_[scheme] = protocol_handler; |
| 120 return true; |
| 121 } |
| 122 |
| 123 void URLRequestJobFactoryImpl::AddInterceptor(Interceptor* interceptor) { |
| 124 DCHECK(CalledOnValidThread()); |
| 125 CHECK(interceptor); |
| 126 |
| 127 interceptors_.push_back(interceptor); |
| 128 } |
| 129 |
| 130 } // namespace net | 130 } // namespace net |
| OLD | NEW |