Merge revision 1594 changes:

- Fix completion status for asynchronous custom resource handler requests (issue #1066, issue #1187).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1750@1595 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2014-02-06 00:19:22 +00:00
parent b2b1e4a356
commit 5bc6018fba
2 changed files with 17 additions and 18 deletions

View File

@ -112,19 +112,13 @@ class CefResourceRequestJobCallback : public CefCallback {
dest_size_ = 0; dest_size_ = 0;
dest_ = NULL; dest_ = NULL;
if (bytes_read > 0) { // Clear the IO_PENDING status.
// Clear the IO_PENDING status. job_->SetStatus(URLRequestStatus());
job_->SetStatus(URLRequestStatus());
// Notify about the available bytes. This may cause another call to // Notify about the available bytes. If bytes_read > 0 then
// ReadRawData() from URLRequest::Read. // ReadRawData may be called from URLRequest::Read. If bytes_read == 0
job_->NotifyReadComplete(bytes_read); // then Kill will be called from the URLRequest destructor.
} else { job_->NotifyReadComplete(bytes_read);
// Either we read all requested bytes or the handler detected the
// end of the resource.
job_->NotifyDone(URLRequestStatus());
Detach();
}
} else if (!job_->GetStatus().is_io_pending()) { } else if (!job_->GetStatus().is_io_pending()) {
// Failed due to an error. // Failed due to an error.
NOTREACHED() << NOTREACHED() <<
@ -158,6 +152,7 @@ CefResourceRequestJob::CefResourceRequestJob(
CefRefPtr<CefResourceHandler> handler) CefRefPtr<CefResourceHandler> handler)
: net::URLRequestJob(request, network_delegate), : net::URLRequestJob(request, network_delegate),
handler_(handler), handler_(handler),
done_(false),
remaining_bytes_(0), remaining_bytes_(0),
response_cookies_save_index_(0), response_cookies_save_index_(0),
weak_factory_(this) { weak_factory_(this) {
@ -207,8 +202,10 @@ void CefResourceRequestJob::Start() {
void CefResourceRequestJob::Kill() { void CefResourceRequestJob::Kill() {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
// Notify the handler that the request has been canceled. if (!done_) {
handler_->Cancel(); // Notify the handler that the request has been canceled.
handler_->Cancel();
}
if (callback_) { if (callback_) {
callback_->Detach(); callback_->Detach();
@ -221,16 +218,15 @@ void CefResourceRequestJob::Kill() {
// This method will be called by URLRequestJob::Read and our callback. // This method will be called by URLRequestJob::Read and our callback.
// It can indicate the following states: // It can indicate the following states:
// 1. If the request is complete set |bytes_read| == 0 and return true. The // 1. If the request is complete set |bytes_read| == 0 and return true. The
// caller is then responsible for calling NotifyDone. ReadRawData should not // caller is then responsible for calling NotifyReadComplete. ReadRawData
// be called again. // should not be called again.
// 2. If data is available synchronously set |bytes_read| > 0 and return true. // 2. If data is available synchronously set |bytes_read| > 0 and return true.
// The caller is then responsible for calling NotifyReadComplete. ReadRawData // The caller is then responsible for calling NotifyReadComplete. ReadRawData
// may be called again by URLRequestJob::Read. // may be called again by URLRequestJob::Read.
// 3. If data is not available now but may be available asynchronously set // 3. If data is not available now but may be available asynchronously set
// status to IO_PENDING and return false. When executed asynchronously the // status to IO_PENDING and return false. When executed asynchronously the
// callback will again call ReadRawData. If data is returned at that time the // callback will again call ReadRawData. If data is returned at that time the
// callback will clear the status and call NotifyReadComplete or NotifyDone // callback will clear the status and call NotifyReadComplete.
// as appropriate.
bool CefResourceRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, bool CefResourceRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
int* bytes_read) { int* bytes_read) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
@ -241,6 +237,7 @@ bool CefResourceRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
if (remaining_bytes_ == 0) { if (remaining_bytes_ == 0) {
// No more data to read. // No more data to read.
*bytes_read = 0; *bytes_read = 0;
done_ = true;
return true; return true;
} else if (remaining_bytes_ > 0 && remaining_bytes_ < dest_size) { } else if (remaining_bytes_ > 0 && remaining_bytes_ < dest_size) {
// The handler knows the content size beforehand. // The handler knows the content size beforehand.
@ -260,6 +257,7 @@ bool CefResourceRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
if (!rv) { if (!rv) {
// The handler has indicated completion of the request. // The handler has indicated completion of the request.
*bytes_read = 0; *bytes_read = 0;
done_ = true;
return true; return true;
} else if (*bytes_read == 0) { } else if (*bytes_read == 0) {
// Continue reading asynchronously. May happen multiple times in a row so // Continue reading asynchronously. May happen multiple times in a row so

View File

@ -60,6 +60,7 @@ class CefResourceRequestJob : public net::URLRequestJob {
void FetchResponseCookies(std::vector<std::string>* cookies); void FetchResponseCookies(std::vector<std::string>* cookies);
CefRefPtr<CefResourceHandler> handler_; CefRefPtr<CefResourceHandler> handler_;
bool done_;
CefRefPtr<CefResponse> response_; CefRefPtr<CefResponse> response_;
GURL redirect_url_; GURL redirect_url_;
int64 remaining_bytes_; int64 remaining_bytes_;