Browse Source

chore: tidy up usage of PendingRemote (#26176)

David Sanders 4 years ago
parent
commit
98b0ccbdb1

+ 8 - 7
shell/browser/net/electron_url_loader_factory.cc

@@ -213,9 +213,11 @@ void ElectronURLLoaderFactory::OnComplete(
     mojo::PendingRemote<network::mojom::URLLoaderClient> client,
     int32_t request_id,
     const network::URLLoaderCompletionStatus& status) {
-  mojo::Remote<network::mojom::URLLoaderClient> client_remote(
-      std::move(client));
-  client_remote->OnComplete(status);
+  if (client.is_valid()) {
+    mojo::Remote<network::mojom::URLLoaderClient> client_remote(
+        std::move(client));
+    client_remote->OnComplete(status);
+  }
 }
 
 // static
@@ -294,14 +296,13 @@ void ElectronURLLoaderFactory::StartLoading(
     // module.
     //
     // I'm not sure whether this is an intended behavior in Chromium.
-    mojo::Remote<network::mojom::URLLoaderFactory> proxy_factory_remote(
-        std::move(proxy_factory));
+    if (proxy_factory.is_valid()) {
+      mojo::Remote<network::mojom::URLLoaderFactory> proxy_factory_remote(
+          std::move(proxy_factory));
 
-    if (proxy_factory_remote.is_bound()) {
       proxy_factory_remote->CreateLoaderAndStart(
           std::move(loader), routing_id, request_id, options, new_request,
           std::move(client), traffic_annotation);
-      proxy_factory = proxy_factory_remote.Unbind();
     } else {
       StartLoadingHttp(std::move(loader), new_request, std::move(client),
                        traffic_annotation,

+ 3 - 3
shell/browser/net/proxying_url_loader_factory.cc

@@ -802,8 +802,8 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(
   // Check if user has intercepted this scheme.
   auto it = intercepted_handlers_.find(request.url.scheme());
   if (it != intercepted_handlers_.end()) {
-    mojo::Remote<network::mojom::URLLoaderFactory> loader_remote;
-    this->Clone(loader_remote.BindNewPipeAndPassReceiver());
+    mojo::PendingRemote<network::mojom::URLLoaderFactory> loader_remote;
+    this->Clone(loader_remote.InitWithNewPipeAndPassReceiver());
 
     // <scheme, <type, handler>>
     it->second.second.Run(
@@ -811,7 +811,7 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(
         base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
                        std::move(loader), routing_id, request_id, options,
                        request, std::move(client), traffic_annotation,
-                       loader_remote.Unbind(), it->second.first));
+                       std::move(loader_remote), it->second.first));
     return;
   }