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

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

Issue 2390983003: Implement Mojo SyncLoad (Closed)
Patch Set: +tests Created 4 years, 2 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
« no previous file with comments | « content/browser/loader/url_loader_factory_impl.h ('k') | content/child/resource_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 #include "content/browser/loader/resource_message_filter.h" 8 #include "content/browser/loader/resource_message_filter.h"
9 #include "content/common/resource_request.h" 9 #include "content/common/resource_request.h"
10 #include "content/common/url_loader.mojom.h" 10 #include "content/common/url_loader.mojom.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.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 {
17
18 void DispatchSyncLoadResult(
19 const URLLoaderFactoryImpl::SyncLoadCallback& callback,
20 const SyncLoadResult* result) {
21 // |result| can be null when a loading task is aborted unexpectedly. Reply
22 // with a failure result on that case.
23 // TODO(tzik): Test null-result case.
24 if (!result) {
25 SyncLoadResult failure;
26 failure.error_code = net::ERR_FAILED;
27 callback.Run(failure);
28 return;
29 }
30
31 callback.Run(*result);
32 }
33
34 } // namespace
35
16 URLLoaderFactoryImpl::URLLoaderFactoryImpl( 36 URLLoaderFactoryImpl::URLLoaderFactoryImpl(
17 scoped_refptr<ResourceMessageFilter> resource_message_filter) 37 scoped_refptr<ResourceMessageFilter> resource_message_filter)
18 : resource_message_filter_(std::move(resource_message_filter)) { 38 : resource_message_filter_(std::move(resource_message_filter)) {
19 DCHECK(resource_message_filter_); 39 DCHECK(resource_message_filter_);
20 DCHECK_CURRENTLY_ON(BrowserThread::IO); 40 DCHECK_CURRENTLY_ON(BrowserThread::IO);
21 } 41 }
22 42
23 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { 43 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() {
24 DCHECK_CURRENTLY_ON(BrowserThread::IO); 44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
25 } 45 }
26 46
27 void URLLoaderFactoryImpl::CreateLoaderAndStart( 47 void URLLoaderFactoryImpl::CreateLoaderAndStart(
28 mojom::URLLoaderRequest request, 48 mojom::URLLoaderRequest request,
29 int32_t routing_id, 49 int32_t routing_id,
30 int32_t request_id, 50 int32_t request_id,
31 const ResourceRequest& url_request, 51 const ResourceRequest& url_request,
32 mojom::URLLoaderClientPtr client) { 52 mojom::URLLoaderClientPtr client) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO); 53 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34 54
35 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); 55 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
36 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, 56 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
37 std::move(request), std::move(client), 57 std::move(request), std::move(client),
38 resource_message_filter_.get()); 58 resource_message_filter_.get());
39 } 59 }
40 60
61 void URLLoaderFactoryImpl::SyncLoad(int32_t routing_id,
62 int32_t request_id,
63 const ResourceRequest& url_request,
64 const SyncLoadCallback& callback) {
65 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66
67 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
68 rdh->OnSyncLoadWithMojo(routing_id, request_id, url_request,
69 resource_message_filter_.get(),
70 base::Bind(&DispatchSyncLoadResult, callback));
71 }
72
41 void URLLoaderFactoryImpl::Create( 73 void URLLoaderFactoryImpl::Create(
42 scoped_refptr<ResourceMessageFilter> filter, 74 scoped_refptr<ResourceMessageFilter> filter,
43 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { 75 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
44 mojo::MakeStrongBinding( 76 mojo::MakeStrongBinding(
45 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))), 77 base::WrapUnique(new URLLoaderFactoryImpl(std::move(filter))),
46 std::move(request)); 78 std::move(request));
47 } 79 }
48 80
49 } // namespace content 81 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/url_loader_factory_impl.h ('k') | content/child/resource_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698