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" |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 URLRequestInterceptor* g_interceptor_for_testing = NULL; | 19 URLRequestInterceptor* g_interceptor_for_testing = NULL; |
18 | 20 |
19 } // namespace | 21 } // namespace |
20 | 22 |
21 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} | 23 URLRequestJobFactoryImpl::URLRequestJobFactoryImpl() {} |
22 | 24 |
23 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {} | 25 URLRequestJobFactoryImpl::~URLRequestJobFactoryImpl() {} |
24 | 26 |
27 // static | |
28 std::unique_ptr<URLRequestJobFactoryImpl> | |
29 URLRequestJobFactoryImpl::CreateWithDefaultProtocolHandlers() { | |
30 URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; | |
31 job_factory->SetProtocolHandler("http", | |
mmenke
2016/04/21 20:58:01
Maybe use the constants in url/url_constants inste
mgersh
2016/04/22 20:27:15
Done.
| |
32 base::WrapUnique(new HttpProtocolHandler)); | |
33 job_factory->SetProtocolHandler("https", | |
34 base::WrapUnique(new HttpProtocolHandler)); | |
35 | |
36 #if !defined(OS_IOS) | |
37 job_factory->SetProtocolHandler("ws", | |
38 base::WrapUnique(new HttpProtocolHandler)); | |
39 job_factory->SetProtocolHandler("wss", | |
40 base::WrapUnique(new HttpProtocolHandler)); | |
41 #endif // !defined(OS_IOS) | |
42 | |
43 return base::WrapUnique(job_factory); | |
mmenke
2016/04/21 20:58:01
Better to make job_factory a unique_ptr, and then
mgersh
2016/04/22 20:27:15
Done.
| |
44 } | |
45 | |
25 bool URLRequestJobFactoryImpl::SetProtocolHandler( | 46 bool URLRequestJobFactoryImpl::SetProtocolHandler( |
26 const std::string& scheme, | 47 const std::string& scheme, |
27 std::unique_ptr<ProtocolHandler> protocol_handler) { | 48 std::unique_ptr<ProtocolHandler> protocol_handler) { |
28 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
29 | 50 |
30 if (!protocol_handler) { | 51 if (!protocol_handler) { |
31 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); | 52 ProtocolHandlerMap::iterator it = protocol_handler_map_.find(scheme); |
32 if (it == protocol_handler_map_.end()) | 53 if (it == protocol_handler_map_.end()) |
33 return false; | 54 return false; |
34 | 55 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 | 90 |
70 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse( | 91 URLRequestJob* URLRequestJobFactoryImpl::MaybeInterceptResponse( |
71 URLRequest* request, | 92 URLRequest* request, |
72 NetworkDelegate* network_delegate) const { | 93 NetworkDelegate* network_delegate) const { |
73 return nullptr; | 94 return nullptr; |
74 } | 95 } |
75 | 96 |
76 bool URLRequestJobFactoryImpl::IsHandledProtocol( | 97 bool URLRequestJobFactoryImpl::IsHandledProtocol( |
77 const std::string& scheme) const { | 98 const std::string& scheme) const { |
78 DCHECK(CalledOnValidThread()); | 99 DCHECK(CalledOnValidThread()); |
79 return ContainsKey(protocol_handler_map_, scheme) || | 100 return ContainsKey(protocol_handler_map_, scheme); |
80 URLRequestJobManager::SupportsScheme(scheme); | |
81 } | 101 } |
82 | 102 |
83 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { | 103 bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const { |
84 if (!url.is_valid()) { | 104 if (!url.is_valid()) { |
85 // We handle error cases. | 105 // We handle error cases. |
86 return true; | 106 return true; |
87 } | 107 } |
88 return IsHandledProtocol(url.scheme()); | 108 return IsHandledProtocol(url.scheme()); |
89 } | 109 } |
90 | 110 |
(...skipping 15 matching lines...) Expand all Loading... | |
106 | 126 |
107 // static | 127 // static |
108 void URLRequestJobFactoryImpl::SetInterceptorForTesting( | 128 void URLRequestJobFactoryImpl::SetInterceptorForTesting( |
109 URLRequestInterceptor* interceptor) { | 129 URLRequestInterceptor* interceptor) { |
110 DCHECK(!interceptor || !g_interceptor_for_testing); | 130 DCHECK(!interceptor || !g_interceptor_for_testing); |
111 | 131 |
112 g_interceptor_for_testing = interceptor; | 132 g_interceptor_for_testing = interceptor; |
113 } | 133 } |
114 | 134 |
115 } // namespace net | 135 } // namespace net |
OLD | NEW |