| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "chrome/browser/automation/automation_resource_message_filter.h" | 9 #include "chrome/browser/automation/automation_resource_message_filter.h" |
| 10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 "max-forwards", | 32 "max-forwards", |
| 33 "proxy-authorization", | 33 "proxy-authorization", |
| 34 "te", | 34 "te", |
| 35 "upgrade", | 35 "upgrade", |
| 36 "via" | 36 "via" |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 int URLRequestAutomationJob::instance_count_ = 0; | 39 int URLRequestAutomationJob::instance_count_ = 0; |
| 40 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; | 40 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; |
| 41 | 41 |
| 42 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ | 42 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ |
| 43 = NULL; | 43 = NULL; |
| 44 URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ | 44 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ |
| 45 = NULL; | 45 = NULL; |
| 46 | 46 |
| 47 URLRequestAutomationJob::URLRequestAutomationJob(URLRequest* request, int tab, | 47 URLRequestAutomationJob::URLRequestAutomationJob( |
| 48 int request_id, AutomationResourceMessageFilter* filter, bool is_pending) | 48 net::URLRequest* request, |
| 49 int tab, |
| 50 int request_id, |
| 51 AutomationResourceMessageFilter* filter, |
| 52 bool is_pending) |
| 49 : URLRequestJob(request), | 53 : URLRequestJob(request), |
| 50 id_(0), | 54 id_(0), |
| 51 tab_(tab), | 55 tab_(tab), |
| 52 message_filter_(filter), | 56 message_filter_(filter), |
| 53 pending_buf_size_(0), | 57 pending_buf_size_(0), |
| 54 redirect_status_(0), | 58 redirect_status_(0), |
| 55 request_id_(request_id), | 59 request_id_(request_id), |
| 56 is_pending_(is_pending) { | 60 is_pending_(is_pending) { |
| 57 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 61 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
| 58 DCHECK(message_filter_ != NULL); | 62 DCHECK(message_filter_ != NULL); |
| 59 | 63 |
| 60 if (message_filter_) { | 64 if (message_filter_) { |
| 61 id_ = message_filter_->NewAutomationRequestId(); | 65 id_ = message_filter_->NewAutomationRequestId(); |
| 62 DCHECK_NE(id_, 0); | 66 DCHECK_NE(id_, 0); |
| 63 } | 67 } |
| 64 } | 68 } |
| 65 | 69 |
| 66 URLRequestAutomationJob::~URLRequestAutomationJob() { | 70 URLRequestAutomationJob::~URLRequestAutomationJob() { |
| 67 DVLOG(1) << "URLRequestAutomationJob delete. Count: " << --instance_count_; | 71 DVLOG(1) << "URLRequestAutomationJob delete. Count: " << --instance_count_; |
| 68 Cleanup(); | 72 Cleanup(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() { | 75 bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 73 | 77 |
| 74 if (!is_protocol_factory_registered_) { | 78 if (!is_protocol_factory_registered_) { |
| 75 old_http_factory_ = | 79 old_http_factory_ = |
| 76 URLRequest::RegisterProtocolFactory("http", | 80 net::URLRequest::RegisterProtocolFactory( |
| 77 &URLRequestAutomationJob::Factory); | 81 "http", &URLRequestAutomationJob::Factory); |
| 78 old_https_factory_ = | 82 old_https_factory_ = |
| 79 URLRequest::RegisterProtocolFactory("https", | 83 net::URLRequest::RegisterProtocolFactory( |
| 80 &URLRequestAutomationJob::Factory); | 84 "https", &URLRequestAutomationJob::Factory); |
| 81 is_protocol_factory_registered_ = true; | 85 is_protocol_factory_registered_ = true; |
| 82 } | 86 } |
| 83 | 87 |
| 84 return true; | 88 return true; |
| 85 } | 89 } |
| 86 | 90 |
| 87 URLRequestJob* URLRequestAutomationJob::Factory(URLRequest* request, | 91 URLRequestJob* URLRequestAutomationJob::Factory(net::URLRequest* request, |
| 88 const std::string& scheme) { | 92 const std::string& scheme) { |
| 89 bool scheme_is_http = request->url().SchemeIs("http"); | 93 bool scheme_is_http = request->url().SchemeIs("http"); |
| 90 bool scheme_is_https = request->url().SchemeIs("https"); | 94 bool scheme_is_https = request->url().SchemeIs("https"); |
| 91 | 95 |
| 92 // Returning null here just means that the built-in handler will be used. | 96 // Returning null here just means that the built-in handler will be used. |
| 93 if (scheme_is_http || scheme_is_https) { | 97 if (scheme_is_http || scheme_is_https) { |
| 94 ResourceDispatcherHostRequestInfo* request_info = NULL; | 98 ResourceDispatcherHostRequestInfo* request_info = NULL; |
| 95 if (request->GetUserData(NULL)) | 99 if (request->GetUserData(NULL)) |
| 96 request_info = ResourceDispatcherHost::InfoForRequest(request); | 100 request_info = ResourceDispatcherHost::InfoForRequest(request); |
| 97 if (request_info) { | 101 if (request_info) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 if (!is_done()) { | 466 if (!is_done()) { |
| 463 NotifyDone(request_status_); | 467 NotifyDone(request_status_); |
| 464 } | 468 } |
| 465 // Reset any pending reads. | 469 // Reset any pending reads. |
| 466 if (pending_buf_) { | 470 if (pending_buf_) { |
| 467 pending_buf_ = NULL; | 471 pending_buf_ = NULL; |
| 468 pending_buf_size_ = 0; | 472 pending_buf_size_ = 0; |
| 469 NotifyReadComplete(0); | 473 NotifyReadComplete(0); |
| 470 } | 474 } |
| 471 } | 475 } |
| OLD | NEW |