Chromium Code Reviews| Index: android_webview/browser/net/android_stream_reader_url_request_job.cc |
| diff --git a/android_webview/browser/net/android_stream_reader_url_request_job.cc b/android_webview/browser/net/android_stream_reader_url_request_job.cc |
| index 2f2d68428cd0619fb27ec650f92a1f343f8b05cf..8e67deaa5fe6842824221be58b0051165f2c601a 100644 |
| --- a/android_webview/browser/net/android_stream_reader_url_request_job.cc |
| +++ b/android_webview/browser/net/android_stream_reader_url_request_job.cc |
| @@ -95,6 +95,17 @@ AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( |
| DCHECK(delegate_); |
| } |
| +AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( |
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate, |
| + scoped_ptr<DelegateObtainer> delegate_obtainer, |
| + bool) |
| + : URLRequestJob(request, network_delegate), |
| + delegate_obtainer_(delegate_obtainer.Pass()), |
| + weak_factory_(this) { |
| + DCHECK(delegate_obtainer_); |
| +} |
| + |
| AndroidStreamReaderURLRequestJob::~AndroidStreamReaderURLRequestJob() { |
| } |
| @@ -123,25 +134,15 @@ void OpenInputStreamOnWorkerThread( |
| void AndroidStreamReaderURLRequestJob::Start() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - // Start reading asynchronously so that all error reporting and data |
| - // callbacks happen as they would for network requests. |
| - SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, |
| - net::ERR_IO_PENDING)); |
| - |
| - // This could be done in the InputStreamReader but would force more |
| - // complex synchronization in the delegate. |
| - GetWorkerThreadRunner()->PostTask( |
| - FROM_HERE, |
| - base::Bind( |
| - &OpenInputStreamOnWorkerThread, |
| - base::MessageLoop::current()->task_runner(), |
| - // This is intentional - the job could be deleted while the callback |
| - // is executing on the background thread. |
| - // The delegate will be "returned" to the job once the InputStream |
| - // open attempt is completed. |
| - base::Passed(&delegate_), request()->url(), |
| - base::Bind(&AndroidStreamReaderURLRequestJob::OnInputStreamOpened, |
| - weak_factory_.GetWeakPtr()))); |
| + if (!delegate_) { |
| + DCHECK(delegate_obtainer_); |
| + delegate_obtainer_->ObtainDelegate( |
| + request(), |
| + base::Bind(&AndroidStreamReaderURLRequestJob::DelegateObtained, |
| + weak_factory_.GetWeakPtr())); |
| + } else { |
| + DoStart(); |
| + } |
| } |
| void AndroidStreamReaderURLRequestJob::Kill() { |
| @@ -290,6 +291,41 @@ bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) { |
| env, request(), input_stream_reader_wrapper_->input_stream(), charset); |
| } |
| +void AndroidStreamReaderURLRequestJob::DelegateObtained( |
| + scoped_ptr<Delegate> delegate) { |
| + DCHECK(!delegate_); |
| + delegate_obtainer_.reset(nullptr); |
|
boliu
2015/10/01 19:13:56
nit: just reset()
mnaganov (inactive)
2015/10/01 19:51:03
Done.
|
| + if (delegate) { |
| + delegate_.swap(delegate); |
|
boliu
2015/10/01 19:13:56
DCHECK(!delegate_) before swap? I think that's cor
mnaganov (inactive)
2015/10/01 19:51:03
Look three lines above :)
|
| + DoStart(); |
| + } else { |
| + NotifyRestartRequired(); |
| + } |
| +} |
| + |
| +void AndroidStreamReaderURLRequestJob::DoStart() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + // Start reading asynchronously so that all error reporting and data |
| + // callbacks happen as they would for network requests. |
| + SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, |
| + net::ERR_IO_PENDING)); |
| + |
| + // This could be done in the InputStreamReader but would force more |
| + // complex synchronization in the delegate. |
| + GetWorkerThreadRunner()->PostTask( |
| + FROM_HERE, |
| + base::Bind( |
| + &OpenInputStreamOnWorkerThread, |
| + base::MessageLoop::current()->task_runner(), |
| + // This is intentional - the job could be deleted while the callback |
| + // is executing on the background thread. |
| + // The delegate will be "returned" to the job once the InputStream |
| + // open attempt is completed. |
| + base::Passed(&delegate_), request()->url(), |
| + base::Bind(&AndroidStreamReaderURLRequestJob::OnInputStreamOpened, |
| + weak_factory_.GetWeakPtr()))); |
| +} |
| + |
| void AndroidStreamReaderURLRequestJob::HeadersComplete( |
| int status_code, |
| const std::string& status_text) { |