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.h" | 5 #include "net/url_request/url_request_job_factory.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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 void URLRequestJobFactory::AddInterceptor(Interceptor* interceptor) { | 51 void URLRequestJobFactory::AddInterceptor(Interceptor* interceptor) { |
52 DCHECK(CalledOnValidThread()); | 52 DCHECK(CalledOnValidThread()); |
53 CHECK(interceptor); | 53 CHECK(interceptor); |
54 | 54 |
55 interceptors_.push_back(interceptor); | 55 interceptors_.push_back(interceptor); |
56 } | 56 } |
57 | 57 |
58 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithInterceptor( | 58 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithInterceptor( |
59 URLRequest* request) const { | 59 URLRequest* request, NetworkDelegate* network_delegate) const { |
60 DCHECK(CalledOnValidThread()); | 60 DCHECK(CalledOnValidThread()); |
61 URLRequestJob* job = NULL; | 61 URLRequestJob* job = NULL; |
62 | 62 |
63 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 63 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
64 InterceptorList::const_iterator i; | 64 InterceptorList::const_iterator i; |
65 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 65 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
66 job = (*i)->MaybeIntercept(request); | 66 job = (*i)->MaybeIntercept(request, network_delegate); |
67 if (job) | 67 if (job) |
68 return job; | 68 return job; |
69 } | 69 } |
70 } | 70 } |
71 return NULL; | 71 return NULL; |
72 } | 72 } |
73 | 73 |
74 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithProtocolHandler( | 74 URLRequestJob* URLRequestJobFactory::MaybeCreateJobWithProtocolHandler( |
75 const std::string& scheme, | 75 const std::string& scheme, |
76 URLRequest* request) const { | 76 URLRequest* request, |
| 77 NetworkDelegate* network_delegate) const { |
77 DCHECK(CalledOnValidThread()); | 78 DCHECK(CalledOnValidThread()); |
78 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme); | 79 ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(scheme); |
79 if (it == protocol_handler_map_.end()) | 80 if (it == protocol_handler_map_.end()) |
80 return NULL; | 81 return NULL; |
81 return it->second->MaybeCreateJob(request); | 82 return it->second->MaybeCreateJob(request, network_delegate); |
82 } | 83 } |
83 | 84 |
84 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect( | 85 URLRequestJob* URLRequestJobFactory::MaybeInterceptRedirect( |
85 const GURL& location, | 86 const GURL& location, |
86 URLRequest* request) const { | 87 URLRequest* request, |
| 88 NetworkDelegate* network_delegate) const { |
87 DCHECK(CalledOnValidThread()); | 89 DCHECK(CalledOnValidThread()); |
88 URLRequestJob* job = NULL; | 90 URLRequestJob* job = NULL; |
89 | 91 |
90 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 92 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
91 InterceptorList::const_iterator i; | 93 InterceptorList::const_iterator i; |
92 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 94 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
93 job = (*i)->MaybeInterceptRedirect(location, request); | 95 job = (*i)->MaybeInterceptRedirect(location, request, network_delegate); |
94 if (job) | 96 if (job) |
95 return job; | 97 return job; |
96 } | 98 } |
97 } | 99 } |
98 return NULL; | 100 return NULL; |
99 } | 101 } |
100 | 102 |
101 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse( | 103 URLRequestJob* URLRequestJobFactory::MaybeInterceptResponse( |
102 URLRequest* request) const { | 104 URLRequest* request, NetworkDelegate* network_delegate) const { |
103 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
104 URLRequestJob* job = NULL; | 106 URLRequestJob* job = NULL; |
105 | 107 |
106 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 108 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
107 InterceptorList::const_iterator i; | 109 InterceptorList::const_iterator i; |
108 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 110 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
109 job = (*i)->MaybeInterceptResponse(request); | 111 job = (*i)->MaybeInterceptResponse(request, network_delegate); |
110 if (job) | 112 if (job) |
111 return job; | 113 return job; |
112 } | 114 } |
113 } | 115 } |
114 return NULL; | 116 return NULL; |
115 } | 117 } |
116 | 118 |
117 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const { | 119 bool URLRequestJobFactory::IsHandledProtocol(const std::string& scheme) const { |
118 DCHECK(CalledOnValidThread()); | 120 DCHECK(CalledOnValidThread()); |
119 InterceptorList::const_iterator i; | 121 InterceptorList::const_iterator i; |
120 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 122 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
121 if ((*i)->WillHandleProtocol(scheme)) | 123 if ((*i)->WillHandleProtocol(scheme)) |
122 return true; | 124 return true; |
123 } | 125 } |
124 return ContainsKey(protocol_handler_map_, scheme) || | 126 return ContainsKey(protocol_handler_map_, scheme) || |
125 URLRequestJobManager::GetInstance()->SupportsScheme(scheme); | 127 URLRequestJobManager::GetInstance()->SupportsScheme(scheme); |
126 } | 128 } |
127 | 129 |
128 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const { | 130 bool URLRequestJobFactory::IsHandledURL(const GURL& url) const { |
129 if (!url.is_valid()) { | 131 if (!url.is_valid()) { |
130 // We handle error cases. | 132 // We handle error cases. |
131 return true; | 133 return true; |
132 } | 134 } |
133 return IsHandledProtocol(url.scheme()); | 135 return IsHandledProtocol(url.scheme()); |
134 } | 136 } |
135 | 137 |
136 } // namespace net | 138 } // namespace net |
OLD | NEW |