Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: content/browser/loader/url_loader_factory_impl.cc

Issue 2824193002: Enable use_once_callback for //content/common/*.mojom (Closed)
Patch Set: push_messaging fix Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/loader/url_loader_factory_impl.h" 5 #include "content/browser/loader/url_loader_factory_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/loader/resource_dispatcher_host_impl.h" 8 #include "content/browser/loader/resource_dispatcher_host_impl.h"
9 #include "content/browser/loader/resource_requester_info.h" 9 #include "content/browser/loader/resource_requester_info.h"
10 #include "content/common/resource_request.h" 10 #include "content/common/resource_request.h"
11 #include "content/common/url_loader.mojom.h" 11 #include "content/common/url_loader.mojom.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 void DispatchSyncLoadResult( 18 void DispatchSyncLoadResult(URLLoaderFactoryImpl::SyncLoadCallback callback,
19 const URLLoaderFactoryImpl::SyncLoadCallback& callback, 19 const SyncLoadResult* result) {
20 const SyncLoadResult* result) {
21 // |result| can be null when a loading task is aborted unexpectedly. Reply 20 // |result| can be null when a loading task is aborted unexpectedly. Reply
22 // with a failure result on that case. 21 // with a failure result on that case.
23 // TODO(tzik): Test null-result case. 22 // TODO(tzik): Test null-result case.
24 if (!result) { 23 if (!result) {
25 SyncLoadResult failure; 24 SyncLoadResult failure;
26 failure.error_code = net::ERR_FAILED; 25 failure.error_code = net::ERR_FAILED;
27 callback.Run(failure); 26 std::move(callback).Run(failure);
28 return; 27 return;
29 } 28 }
30 29
31 callback.Run(*result); 30 std::move(callback).Run(*result);
32 } 31 }
33 32
34 } // namespace 33 } // namespace
35 34
36 URLLoaderFactoryImpl::URLLoaderFactoryImpl( 35 URLLoaderFactoryImpl::URLLoaderFactoryImpl(
37 scoped_refptr<ResourceRequesterInfo> requester_info, 36 scoped_refptr<ResourceRequesterInfo> requester_info,
38 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner) 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner)
39 : requester_info_(std::move(requester_info)), 38 : requester_info_(std::move(requester_info)),
40 io_thread_task_runner_(io_thread_runner) { 39 io_thread_task_runner_(io_thread_runner) {
41 DCHECK((requester_info_->IsRenderer() && requester_info_->filter()) || 40 DCHECK((requester_info_->IsRenderer() && requester_info_->filter()) ||
(...skipping 13 matching lines...) Expand all
55 const ResourceRequest& url_request, 54 const ResourceRequest& url_request,
56 mojom::URLLoaderClientPtr client) { 55 mojom::URLLoaderClientPtr client) {
57 DCHECK_EQ(options, mojom::kURLLoadOptionNone); 56 DCHECK_EQ(options, mojom::kURLLoadOptionNone);
58 CreateLoaderAndStart(requester_info_.get(), std::move(request), routing_id, 57 CreateLoaderAndStart(requester_info_.get(), std::move(request), routing_id,
59 request_id, url_request, std::move(client)); 58 request_id, url_request, std::move(client));
60 } 59 }
61 60
62 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id, 61 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id,
63 int32_t request_id, 62 int32_t request_id,
64 const ResourceRequest& url_request, 63 const ResourceRequest& url_request,
65 const SyncLoadCallback& callback) { 64 SyncLoadCallback callback) {
66 SyncLoad(requester_info_.get(), routing_id, request_id, url_request, 65 SyncLoad(requester_info_.get(), routing_id, request_id, url_request,
67 callback); 66 std::move(callback));
68 } 67 }
69 68
70 // static 69 // static
71 void URLLoaderFactoryImpl::CreateLoaderAndStart( 70 void URLLoaderFactoryImpl::CreateLoaderAndStart(
72 ResourceRequesterInfo* requester_info, 71 ResourceRequesterInfo* requester_info,
73 mojom::URLLoaderAssociatedRequest request, 72 mojom::URLLoaderAssociatedRequest request,
74 int32_t routing_id, 73 int32_t routing_id,
75 int32_t request_id, 74 int32_t request_id,
76 const ResourceRequest& url_request, 75 const ResourceRequest& url_request,
77 mojom::URLLoaderClientPtr client) { 76 mojom::URLLoaderClientPtr client) {
78 DCHECK(ResourceDispatcherHostImpl::Get() 77 DCHECK(ResourceDispatcherHostImpl::Get()
79 ->io_thread_task_runner() 78 ->io_thread_task_runner()
80 ->BelongsToCurrentThread()); 79 ->BelongsToCurrentThread());
81 80
82 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 81 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
83 rdh->OnRequestResourceWithMojo(requester_info, routing_id, request_id, 82 rdh->OnRequestResourceWithMojo(requester_info, routing_id, request_id,
84 url_request, std::move(request), 83 url_request, std::move(request),
85 std::move(client)); 84 std::move(client));
86 } 85 }
87 86
88 // static 87 // static
89 void URLLoaderFactoryImpl::SyncLoad(ResourceRequesterInfo* requester_info, 88 void URLLoaderFactoryImpl::SyncLoad(ResourceRequesterInfo* requester_info,
90 int32_t routing_id, 89 int32_t routing_id,
91 int32_t request_id, 90 int32_t request_id,
92 const ResourceRequest& url_request, 91 const ResourceRequest& url_request,
93 const SyncLoadCallback& callback) { 92 SyncLoadCallback callback) {
94 DCHECK(ResourceDispatcherHostImpl::Get() 93 DCHECK(ResourceDispatcherHostImpl::Get()
95 ->io_thread_task_runner() 94 ->io_thread_task_runner()
96 ->BelongsToCurrentThread()); 95 ->BelongsToCurrentThread());
97 96
98 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 97 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
99 rdh->OnSyncLoadWithMojo(requester_info, routing_id, request_id, url_request, 98 rdh->OnSyncLoadWithMojo(
100 base::Bind(&DispatchSyncLoadResult, callback)); 99 requester_info, routing_id, request_id, url_request,
100 base::Bind(&DispatchSyncLoadResult, base::Passed(&callback)));
mmenke 2017/04/21 16:25:57 You could use BindOnce here, too, and make OnSyncL
tzik 2017/04/24 09:17:11 Let me do it in a separate CL. # This should hopef
101 } 101 }
102 102
103 void URLLoaderFactoryImpl::Create( 103 void URLLoaderFactoryImpl::Create(
104 scoped_refptr<ResourceRequesterInfo> requester_info, 104 scoped_refptr<ResourceRequesterInfo> requester_info,
105 mojo::InterfaceRequest<mojom::URLLoaderFactory> request, 105 mojo::InterfaceRequest<mojom::URLLoaderFactory> request,
106 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner) { 106 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread_runner) {
107 mojo::MakeStrongBinding(base::WrapUnique(new URLLoaderFactoryImpl( 107 mojo::MakeStrongBinding(base::WrapUnique(new URLLoaderFactoryImpl(
108 std::move(requester_info), io_thread_runner)), 108 std::move(requester_info), io_thread_runner)),
109 std::move(request)); 109 std::move(request));
110 } 110 }
111 111
112 } // namespace content 112 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/url_loader_factory_impl.h ('k') | content/browser/payments/payment_app_content_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698