| 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/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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 = NULL; | 44 = NULL; |
| 45 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ | 45 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ |
| 46 = NULL; | 46 = NULL; |
| 47 | 47 |
| 48 URLRequestAutomationJob::URLRequestAutomationJob( | 48 URLRequestAutomationJob::URLRequestAutomationJob( |
| 49 net::URLRequest* request, | 49 net::URLRequest* request, |
| 50 int tab, | 50 int tab, |
| 51 int request_id, | 51 int request_id, |
| 52 AutomationResourceMessageFilter* filter, | 52 AutomationResourceMessageFilter* filter, |
| 53 bool is_pending) | 53 bool is_pending) |
| 54 : URLRequestJob(request), | 54 : net::URLRequestJob(request), |
| 55 id_(0), | 55 id_(0), |
| 56 tab_(tab), | 56 tab_(tab), |
| 57 message_filter_(filter), | 57 message_filter_(filter), |
| 58 pending_buf_size_(0), | 58 pending_buf_size_(0), |
| 59 redirect_status_(0), | 59 redirect_status_(0), |
| 60 request_id_(request_id), | 60 request_id_(request_id), |
| 61 is_pending_(is_pending), | 61 is_pending_(is_pending), |
| 62 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 62 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 63 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 63 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
| 64 DCHECK(message_filter_ != NULL); | 64 DCHECK(message_filter_ != NULL); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 "http", &URLRequestAutomationJob::Factory); | 83 "http", &URLRequestAutomationJob::Factory); |
| 84 old_https_factory_ = | 84 old_https_factory_ = |
| 85 net::URLRequest::RegisterProtocolFactory( | 85 net::URLRequest::RegisterProtocolFactory( |
| 86 "https", &URLRequestAutomationJob::Factory); | 86 "https", &URLRequestAutomationJob::Factory); |
| 87 is_protocol_factory_registered_ = true; | 87 is_protocol_factory_registered_ = true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 URLRequestJob* URLRequestAutomationJob::Factory(net::URLRequest* request, | 93 net::URLRequestJob* URLRequestAutomationJob::Factory( |
| 94 const std::string& scheme) { | 94 net::URLRequest* request, |
| 95 const std::string& scheme) { |
| 95 bool scheme_is_http = request->url().SchemeIs("http"); | 96 bool scheme_is_http = request->url().SchemeIs("http"); |
| 96 bool scheme_is_https = request->url().SchemeIs("https"); | 97 bool scheme_is_https = request->url().SchemeIs("https"); |
| 97 | 98 |
| 98 // Returning null here just means that the built-in handler will be used. | 99 // Returning null here just means that the built-in handler will be used. |
| 99 if (scheme_is_http || scheme_is_https) { | 100 if (scheme_is_http || scheme_is_https) { |
| 100 ResourceDispatcherHostRequestInfo* request_info = NULL; | 101 ResourceDispatcherHostRequestInfo* request_info = NULL; |
| 101 if (request->GetUserData(NULL)) | 102 if (request->GetUserData(NULL)) |
| 102 request_info = ResourceDispatcherHost::InfoForRequest(request); | 103 request_info = ResourceDispatcherHost::InfoForRequest(request); |
| 103 if (request_info) { | 104 if (request_info) { |
| 104 int child_id = request_info->child_id(); | 105 int child_id = request_info->child_id(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 } | 121 } |
| 121 | 122 |
| 122 if (scheme_is_http && old_http_factory_) | 123 if (scheme_is_http && old_http_factory_) |
| 123 return old_http_factory_(request, scheme); | 124 return old_http_factory_(request, scheme); |
| 124 else if (scheme_is_https && old_https_factory_) | 125 else if (scheme_is_https && old_https_factory_) |
| 125 return old_https_factory_(request, scheme); | 126 return old_https_factory_(request, scheme); |
| 126 } | 127 } |
| 127 return NULL; | 128 return NULL; |
| 128 } | 129 } |
| 129 | 130 |
| 130 // URLRequestJob Implementation. | 131 // net::URLRequestJob Implementation. |
| 131 void URLRequestAutomationJob::Start() { | 132 void URLRequestAutomationJob::Start() { |
| 132 if (!is_pending()) { | 133 if (!is_pending()) { |
| 133 // Start reading asynchronously so that all error reporting and data | 134 // Start reading asynchronously so that all error reporting and data |
| 134 // callbacks happen as they would for network requests. | 135 // callbacks happen as they would for network requests. |
| 135 MessageLoop::current()->PostTask( | 136 MessageLoop::current()->PostTask( |
| 136 FROM_HERE, | 137 FROM_HERE, |
| 137 method_factory_.NewRunnableMethod( | 138 method_factory_.NewRunnableMethod( |
| 138 &URLRequestAutomationJob::StartAsync)); | 139 &URLRequestAutomationJob::StartAsync)); |
| 139 } else { | 140 } else { |
| 140 // If this is a pending job, then register it immediately with the message | 141 // If this is a pending job, then register it immediately with the message |
| 141 // 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 |
| 142 // external host to connect to the corresponding external tab. | 143 // external host to connect to the corresponding external tab. |
| 143 message_filter_->RegisterRequest(this); | 144 message_filter_->RegisterRequest(this); |
| 144 } | 145 } |
| 145 } | 146 } |
| 146 | 147 |
| 147 void URLRequestAutomationJob::Kill() { | 148 void URLRequestAutomationJob::Kill() { |
| 148 if (message_filter_.get()) { | 149 if (message_filter_.get()) { |
| 149 if (!is_pending()) { | 150 if (!is_pending()) { |
| 150 message_filter_->Send(new AutomationMsg_RequestEnd(0, tab_, id_, | 151 message_filter_->Send(new AutomationMsg_RequestEnd(0, tab_, id_, |
| 151 URLRequestStatus(URLRequestStatus::CANCELED, net::ERR_ABORTED))); | 152 URLRequestStatus(URLRequestStatus::CANCELED, net::ERR_ABORTED))); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 DisconnectFromMessageFilter(); | 155 DisconnectFromMessageFilter(); |
| 155 URLRequestJob::Kill(); | 156 net::URLRequestJob::Kill(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 bool URLRequestAutomationJob::ReadRawData( | 159 bool URLRequestAutomationJob::ReadRawData( |
| 159 net::IOBuffer* buf, int buf_size, int* bytes_read) { | 160 net::IOBuffer* buf, int buf_size, int* bytes_read) { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 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()); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (!is_done()) { | 473 if (!is_done()) { |
| 473 NotifyDone(request_status_); | 474 NotifyDone(request_status_); |
| 474 } | 475 } |
| 475 // Reset any pending reads. | 476 // Reset any pending reads. |
| 476 if (pending_buf_) { | 477 if (pending_buf_) { |
| 477 pending_buf_ = NULL; | 478 pending_buf_ = NULL; |
| 478 pending_buf_size_ = 0; | 479 pending_buf_size_ = 0; |
| 479 NotifyReadComplete(0); | 480 NotifyReadComplete(0); |
| 480 } | 481 } |
| 481 } | 482 } |
| OLD | NEW |