| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_frame/urlmon_url_request.h" | 5 #include "chrome_frame/urlmon_url_request.h" |
| 6 | 6 |
| 7 #include <wininet.h> | 7 #include <wininet.h> |
| 8 | 8 |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool UrlmonUrlRequest::Start() { | 41 bool UrlmonUrlRequest::Start() { |
| 42 DCHECK_EQ(PlatformThread::CurrentId(), thread_); | 42 DCHECK_EQ(PlatformThread::CurrentId(), thread_); |
| 43 | 43 |
| 44 if (!worker_thread_) { | 44 if (!worker_thread_) { |
| 45 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; | 45 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 worker_thread_->message_loop()->PostTask( | |
| 50 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StartAsync)); | |
| 51 | |
| 52 // Take a self reference to maintain COM lifetime. This will be released | 49 // Take a self reference to maintain COM lifetime. This will be released |
| 53 // in EndRequest | 50 // in EndRequest |
| 54 AddRef(); | 51 AddRef(); |
| 55 request_handler()->AddRequest(this); | 52 request_handler()->AddRequest(this); |
| 53 |
| 54 worker_thread_->message_loop()->PostTask( |
| 55 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StartAsync)); |
| 56 |
| 56 return true; | 57 return true; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void UrlmonUrlRequest::Stop() { | 60 void UrlmonUrlRequest::Stop() { |
| 60 DCHECK_EQ(PlatformThread::CurrentId(), thread_); | 61 DCHECK_EQ(PlatformThread::CurrentId(), thread_); |
| 61 | 62 |
| 62 if (!worker_thread_) { | 63 if (!worker_thread_) { |
| 63 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; | 64 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; |
| 64 return; | 65 return; |
| 65 } | 66 } |
| 66 | 67 |
| 68 // We can remove the request from the map safely here if it is still valid. |
| 69 // There is an additional reference on the UrlmonUrlRequest instance which |
| 70 // is released when the task scheduled by the EndRequest function executes. |
| 71 request_handler()->RemoveRequest(this); |
| 72 |
| 67 worker_thread_->message_loop()->PostTask( | 73 worker_thread_->message_loop()->PostTask( |
| 68 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StopAsync)); | 74 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StopAsync)); |
| 69 } | 75 } |
| 70 | 76 |
| 71 void UrlmonUrlRequest::StartAsync() { | 77 void UrlmonUrlRequest::StartAsync() { |
| 72 DCHECK(worker_thread_ != NULL); | 78 DCHECK(worker_thread_ != NULL); |
| 73 | 79 |
| 74 status_.set_status(URLRequestStatus::IO_PENDING); | 80 status_.set_status(URLRequestStatus::IO_PENDING); |
| 75 HRESULT hr = StartAsyncDownload(); | 81 HRESULT hr = StartAsyncDownload(); |
| 76 if (FAILED(hr)) { | 82 if (FAILED(hr)) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 " Status: " << status_.status(); | 204 " Status: " << status_.status(); |
| 199 if (FAILED(result)) { | 205 if (FAILED(result)) { |
| 200 status_.set_status(URLRequestStatus::FAILED); | 206 status_.set_status(URLRequestStatus::FAILED); |
| 201 status_.set_os_error(HresultToNetError(result)); | 207 status_.set_os_error(HresultToNetError(result)); |
| 202 EndRequest(); | 208 EndRequest(); |
| 203 } else { | 209 } else { |
| 204 status_.set_status(URLRequestStatus::SUCCESS); | 210 status_.set_status(URLRequestStatus::SUCCESS); |
| 205 status_.set_os_error(0); | 211 status_.set_os_error(0); |
| 206 } | 212 } |
| 207 | 213 |
| 214 DLOG(INFO) << "OnStopBinding received for request id: " << id(); |
| 215 |
| 208 // Release these variables after reporting EndRequest since we might need to | 216 // Release these variables after reporting EndRequest since we might need to |
| 209 // access their state. | 217 // access their state. |
| 210 binding_ = NULL; | 218 binding_ = NULL; |
| 211 bind_context_ = NULL; | 219 bind_context_ = NULL; |
| 212 | 220 |
| 213 return S_OK; | 221 return S_OK; |
| 214 } | 222 } |
| 215 | 223 |
| 216 STDMETHODIMP UrlmonUrlRequest::GetBindInfo(DWORD* bind_flags, | 224 STDMETHODIMP UrlmonUrlRequest::GetBindInfo(DWORD* bind_flags, |
| 217 BINDINFO *bind_info) { | 225 BINDINFO *bind_info) { |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 DCHECK(task_marshaller_ != NULL); | 606 DCHECK(task_marshaller_ != NULL); |
| 599 | 607 |
| 600 // Remove the request mapping and release the outstanding reference to us in | 608 // Remove the request mapping and release the outstanding reference to us in |
| 601 // the context of the UI thread. | 609 // the context of the UI thread. |
| 602 task_marshaller_->PostTask( | 610 task_marshaller_->PostTask( |
| 603 FROM_HERE, NewRunnableMethod(this, | 611 FROM_HERE, NewRunnableMethod(this, |
| 604 &UrlmonUrlRequest::EndRequestInternal)); | 612 &UrlmonUrlRequest::EndRequestInternal)); |
| 605 } | 613 } |
| 606 | 614 |
| 607 void UrlmonUrlRequest::EndRequestInternal() { | 615 void UrlmonUrlRequest::EndRequestInternal() { |
| 616 // The request object could have been removed from the map in the |
| 617 // OnRequestEnd callback which executes on receiving the |
| 618 // AutomationMsg_RequestEnd IPC from Chrome. |
| 608 request_handler()->RemoveRequest(this); | 619 request_handler()->RemoveRequest(this); |
| 609 // Release the outstanding reference in the context of the UI thread to | 620 // Release the outstanding reference in the context of the UI thread to |
| 610 // ensure that our instance gets deleted in the same thread which created it. | 621 // ensure that our instance gets deleted in the same thread which created it. |
| 611 Release(); | 622 Release(); |
| 612 } | 623 } |
| 613 | 624 |
| 614 int UrlmonUrlRequest::GetHttpResponseStatus() const { | 625 int UrlmonUrlRequest::GetHttpResponseStatus() const { |
| 615 if (binding_ == NULL) { | 626 if (binding_ == NULL) { |
| 616 DLOG(WARNING) << "GetHttpResponseStatus - no binding_"; | 627 DLOG(WARNING) << "GetHttpResponseStatus - no binding_"; |
| 617 return 0; | 628 return 0; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 ret = net::ERR_ACCESS_DENIED; | 810 ret = net::ERR_ACCESS_DENIED; |
| 800 break; | 811 break; |
| 801 | 812 |
| 802 default: | 813 default: |
| 803 DLOG(WARNING) | 814 DLOG(WARNING) |
| 804 << StringPrintf("TODO: translate HRESULT 0x%08X to net::Error", hr); | 815 << StringPrintf("TODO: translate HRESULT 0x%08X to net::Error", hr); |
| 805 break; | 816 break; |
| 806 } | 817 } |
| 807 return ret; | 818 return ret; |
| 808 } | 819 } |
| OLD | NEW |