| 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/memory/ptr_util.h" |
| 7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 8 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/url_request/http_protocol_handler.h" |
| 9 #include "net/url_request/url_request_interceptor.h" | 11 #include "net/url_request/url_request_interceptor.h" |
| 10 #include "net/url_request/url_request_job_manager.h" | 12 #include "net/url_request/url_request_job_manager.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 #include "url/url_constants.h" |
| 12 | 15 |
| 13 namespace net { | 16 namespace net { |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 17 URLRequestInterceptor* g_interceptor_for_testing = NULL; | 20 URLRequestInterceptor* g_interceptor_for_testing = NULL; |
| 18 | 21 |
| 19 } // namespace | 22 } // namespace |
| 20 | 23 |
| 21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} | 24 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} |
| 22 | 25 |
| 23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {} | 26 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {} |
| 24 | 27 |
| 28 // static |
| 29 std::unique_ptr<URLRequestJobFactoryImpl> |
| 30 URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers() { |
| 31 std::unique_ptr<URLRequestJobFactoryImpl> job_factory( |
| 32 new URLRequestJobFactoryImpl); |
| 33 job_factory->SetProtocolHandler(url::kHttpScheme, |
| 34 base::WrapUnique(new HttpProtocolHandler)); |
| 35 job_factory->SetProtocolHandler(url::kHttpsScheme, |
| 36 base::WrapUnique(new HttpProtocolHandler)); |
| 37 |
| 38 #if !defined(OS_IOS) |
| 39 job_factory->SetProtocolHandler(url::kWsScheme, |
| 40 base::WrapUnique(new HttpProtocolHandler)); |
| 41 job_factory->SetProtocolHandler(url::kWssScheme, |
| 42 base::WrapUnique(new HttpProtocolHandler)); |
| 43 #endif // !defined(OS_IOS) |
| 44 |
| 45 return job_factory; |
| 46 } |
| 47 |
| 25 bool URLRequestJobFactoryImpl::SetProtocolHandler( | 48 bool URLRequestJobFactoryImpl::SetProtocolHandler( |
| 26 const std::string& scheme, | 49 const std::string& scheme, |
| 27 std::unique_ptr<ProtocolHandler> protocol_handler) { | 50 std::unique_ptr<ProtocolHandler> protocol_handler) { |
| 28 DCHECK(CalledOnValidThread()); | 51 DCHECK(CalledOnValidThread()); |
| 29 | 52 |
| 30 if (!protocol_handler) { | 53 if (!protocol_handler) { |
| 31 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); | 54 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); |
| 32 if (it == protocol_handler_map_.end()) | 55 if (it == protocol_handler_map_.end()) |
| 33 return false; | 56 return false; |
| 34 | 57 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 92 |
| 70 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse( | 93 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse( |
| 71 URLRequest* request, | 94 URLRequest* request, |
| 72 NetworkDelegate* network_delegate) const { | 95 NetworkDelegate* network_delegate) const { |
| 73 return nullptr; | 96 return nullptr; |
| 74 } | 97 } |
| 75 | 98 |
| 76 bool URLRequestJobFactoryImpl::IsHandledProtocol( | 99 bool URLRequestJobFactoryImpl::IsHandledProtocol( |
| 77 const std::string& scheme) const { | 100 const std::string& scheme) const { |
| 78 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 79 return base::ContainsKey(protocol_handler_map_, scheme) || | 102 return base::ContainsKey(protocol_handler_map_, scheme); |
| 80 URLRequestJobManager::SupportsScheme(scheme); | |
| 81 } | 103 } |
| 82 | 104 |
| 83 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { | 105 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { |
| 84 if (!url.is_valid()) { | 106 if (!url.is_valid()) { |
| 85 // We handle error cases. | 107 // We handle error cases. |
| 86 return true; | 108 return true; |
| 87 } | 109 } |
| 88 return IsHandledProtocol(url.scheme()); | 110 return IsHandledProtocol(url.scheme()); |
| 89 } | 111 } |
| 90 | 112 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 | 128 |
| 107 // static | 129 // static |
| 108 void URLRequestJobFactoryImpl::SetInterceptorForTesting( | 130 void URLRequestJobFactoryImpl::SetInterceptorForTesting( |
| 109 URLRequestInterceptor* interceptor) { | 131 URLRequestInterceptor* interceptor) { |
| 110 DCHECK(!interceptor || !g_interceptor_for_testing); | 132 DCHECK(!interceptor || !g_interceptor_for_testing); |
| 111 | 133 |
| 112 g_interceptor_for_testing = interceptor; | 134 g_interceptor_for_testing = interceptor; |
| 113 } | 135 } |
| 114 | 136 |
| 115 } // namespace net | 137 } // namespace net |
| OLD | NEW |