Skip to content

Commit

Permalink
Fix crash in net fetcher (#713) (#785)
Browse files Browse the repository at this point in the history
Crash could occur because of concurrent execution of GetLoadTiminInfo and Stop.
The problem solved by let the content of the GetLoadTimingInfo function
(i.e. ReportLoadTimingInfo) be executed by the delegate thread.

b/266121186

Change-Id: I5249ed823c3cf9ff230e18cfa660a42347c9da99
(cherry picked from commit d0e1689)

Co-authored-by: MichaelSweden <[email protected]>
  • Loading branch information
1 parent 9d5e39e commit 528e98d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion net/url_request/url_fetcher_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ void URLFetcherCore::Start() {
}

void URLFetcherCore::Stop() {
if (delegate_task_runner_) // May be NULL in tests.
if (delegate_task_runner_) { // May be NULL in tests.
DCHECK(delegate_task_runner_->RunsTasksInCurrentSequence());
}

delegate_ = NULL;
fetcher_ = NULL;
Expand Down Expand Up @@ -783,8 +784,11 @@ void URLFetcherCore::StartURLRequest() {
if (!extra_request_headers_.IsEmpty())
request_->SetExtraRequestHeaders(extra_request_headers_);

#if defined(STARBOARD)
request_->SetLoadTimingInfoCallback(base::Bind(&URLFetcherCore::GetLoadTimingInfo,
base::Unretained(this)));
#endif

request_->Start();
}

Expand Down Expand Up @@ -1133,6 +1137,14 @@ void URLFetcherCore::AssertHasNoUploadData() const {
#if defined(STARBOARD)
void URLFetcherCore::GetLoadTimingInfo(
const net::LoadTimingInfo& timing_info) {
delegate_task_runner_->PostTask(
FROM_HERE,
base::Bind(&URLFetcherCore::GetLoadTimingInfoInDelegateThread,
this, timing_info));
}

void URLFetcherCore::GetLoadTimingInfoInDelegateThread(
const net::LoadTimingInfo& timing_info) {
// Check if the URLFetcherCore has been stopped before.
if (delegate_) {
delegate_->ReportLoadTimingInfo(timing_info);
Expand Down
1 change: 1 addition & 0 deletions net/url_request/url_fetcher_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class URLFetcherCore : public base::RefCountedThreadSafe<URLFetcherCore>,
static void SetIgnoreCertificateRequests(bool ignored);
#if defined (STARBOARD)
void GetLoadTimingInfo(const net::LoadTimingInfo& timing_info);
void GetLoadTimingInfoInDelegateThread(const net::LoadTimingInfo& timing_info);
#endif // defined(STARBOARD)
private:
friend class base::RefCountedThreadSafe<URLFetcherCore>;
Expand Down

0 comments on commit 528e98d

Please sign in to comment.