mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Merge revision 1230 changes:
- Continue resource loading asynchronously to avoid issues during ResourceScheduler stack unwinding. git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1453@1231 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -58,68 +58,15 @@ class CefResourceRequestJobCallback : public CefCallback {
|
|||||||
dest_size_(0) {}
|
dest_size_(0) {}
|
||||||
|
|
||||||
virtual void Continue() OVERRIDE {
|
virtual void Continue() OVERRIDE {
|
||||||
if (CEF_CURRENTLY_ON_IOT()) {
|
// Continue asynchronously.
|
||||||
// Currently on IO thread.
|
CEF_POST_TASK(CEF_IOT,
|
||||||
// Return early if the callback has already been detached.
|
base::Bind(&CefResourceRequestJobCallback::ContinueOnIOThread, this));
|
||||||
if (!job_)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (type_ == HEADERS_AVAILABLE) {
|
|
||||||
// Callback for headers available.
|
|
||||||
if (!job_->has_response_started()) {
|
|
||||||
// Send header information.
|
|
||||||
job_->SendHeaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
// This type of callback only ever needs to be called once.
|
|
||||||
Detach();
|
|
||||||
} else if (type_ == BYTES_AVAILABLE) {
|
|
||||||
// Callback for bytes available.
|
|
||||||
if (job_->has_response_started() &&
|
|
||||||
job_->GetStatus().is_io_pending()) {
|
|
||||||
// Read the bytes. They should be available but, if not, wait again.
|
|
||||||
int bytes_read = 0;
|
|
||||||
if (job_->ReadRawData(dest_, dest_size_, &bytes_read)) {
|
|
||||||
if (bytes_read > 0) {
|
|
||||||
// Clear the IO_PENDING status.
|
|
||||||
job_->SetStatus(URLRequestStatus());
|
|
||||||
|
|
||||||
// Notify about the available bytes.
|
|
||||||
job_->NotifyReadComplete(bytes_read);
|
|
||||||
|
|
||||||
dest_ = NULL;
|
|
||||||
dest_size_ = 0;
|
|
||||||
} else {
|
|
||||||
// All done.
|
|
||||||
job_->NotifyDone(URLRequestStatus());
|
|
||||||
Detach();
|
|
||||||
}
|
|
||||||
} else if (!job_->GetStatus().is_io_pending()) {
|
|
||||||
// Failed due to an error.
|
|
||||||
NOTREACHED() <<
|
|
||||||
"ReadRawData returned false without setting IO as pending";
|
|
||||||
job_->NotifyDone(URLRequestStatus());
|
|
||||||
Detach();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Execute this method on the IO thread.
|
|
||||||
CEF_POST_TASK(CEF_IOT,
|
|
||||||
base::Bind(&CefResourceRequestJobCallback::Continue, this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Cancel() OVERRIDE {
|
virtual void Cancel() OVERRIDE {
|
||||||
if (CEF_CURRENTLY_ON_IOT()) {
|
// Cancel asynchronously.
|
||||||
// Currently on IO thread.
|
CEF_POST_TASK(CEF_IOT,
|
||||||
if (job_)
|
base::Bind(&CefResourceRequestJobCallback::CancelOnIOThread, this));
|
||||||
job_->Kill();
|
|
||||||
} else {
|
|
||||||
// Execute this method on the IO thread.
|
|
||||||
CEF_POST_TASK(CEF_IOT,
|
|
||||||
base::Bind(&CefResourceRequestJobCallback::Cancel, this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Detach() {
|
void Detach() {
|
||||||
@@ -134,6 +81,61 @@ class CefResourceRequestJobCallback : public CefCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ContinueOnIOThread() {
|
||||||
|
CEF_REQUIRE_IOT();
|
||||||
|
|
||||||
|
// Return early if the callback has already been detached.
|
||||||
|
if (!job_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (type_ == HEADERS_AVAILABLE) {
|
||||||
|
// Callback for headers available.
|
||||||
|
if (!job_->has_response_started()) {
|
||||||
|
// Send header information.
|
||||||
|
job_->SendHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This type of callback only ever needs to be called once.
|
||||||
|
Detach();
|
||||||
|
} else if (type_ == BYTES_AVAILABLE) {
|
||||||
|
// Callback for bytes available.
|
||||||
|
if (job_->has_response_started() &&
|
||||||
|
job_->GetStatus().is_io_pending()) {
|
||||||
|
// Read the bytes. They should be available but, if not, wait again.
|
||||||
|
int bytes_read = 0;
|
||||||
|
if (job_->ReadRawData(dest_, dest_size_, &bytes_read)) {
|
||||||
|
if (bytes_read > 0) {
|
||||||
|
// Clear the IO_PENDING status.
|
||||||
|
job_->SetStatus(URLRequestStatus());
|
||||||
|
|
||||||
|
// Notify about the available bytes.
|
||||||
|
job_->NotifyReadComplete(bytes_read);
|
||||||
|
|
||||||
|
dest_ = NULL;
|
||||||
|
dest_size_ = 0;
|
||||||
|
} else {
|
||||||
|
// All done.
|
||||||
|
job_->NotifyDone(URLRequestStatus());
|
||||||
|
Detach();
|
||||||
|
}
|
||||||
|
} else if (!job_->GetStatus().is_io_pending()) {
|
||||||
|
// Failed due to an error.
|
||||||
|
NOTREACHED() <<
|
||||||
|
"ReadRawData returned false without setting IO as pending";
|
||||||
|
job_->NotifyDone(URLRequestStatus());
|
||||||
|
Detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CancelOnIOThread() {
|
||||||
|
CEF_REQUIRE_IOT();
|
||||||
|
|
||||||
|
if (job_)
|
||||||
|
job_->Kill();
|
||||||
|
}
|
||||||
|
|
||||||
CefResourceRequestJob* job_;
|
CefResourceRequestJob* job_;
|
||||||
Type type_;
|
Type type_;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user