Use CompletionOnceCallback
several CLs, e.g. https://chromium-review.googlesource.com/c/chromium/src/+/1092933
This commit is contained in:
Родитель
ec1bd5375a
Коммит
18128a1582
|
@ -515,9 +515,18 @@ void Session::DisableNetworkEmulation() {
|
|||
network_emulation_token_, network::mojom::NetworkConditions::New());
|
||||
}
|
||||
|
||||
void WrapVerifyProc(base::Callback<void(const VerifyRequestParams& request,
|
||||
base::Callback<void(int)>)> proc,
|
||||
const VerifyRequestParams& request,
|
||||
base::OnceCallback<void(int)> cb) {
|
||||
proc.Run(request, base::AdaptCallbackForRepeating(std::move(cb)));
|
||||
}
|
||||
|
||||
void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
||||
mate::Arguments* args) {
|
||||
AtomCertVerifier::VerifyProc proc;
|
||||
base::Callback<void(const VerifyRequestParams& request,
|
||||
base::Callback<void(int)>)>
|
||||
proc;
|
||||
if (!(val->IsNull() || mate::ConvertFromV8(args->isolate(), val, &proc))) {
|
||||
args->ThrowError("Must pass null or function");
|
||||
return;
|
||||
|
@ -527,7 +536,7 @@ void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
|
|||
BrowserThread::IO, FROM_HERE,
|
||||
base::BindOnce(&SetCertVerifyProcInIO,
|
||||
WrapRefCounted(browser_context_->GetRequestContext()),
|
||||
proc));
|
||||
base::Bind(&WrapVerifyProc, proc)));
|
||||
}
|
||||
|
||||
void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,
|
||||
|
|
|
@ -30,14 +30,14 @@ namespace {
|
|||
class Response : public base::LinkNode<Response> {
|
||||
public:
|
||||
Response(net::CertVerifyResult* verify_result,
|
||||
const net::CompletionCallback& callback)
|
||||
: verify_result_(verify_result), callback_(callback) {}
|
||||
net::CompletionOnceCallback callback)
|
||||
: verify_result_(verify_result), callback_(std::move(callback)) {}
|
||||
net::CertVerifyResult* verify_result() { return verify_result_; }
|
||||
net::CompletionCallback callback() { return callback_; }
|
||||
net::CompletionOnceCallback callback() { return std::move(callback_); }
|
||||
|
||||
private:
|
||||
net::CertVerifyResult* verify_result_;
|
||||
net::CompletionCallback callback_;
|
||||
net::CompletionOnceCallback callback_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Response);
|
||||
};
|
||||
|
@ -130,8 +130,8 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
|
|||
}
|
||||
|
||||
void AddResponseListener(net::CertVerifyResult* verify_result,
|
||||
const net::CompletionCallback& callback) {
|
||||
response_list_.Append(new Response(verify_result, callback));
|
||||
net::CompletionOnceCallback callback) {
|
||||
response_list_.Append(new Response(verify_result, std::move(callback)));
|
||||
}
|
||||
|
||||
const AtomCertVerifier::RequestParams& params() const { return params_; }
|
||||
|
@ -163,15 +163,15 @@ void AtomCertVerifier::SetVerifyProc(const VerifyProc& proc) {
|
|||
int AtomCertVerifier::Verify(const RequestParams& params,
|
||||
net::CRLSet* crl_set,
|
||||
net::CertVerifyResult* verify_result,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
std::unique_ptr<Request>* out_req,
|
||||
const net::NetLogWithSource& net_log) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
|
||||
if (verify_proc_.is_null()) {
|
||||
ct_delegate_->ClearCTExcludedHostsList();
|
||||
return default_cert_verifier_->Verify(params, crl_set, verify_result,
|
||||
callback, out_req, net_log);
|
||||
return default_cert_verifier_->Verify(
|
||||
params, crl_set, verify_result, std::move(callback), out_req, net_log);
|
||||
} else {
|
||||
CertVerifierRequest* request = FindRequest(params);
|
||||
if (!request) {
|
||||
|
@ -182,7 +182,7 @@ int AtomCertVerifier::Verify(const RequestParams& params,
|
|||
*out_req = std::move(new_request);
|
||||
inflight_requests_[params] = request;
|
||||
}
|
||||
request->AddResponseListener(verify_result, callback);
|
||||
request->AddResponseListener(verify_result, std::move(callback));
|
||||
|
||||
return net::ERR_IO_PENDING;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class AtomCertVerifier : public net::CertVerifier {
|
|||
~AtomCertVerifier() override;
|
||||
|
||||
using VerifyProc = base::Callback<void(const VerifyRequestParams& request,
|
||||
const net::CompletionCallback&)>;
|
||||
net::CompletionOnceCallback)>;
|
||||
|
||||
void SetVerifyProc(const VerifyProc& proc);
|
||||
|
||||
|
@ -53,7 +53,7 @@ class AtomCertVerifier : public net::CertVerifier {
|
|||
int Verify(const RequestParams& params,
|
||||
net::CRLSet* crl_set,
|
||||
net::CertVerifyResult* verify_result,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
std::unique_ptr<Request>* out_req,
|
||||
const net::NetLogWithSource& net_log) override;
|
||||
bool SupportsOCSPStapling() override;
|
||||
|
|
|
@ -269,7 +269,7 @@ void AtomNetworkDelegate::SetResponseListenerInIO(ResponseEvent type,
|
|||
|
||||
int AtomNetworkDelegate::OnBeforeURLRequest(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
GURL* new_url) {
|
||||
if (!base::ContainsKey(response_listeners_, kOnBeforeRequest)) {
|
||||
for (const auto& domain : ignore_connections_limit_domains_) {
|
||||
|
@ -283,18 +283,19 @@ int AtomNetworkDelegate::OnBeforeURLRequest(
|
|||
return net::OK;
|
||||
}
|
||||
|
||||
return HandleResponseEvent(kOnBeforeRequest, request, callback, new_url);
|
||||
return HandleResponseEvent(kOnBeforeRequest, request, std::move(callback),
|
||||
new_url);
|
||||
}
|
||||
|
||||
int AtomNetworkDelegate::OnBeforeStartTransaction(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
net::HttpRequestHeaders* headers) {
|
||||
if (!base::ContainsKey(response_listeners_, kOnBeforeSendHeaders))
|
||||
return net::OK;
|
||||
|
||||
return HandleResponseEvent(kOnBeforeSendHeaders, request, callback, headers,
|
||||
*headers);
|
||||
return HandleResponseEvent(kOnBeforeSendHeaders, request, std::move(callback),
|
||||
headers, *headers);
|
||||
}
|
||||
|
||||
void AtomNetworkDelegate::OnStartTransaction(
|
||||
|
@ -308,7 +309,7 @@ void AtomNetworkDelegate::OnStartTransaction(
|
|||
|
||||
int AtomNetworkDelegate::OnHeadersReceived(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
const net::HttpResponseHeaders* original,
|
||||
scoped_refptr<net::HttpResponseHeaders>* override,
|
||||
GURL* allowed) {
|
||||
|
@ -316,7 +317,7 @@ int AtomNetworkDelegate::OnHeadersReceived(
|
|||
return net::OK;
|
||||
|
||||
return HandleResponseEvent(
|
||||
kOnHeadersReceived, request, callback,
|
||||
kOnHeadersReceived, request, std::move(callback),
|
||||
std::make_pair(override, original->GetStatusLine()), original);
|
||||
}
|
||||
|
||||
|
@ -463,7 +464,7 @@ template <typename Out, typename... Args>
|
|||
int AtomNetworkDelegate::HandleResponseEvent(
|
||||
ResponseEvent type,
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
Out out,
|
||||
Args... args) {
|
||||
const auto& info = response_listeners_[type];
|
||||
|
@ -478,7 +479,7 @@ int AtomNetworkDelegate::HandleResponseEvent(
|
|||
request, &render_process_id, &render_frame_id);
|
||||
|
||||
// The |request| could be destroyed before the |callback| is called.
|
||||
callbacks_[request->identifier()] = callback;
|
||||
callbacks_[request->identifier()] = std::move(callback);
|
||||
|
||||
ResponseCallback response =
|
||||
base::Bind(&AtomNetworkDelegate::OnListenerResultInUI<Out>,
|
||||
|
@ -524,7 +525,7 @@ void AtomNetworkDelegate::OnListenerResultInIO(
|
|||
|
||||
bool cancel = false;
|
||||
response->GetBoolean("cancel", &cancel);
|
||||
callbacks_[id].Run(cancel ? net::ERR_BLOCKED_BY_CLIENT : net::OK);
|
||||
std::move(callbacks_[id]).Run(cancel ? net::ERR_BLOCKED_BY_CLIENT : net::OK);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -82,10 +82,10 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
|||
protected:
|
||||
// net::NetworkDelegate:
|
||||
int OnBeforeURLRequest(net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
GURL* new_url) override;
|
||||
int OnBeforeStartTransaction(net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
net::HttpRequestHeaders* headers) override;
|
||||
void OnBeforeSendHeaders(net::URLRequest* request,
|
||||
const net::ProxyInfo& proxy_info,
|
||||
|
@ -95,7 +95,7 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
|||
const net::HttpRequestHeaders& headers) override;
|
||||
int OnHeadersReceived(
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
const net::HttpResponseHeaders* original_response_headers,
|
||||
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
|
||||
GURL* allowed_unsafe_redirect_url) override;
|
||||
|
@ -150,7 +150,7 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
|||
template <typename Out, typename... Args>
|
||||
int HandleResponseEvent(ResponseEvent type,
|
||||
net::URLRequest* request,
|
||||
const net::CompletionCallback& callback,
|
||||
net::CompletionOnceCallback callback,
|
||||
Out out,
|
||||
Args... args);
|
||||
|
||||
|
@ -167,7 +167,7 @@ class AtomNetworkDelegate : public net::NetworkDelegate {
|
|||
std::map<uint64_t, scoped_refptr<LoginHandler>> login_handler_map_;
|
||||
std::map<SimpleEvent, SimpleListenerInfo> simple_listeners_;
|
||||
std::map<ResponseEvent, ResponseListenerInfo> response_listeners_;
|
||||
std::map<uint64_t, net::CompletionCallback> callbacks_;
|
||||
std::map<uint64_t, net::CompletionOnceCallback> callbacks_;
|
||||
std::vector<std::string> ignore_connections_limit_domains_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);
|
||||
|
|
Загрузка…
Ссылка в новой задаче