OLD | NEW |
1 // Copyright (c) 2010 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 "chrome/browser/automation/url_request_automation_job.h" | 5 #include "chrome/browser/automation/url_request_automation_job.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/automation/automation_resource_message_filter.h" | 10 #include "chrome/browser/automation/automation_resource_message_filter.h" |
11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // filter so it can be serviced later when we receive a request from the | 142 // filter so it can be serviced later when we receive a request from the |
143 // external host to connect to the corresponding external tab. | 143 // external host to connect to the corresponding external tab. |
144 message_filter_->RegisterRequest(this); | 144 message_filter_->RegisterRequest(this); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 void URLRequestAutomationJob::Kill() { | 148 void URLRequestAutomationJob::Kill() { |
149 if (message_filter_.get()) { | 149 if (message_filter_.get()) { |
150 if (!is_pending()) { | 150 if (!is_pending()) { |
151 message_filter_->Send(new AutomationMsg_RequestEnd(tab_, id_, | 151 message_filter_->Send(new AutomationMsg_RequestEnd(tab_, id_, |
152 URLRequestStatus(URLRequestStatus::CANCELED, net::ERR_ABORTED))); | 152 net::URLRequestStatus(net::URLRequestStatus::CANCELED, |
| 153 net::ERR_ABORTED))); |
153 } | 154 } |
154 } | 155 } |
155 DisconnectFromMessageFilter(); | 156 DisconnectFromMessageFilter(); |
156 net::URLRequestJob::Kill(); | 157 net::URLRequestJob::Kill(); |
157 } | 158 } |
158 | 159 |
159 bool URLRequestAutomationJob::ReadRawData( | 160 bool URLRequestAutomationJob::ReadRawData( |
160 net::IOBuffer* buf, int buf_size, int* bytes_read) { | 161 net::IOBuffer* buf, int buf_size, int* bytes_read) { |
161 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() | 162 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() |
162 << " - read pending: " << buf_size; | 163 << " - read pending: " << buf_size; |
163 | 164 |
164 // We should not receive a read request for a pending job. | 165 // We should not receive a read request for a pending job. |
165 DCHECK(!is_pending()); | 166 DCHECK(!is_pending()); |
166 | 167 |
167 pending_buf_ = buf; | 168 pending_buf_ = buf; |
168 pending_buf_size_ = buf_size; | 169 pending_buf_size_ = buf_size; |
169 | 170 |
170 if (message_filter_) { | 171 if (message_filter_) { |
171 message_filter_->Send(new AutomationMsg_RequestRead(tab_, id_, buf_size)); | 172 message_filter_->Send(new AutomationMsg_RequestRead(tab_, id_, buf_size)); |
172 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 173 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
173 } else { | 174 } else { |
174 MessageLoop::current()->PostTask( | 175 MessageLoop::current()->PostTask( |
175 FROM_HERE, | 176 FROM_HERE, |
176 method_factory_.NewRunnableMethod( | 177 method_factory_.NewRunnableMethod( |
177 &URLRequestAutomationJob::NotifyJobCompletionTask)); | 178 &URLRequestAutomationJob::NotifyJobCompletionTask)); |
178 } | 179 } |
179 return false; | 180 return false; |
180 } | 181 } |
181 | 182 |
182 bool URLRequestAutomationJob::GetMimeType(std::string* mime_type) const { | 183 bool URLRequestAutomationJob::GetMimeType(std::string* mime_type) const { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 286 } |
286 | 287 |
287 void URLRequestAutomationJob::OnDataAvailable( | 288 void URLRequestAutomationJob::OnDataAvailable( |
288 int id, const std::string& bytes) { | 289 int id, const std::string& bytes) { |
289 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() | 290 DVLOG(1) << "URLRequestAutomationJob: " << request_->url().spec() |
290 << " - data available, Size: " << bytes.size(); | 291 << " - data available, Size: " << bytes.size(); |
291 DCHECK(!bytes.empty()); | 292 DCHECK(!bytes.empty()); |
292 | 293 |
293 // The request completed, and we have all the data. | 294 // The request completed, and we have all the data. |
294 // Clear any IO pending status. | 295 // Clear any IO pending status. |
295 SetStatus(URLRequestStatus()); | 296 SetStatus(net::URLRequestStatus()); |
296 | 297 |
297 if (pending_buf_ && pending_buf_->data()) { | 298 if (pending_buf_ && pending_buf_->data()) { |
298 DCHECK_GE(pending_buf_size_, bytes.size()); | 299 DCHECK_GE(pending_buf_size_, bytes.size()); |
299 const int bytes_to_copy = std::min(bytes.size(), pending_buf_size_); | 300 const int bytes_to_copy = std::min(bytes.size(), pending_buf_size_); |
300 memcpy(pending_buf_->data(), &bytes[0], bytes_to_copy); | 301 memcpy(pending_buf_->data(), &bytes[0], bytes_to_copy); |
301 | 302 |
302 pending_buf_ = NULL; | 303 pending_buf_ = NULL; |
303 pending_buf_size_ = 0; | 304 pending_buf_size_ = 0; |
304 | 305 |
305 NotifyReadComplete(bytes_to_copy); | 306 NotifyReadComplete(bytes_to_copy); |
306 } else { | 307 } else { |
307 NOTREACHED() << "Received unexpected data of length:" << bytes.size(); | 308 NOTREACHED() << "Received unexpected data of length:" << bytes.size(); |
308 } | 309 } |
309 } | 310 } |
310 | 311 |
311 void URLRequestAutomationJob::OnRequestEnd( | 312 void URLRequestAutomationJob::OnRequestEnd( |
312 int id, const URLRequestStatus& status) { | 313 int id, const net::URLRequestStatus& status) { |
313 #ifndef NDEBUG | 314 #ifndef NDEBUG |
314 std::string url; | 315 std::string url; |
315 if (request_) | 316 if (request_) |
316 url = request_->url().spec(); | 317 url = request_->url().spec(); |
317 DVLOG(1) << "URLRequestAutomationJob: " << url << " - request end. Status: " | 318 DVLOG(1) << "URLRequestAutomationJob: " << url << " - request end. Status: " |
318 << status.status(); | 319 << status.status(); |
319 #endif | 320 #endif |
320 | 321 |
321 // TODO(tommi): When we hit certificate errors, notify the delegate via | 322 // TODO(tommi): When we hit certificate errors, notify the delegate via |
322 // OnSSLCertificateError(). Right now we don't have the certificate | 323 // OnSSLCertificateError(). Right now we don't have the certificate |
323 // so we don't. We could possibly call OnSSLCertificateError with a NULL | 324 // so we don't. We could possibly call OnSSLCertificateError with a NULL |
324 // certificate, but I'm not sure if all implementations expect it. | 325 // certificate, but I'm not sure if all implementations expect it. |
325 // if (status.status() == URLRequestStatus::FAILED && | 326 // if (status.status() == net::URLRequestStatus::FAILED && |
326 // net::IsCertificateError(status.os_error()) && request_->delegate()) { | 327 // net::IsCertificateError(status.os_error()) && request_->delegate()) { |
327 // request_->delegate()->OnSSLCertificateError(request_, status.os_error()); | 328 // request_->delegate()->OnSSLCertificateError(request_, status.os_error()); |
328 // } | 329 // } |
329 | 330 |
330 DisconnectFromMessageFilter(); | 331 DisconnectFromMessageFilter(); |
331 // NotifyDone may have been called on the job if the original request was | 332 // NotifyDone may have been called on the job if the original request was |
332 // redirected. | 333 // redirected. |
333 if (!is_done()) { | 334 if (!is_done()) { |
334 // We can complete the job if we have a valid response or a pending read. | 335 // We can complete the job if we have a valid response or a pending read. |
335 // An end request can be received in the following cases | 336 // An end request can be received in the following cases |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 375 |
375 // If the job is cancelled before we got a chance to start it | 376 // If the job is cancelled before we got a chance to start it |
376 // we have nothing much to do here. | 377 // we have nothing much to do here. |
377 if (is_done()) | 378 if (is_done()) |
378 return; | 379 return; |
379 | 380 |
380 // We should not receive a Start request for a pending job. | 381 // We should not receive a Start request for a pending job. |
381 DCHECK(!is_pending()); | 382 DCHECK(!is_pending()); |
382 | 383 |
383 if (!request_) { | 384 if (!request_) { |
384 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, | 385 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
385 net::ERR_FAILED)); | 386 net::ERR_FAILED)); |
386 return; | 387 return; |
387 } | 388 } |
388 | 389 |
389 // Register this request with automation message filter. | 390 // Register this request with automation message filter. |
390 message_filter_->RegisterRequest(this); | 391 message_filter_->RegisterRequest(this); |
391 | 392 |
392 // Strip unwanted headers. | 393 // Strip unwanted headers. |
393 net::HttpRequestHeaders new_request_headers; | 394 net::HttpRequestHeaders new_request_headers; |
394 new_request_headers.MergeFrom(request_->extra_request_headers()); | 395 new_request_headers.MergeFrom(request_->extra_request_headers()); |
395 for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i) | 396 for (size_t i = 0; i < arraysize(kFilteredHeaderStrings); ++i) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!is_done()) { | 468 if (!is_done()) { |
468 NotifyDone(request_status_); | 469 NotifyDone(request_status_); |
469 } | 470 } |
470 // Reset any pending reads. | 471 // Reset any pending reads. |
471 if (pending_buf_) { | 472 if (pending_buf_) { |
472 pending_buf_ = NULL; | 473 pending_buf_ = NULL; |
473 pending_buf_size_ = 0; | 474 pending_buf_size_ = 0; |
474 NotifyReadComplete(0); | 475 NotifyReadComplete(0); |
475 } | 476 } |
476 } | 477 } |
OLD | NEW |