diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 4f679f36bc4..b686dc42b1f 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -515,9 +515,18 @@ void Session::DisableNetworkEmulation() { network_emulation_token_, network::mojom::NetworkConditions::New()); } +void WrapVerifyProc(base::Callback)> proc, + const VerifyRequestParams& request, + base::OnceCallback cb) { + proc.Run(request, base::AdaptCallbackForRepeating(std::move(cb))); +} + void Session::SetCertVerifyProc(v8::Local val, mate::Arguments* args) { - AtomCertVerifier::VerifyProc proc; + base::Callback)> + 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 val, BrowserThread::IO, FROM_HERE, base::BindOnce(&SetCertVerifyProcInIO, WrapRefCounted(browser_context_->GetRequestContext()), - proc)); + base::Bind(&WrapVerifyProc, proc))); } void Session::SetPermissionRequestHandler(v8::Local val, diff --git a/atom/browser/net/atom_cert_verifier.cc b/atom/browser/net/atom_cert_verifier.cc index 4e2cc87eee3..2cde41d7436 100644 --- a/atom/browser/net/atom_cert_verifier.cc +++ b/atom/browser/net/atom_cert_verifier.cc @@ -30,14 +30,14 @@ namespace { class Response : public base::LinkNode { 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* 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; } diff --git a/atom/browser/net/atom_cert_verifier.h b/atom/browser/net/atom_cert_verifier.h index 458615f3ed4..356b9b96ce3 100644 --- a/atom/browser/net/atom_cert_verifier.h +++ b/atom/browser/net/atom_cert_verifier.h @@ -38,7 +38,7 @@ class AtomCertVerifier : public net::CertVerifier { ~AtomCertVerifier() override; using VerifyProc = base::Callback; + 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* out_req, const net::NetLogWithSource& net_log) override; bool SupportsOCSPStapling() override; diff --git a/atom/browser/net/atom_network_delegate.cc b/atom/browser/net/atom_network_delegate.cc index c1a36466e65..83eacce38af 100644 --- a/atom/browser/net/atom_network_delegate.cc +++ b/atom/browser/net/atom_network_delegate.cc @@ -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* 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 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, @@ -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 diff --git a/atom/browser/net/atom_network_delegate.h b/atom/browser/net/atom_network_delegate.h index 332632ddf2f..499a44172d1 100644 --- a/atom/browser/net/atom_network_delegate.h +++ b/atom/browser/net/atom_network_delegate.h @@ -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* override_response_headers, GURL* allowed_unsafe_redirect_url) override; @@ -150,7 +150,7 @@ class AtomNetworkDelegate : public net::NetworkDelegate { template 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> login_handler_map_; std::map simple_listeners_; std::map response_listeners_; - std::map callbacks_; + std::map callbacks_; std::vector ignore_connections_limit_domains_; DISALLOW_COPY_AND_ASSIGN(AtomNetworkDelegate);