OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_manager.h" | 5 #include "net/url_request/url_request_job_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 { "about", URLRequestAboutJob::Factory }, | 41 { "about", URLRequestAboutJob::Factory }, |
42 { "data", URLRequestDataJob::Factory }, | 42 { "data", URLRequestDataJob::Factory }, |
43 }; | 43 }; |
44 | 44 |
45 // static | 45 // static |
46 URLRequestJobManager* URLRequestJobManager::GetInstance() { | 46 URLRequestJobManager* URLRequestJobManager::GetInstance() { |
47 return Singleton<URLRequestJobManager>::get(); | 47 return Singleton<URLRequestJobManager>::get(); |
48 } | 48 } |
49 | 49 |
50 URLRequestJob* URLRequestJobManager::CreateJob( | 50 URLRequestJob* URLRequestJobManager::CreateJob( |
51 URLRequest* request) const { | 51 URLRequest* request, NetworkDelegate* network_delegate) const { |
52 DCHECK(IsAllowedThread()); | 52 DCHECK(IsAllowedThread()); |
53 | 53 |
54 // If we are given an invalid URL, then don't even try to inspect the scheme. | 54 // If we are given an invalid URL, then don't even try to inspect the scheme. |
55 if (!request->url().is_valid()) | 55 if (!request->url().is_valid()) |
56 return new URLRequestErrorJob(request, ERR_INVALID_URL); | 56 return new URLRequestErrorJob(request, network_delegate, ERR_INVALID_URL); |
57 | 57 |
58 // We do this here to avoid asking interceptors about unsupported schemes. | 58 // We do this here to avoid asking interceptors about unsupported schemes. |
59 const URLRequestJobFactory* job_factory = NULL; | 59 const URLRequestJobFactory* job_factory = NULL; |
60 job_factory = request->context()->job_factory(); | 60 job_factory = request->context()->job_factory(); |
61 | 61 |
62 const std::string& scheme = request->url().scheme(); // already lowercase | 62 const std::string& scheme = request->url().scheme(); // already lowercase |
63 if (job_factory) { | 63 if (job_factory) { |
64 if (!job_factory->IsHandledProtocol(scheme)) { | 64 if (!job_factory->IsHandledProtocol(scheme)) { |
65 return new URLRequestErrorJob(request, ERR_UNKNOWN_URL_SCHEME); | 65 return new URLRequestErrorJob( |
| 66 request, network_delegate, ERR_UNKNOWN_URL_SCHEME); |
66 } | 67 } |
67 } else if (!SupportsScheme(scheme)) { | 68 } else if (!SupportsScheme(scheme)) { |
68 return new URLRequestErrorJob(request, ERR_UNKNOWN_URL_SCHEME); | 69 return new URLRequestErrorJob( |
| 70 request, network_delegate, ERR_UNKNOWN_URL_SCHEME); |
69 } | 71 } |
70 | 72 |
71 // THREAD-SAFETY NOTICE: | 73 // THREAD-SAFETY NOTICE: |
72 // We do not need to acquire the lock here since we are only reading our | 74 // We do not need to acquire the lock here since we are only reading our |
73 // data structures. They should only be modified on the current thread. | 75 // data structures. They should only be modified on the current thread. |
74 | 76 |
75 // See if the request should be intercepted. | 77 // See if the request should be intercepted. |
76 // | 78 // |
77 | 79 |
78 if (job_factory) { | 80 if (job_factory) { |
79 URLRequestJob* job = job_factory->MaybeCreateJobWithInterceptor(request); | 81 URLRequestJob* job = job_factory->MaybeCreateJobWithInterceptor( |
| 82 request, network_delegate); |
80 if (job) | 83 if (job) |
81 return job; | 84 return job; |
82 } | 85 } |
83 | 86 |
84 // TODO(willchan): Remove this in favor of URLRequestJobFactory::Interceptor. | 87 // TODO(willchan): Remove this in favor of URLRequestJobFactory::Interceptor. |
85 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { | 88 if (!(request->load_flags() & LOAD_DISABLE_INTERCEPT)) { |
86 InterceptorList::const_iterator i; | 89 InterceptorList::const_iterator i; |
87 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { | 90 for (i = interceptors_.begin(); i != interceptors_.end(); ++i) { |
88 URLRequestJob* job = (*i)->MaybeIntercept(request); | 91 URLRequestJob* job = (*i)->MaybeIntercept(request, network_delegate); |
89 if (job) | 92 if (job) |
90 return job; | 93 return job; |
91 } | 94 } |
92 } | 95 } |
93 | 96 |
94 if (job_factory) { | 97 if (job_factory) { |
95 URLRequestJob* job = | 98 URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler( |
96 job_factory->MaybeCreateJobWithProtocolHandler(scheme, request); | 99 scheme, request, network_delegate); |
97 if (job) | 100 if (job) |
98 return job; | 101 return job; |
99 } | 102 } |
100 | 103 |
101 // TODO(willchan): Remove this in favor of | 104 // TODO(willchan): Remove this in favor of |
102 // URLRequestJobFactory::ProtocolHandler. | 105 // URLRequestJobFactory::ProtocolHandler. |
103 // See if the request should be handled by a registered protocol factory. | 106 // See if the request should be handled by a registered protocol factory. |
104 // If the registered factory returns null, then we want to fall-back to the | 107 // If the registered factory returns null, then we want to fall-back to the |
105 // built-in protocol factory. | 108 // built-in protocol factory. |
106 FactoryMap::const_iterator i = factories_.find(scheme); | 109 FactoryMap::const_iterator i = factories_.find(scheme); |
107 if (i != factories_.end()) { | 110 if (i != factories_.end()) { |
108 URLRequestJob* job = i->second(request, scheme); | 111 URLRequestJob* job = i->second(request, network_delegate, scheme); |
109 if (job) | 112 if (job) |
110 return job; | 113 return job; |
111 } | 114 } |
112 | 115 |
113 // See if the request should be handled by a built-in protocol factory. | 116 // See if the request should be handled by a built-in protocol factory. |
114 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) { | 117 for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) { |
115 if (scheme == kBuiltinFactories[i].scheme) { | 118 if (scheme == kBuiltinFactories[i].scheme) { |
116 URLRequestJob* job = (kBuiltinFactories[i].factory)(request, scheme); | 119 URLRequestJob* job = (kBuiltinFactories[i].factory)( |
| 120 request, network_delegate, scheme); |
117 DCHECK(job); // The built-in factories are not expected to fail! | 121 DCHECK(job); // The built-in factories are not expected to fail! |
118 return job; | 122 return job; |
119 } | 123 } |
120 } | 124 } |
121 | 125 |
122 // If we reached here, then it means that a registered protocol factory | 126 // If we reached here, then it means that a registered protocol factory |
123 // wasn't interested in handling the URL. That is fairly unexpected, and we | 127 // wasn't interested in handling the URL. That is fairly unexpected, and we |
124 // don't have a specific error to report here :-( | 128 // don't have a specific error to report here :-( |
125 LOG(WARNING) << "Failed to map: " << request->url().spec(); | 129 LOG(WARNING) << "Failed to map: " << request->url().spec(); |
126 return new URLRequestErrorJob(request, ERR_FAILED); | 130 return new URLRequestErrorJob(request, network_delegate, ERR_FAILED); |
127 } | 131 } |
128 | 132 |
129 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( | 133 URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect( |
130 URLRequest* request, | 134 URLRequest* request, |
131 const GURL& location) const { | 135 const GURL& location) const { |
132 DCHECK(IsAllowedThread()); | 136 DCHECK(IsAllowedThread()); |
133 if (!request->url().is_valid() || | 137 if (!request->url().is_valid() || |
134 request->load_flags() & LOAD_DISABLE_INTERCEPT || | 138 request->load_flags() & LOAD_DISABLE_INTERCEPT || |
135 request->status().status() == URLRequestStatus::CANCELED) { | 139 request->status().status() == URLRequestStatus::CANCELED) { |
136 return NULL; | 140 return NULL; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 264 } |
261 | 265 |
262 URLRequestJobManager::URLRequestJobManager() | 266 URLRequestJobManager::URLRequestJobManager() |
263 : allowed_thread_(0), | 267 : allowed_thread_(0), |
264 allowed_thread_initialized_(false) { | 268 allowed_thread_initialized_(false) { |
265 } | 269 } |
266 | 270 |
267 URLRequestJobManager::~URLRequestJobManager() {} | 271 URLRequestJobManager::~URLRequestJobManager() {} |
268 | 272 |
269 } // namespace net | 273 } // namespace net |
OLD | NEW |