From b7c9f8ba1c54b76913764a654837516476037bf8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 24 Aug 2013 19:46:38 +0800 Subject: [PATCH] The request should go through UI thread. --- browser/api/atom_api_protocol.cc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/browser/api/atom_api_protocol.cc b/browser/api/atom_api_protocol.cc index 21be17e51dd6..8d5f0d104e0c 100644 --- a/browser/api/atom_api_protocol.cc +++ b/browser/api/atom_api_protocol.cc @@ -41,9 +41,10 @@ class AdapterRequestJob : public net::URLRequestJob { protected: virtual void Start() OVERRIDE { DCHECK(!real_job_); - real_job_ = new net::URLRequestErrorJob( - request(), network_delegate(), net::ERR_NOT_IMPLEMENTED); - real_job_->Start(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind(&AdapterRequestJob::GetJobTypeInUI, base::Unretained(this))); } virtual void Kill() OVERRIDE { @@ -94,9 +95,19 @@ class AdapterRequestJob : public net::URLRequestJob { }; void GetJobTypeInUI() { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + content::BrowserThread::PostTask( + content::BrowserThread::IO, + FROM_HERE, + base::Bind(&AdapterRequestJob::CreateJobAndStart, + base::Unretained(this))); } void CreateJobAndStart() { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + real_job_ = new net::URLRequestErrorJob( + request(), network_delegate(), net::ERR_NOT_IMPLEMENTED); + real_job_->Start(); } scoped_refptr real_job_; @@ -141,7 +152,7 @@ v8::Handle Protocol::RegisterProtocol(const v8::Arguments& args) { node::node_isolate, v8::Handle::Cast(args[1])); content::BrowserThread::PostTask(content::BrowserThread::IO, - FROM_HERE, + FROM_HERE, base::Bind(&RegisterProtocolInIO, scheme)); return v8::Undefined(); @@ -158,7 +169,7 @@ v8::Handle Protocol::UnregisterProtocol(const v8::Arguments& args) { handlers_.erase(it); content::BrowserThread::PostTask(content::BrowserThread::IO, - FROM_HERE, + FROM_HERE, base::Bind(&UnregisterProtocolInIO, scheme)); return v8::Undefined();