Don't read Buffer in IO thread
This commit is contained in:
parent
d78efe7c22
commit
b202bba2e6
6 changed files with 26 additions and 26 deletions
|
@ -42,6 +42,14 @@ namespace {
|
||||||
|
|
||||||
typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
|
typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
|
||||||
|
|
||||||
|
scoped_refptr<base::RefCountedBytes> BufferToRefCountedBytes(
|
||||||
|
v8::Local<v8::Value> buf) {
|
||||||
|
scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes);
|
||||||
|
auto start = reinterpret_cast<const unsigned char*>(node::Buffer::Data(buf));
|
||||||
|
data->data().assign(start, start + node::Buffer::Length(buf));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
class CustomProtocolRequestJob : public AdapterRequestJob {
|
class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
public:
|
public:
|
||||||
CustomProtocolRequestJob(Protocol* registry,
|
CustomProtocolRequestJob(Protocol* registry,
|
||||||
|
@ -95,7 +103,8 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
|
|
||||||
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
base::Bind(&AdapterRequestJob::CreateBufferJobAndStart,
|
base::Bind(&AdapterRequestJob::CreateBufferJobAndStart,
|
||||||
GetWeakPtr(), mime_type, encoding, buffer->ToObject()));
|
GetWeakPtr(), mime_type, encoding,
|
||||||
|
BufferToRefCountedBytes(buffer)));
|
||||||
return;
|
return;
|
||||||
} else if (name == "RequestFileJob") {
|
} else if (name == "RequestFileJob") {
|
||||||
base::FilePath path;
|
base::FilePath path;
|
||||||
|
|
|
@ -71,8 +71,6 @@ base::WeakPtr<AdapterRequestJob> AdapterRequestJob::GetWeakPtr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
|
void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
|
||||||
|
|
||||||
real_job_ = new net::URLRequestErrorJob(
|
real_job_ = new net::URLRequestErrorJob(
|
||||||
request(), network_delegate(), error_code);
|
request(), network_delegate(), error_code);
|
||||||
real_job_->Start();
|
real_job_->Start();
|
||||||
|
@ -81,25 +79,21 @@ void AdapterRequestJob::CreateErrorJobAndStart(int error_code) {
|
||||||
void AdapterRequestJob::CreateStringJobAndStart(const std::string& mime_type,
|
void AdapterRequestJob::CreateStringJobAndStart(const std::string& mime_type,
|
||||||
const std::string& charset,
|
const std::string& charset,
|
||||||
const std::string& data) {
|
const std::string& data) {
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
|
||||||
|
|
||||||
real_job_ = new URLRequestStringJob(
|
real_job_ = new URLRequestStringJob(
|
||||||
request(), network_delegate(), mime_type, charset, data);
|
request(), network_delegate(), mime_type, charset, data);
|
||||||
real_job_->Start();
|
real_job_->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateBufferJobAndStart(const std::string& mime_type,
|
void AdapterRequestJob::CreateBufferJobAndStart(
|
||||||
const std::string& charset,
|
const std::string& mime_type,
|
||||||
v8::Local<v8::Object> buffer) {
|
const std::string& charset,
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
scoped_refptr<base::RefCountedBytes> data) {
|
||||||
|
|
||||||
real_job_ = new URLRequestBufferJob(
|
real_job_ = new URLRequestBufferJob(
|
||||||
request(), network_delegate(), mime_type, charset, buffer);
|
request(), network_delegate(), mime_type, charset, data);
|
||||||
real_job_->Start();
|
real_job_->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
|
||||||
real_job_ = asar::CreateJobFromPath(
|
real_job_ = asar::CreateJobFromPath(
|
||||||
path,
|
path,
|
||||||
request(),
|
request(),
|
||||||
|
@ -111,8 +105,6 @@ void AdapterRequestJob::CreateFileJobAndStart(const base::FilePath& path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
|
void AdapterRequestJob::CreateJobFromProtocolHandlerAndStart() {
|
||||||
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
|
|
||||||
DCHECK(protocol_handler_);
|
|
||||||
real_job_ = protocol_handler_->MaybeCreateJob(request(),
|
real_job_ = protocol_handler_->MaybeCreateJob(request(),
|
||||||
network_delegate());
|
network_delegate());
|
||||||
if (!real_job_.get())
|
if (!real_job_.get())
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/memory/ref_counted_memory.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "net/url_request/url_request_job.h"
|
#include "net/url_request/url_request_job.h"
|
||||||
#include "net/url_request/url_request_job_factory.h"
|
#include "net/url_request/url_request_job_factory.h"
|
||||||
|
@ -53,7 +54,7 @@ class AdapterRequestJob : public net::URLRequestJob {
|
||||||
const std::string& data);
|
const std::string& data);
|
||||||
void CreateBufferJobAndStart(const std::string& mime_type,
|
void CreateBufferJobAndStart(const std::string& mime_type,
|
||||||
const std::string& charset,
|
const std::string& charset,
|
||||||
v8::Local<v8::Object> buffer);
|
scoped_refptr<base::RefCountedBytes> data);
|
||||||
void CreateFileJobAndStart(const base::FilePath& path);
|
void CreateFileJobAndStart(const base::FilePath& path);
|
||||||
void CreateJobFromProtocolHandlerAndStart();
|
void CreateJobFromProtocolHandlerAndStart();
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,16 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
URLRequestBufferJob::URLRequestBufferJob(net::URLRequest* request,
|
URLRequestBufferJob::URLRequestBufferJob(
|
||||||
net::NetworkDelegate* network_delegate,
|
net::URLRequest* request,
|
||||||
const std::string& mime_type,
|
net::NetworkDelegate* network_delegate,
|
||||||
const std::string& charset,
|
const std::string& mime_type,
|
||||||
v8::Local<v8::Object> data)
|
const std::string& charset,
|
||||||
|
scoped_refptr<base::RefCountedBytes> data)
|
||||||
: net::URLRequestSimpleJob(request, network_delegate),
|
: net::URLRequestSimpleJob(request, network_delegate),
|
||||||
mime_type_(mime_type),
|
mime_type_(mime_type),
|
||||||
charset_(charset),
|
charset_(charset),
|
||||||
buffer_data_(new base::RefCountedBytes()) {
|
buffer_data_(data) {
|
||||||
auto input = reinterpret_cast<const unsigned char*>(node::Buffer::Data(data));
|
|
||||||
size_t length = node::Buffer::Length(data);
|
|
||||||
buffer_data_->data().assign(input, input + length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int URLRequestBufferJob::GetRefCountedData(
|
int URLRequestBufferJob::GetRefCountedData(
|
||||||
|
|
|
@ -19,7 +19,7 @@ class URLRequestBufferJob : public net::URLRequestSimpleJob {
|
||||||
net::NetworkDelegate* network_delegate,
|
net::NetworkDelegate* network_delegate,
|
||||||
const std::string& mime_type,
|
const std::string& mime_type,
|
||||||
const std::string& charset,
|
const std::string& charset,
|
||||||
v8::Local<v8::Object> buffer);
|
scoped_refptr<base::RefCountedBytes> data);
|
||||||
|
|
||||||
// URLRequestSimpleJob:
|
// URLRequestSimpleJob:
|
||||||
int GetRefCountedData(std::string* mime_type,
|
int GetRefCountedData(std::string* mime_type,
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 269be869988bda9a7e8ad0ef56af178a741af09c
|
Subproject commit 1696237a3f444f0e33a8947749b4d70f6feb511b
|
Loading…
Reference in a new issue