OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/loader/url_loader_factory_impl.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/memory/ptr_util.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
12 #include "content/browser/loader/resource_message_filter.h" | |
13 #include "content/common/resource_messages.h" | |
14 #include "content/common/resource_request.h" | |
15 #include "content/common/url_loader.mojom.h" | |
16 | |
17 namespace content { | |
18 | |
19 namespace { | |
20 | |
21 // This class is an implementation of mojom::URLLoader which is a resource | |
22 // loader interface with Mojo. | |
23 class URLLoaderImpl final : public mojom::URLLoader { | |
mmenke
2016/05/26 21:46:09
I don't suppose there's some mojo signal if the ot
yhirano
2016/05/27 11:30:34
Can you tell me if process death is the only cause
mmenke
2016/05/27 15:39:26
CancelRequestsForProcess is only called on process
| |
24 public: | |
25 // Creates a URLLoader. This function returns nothing and registers the | |
26 // created instance to the ResourceDispatcherHostImpl instead. | |
27 static void Create(scoped_refptr<ResourceMessageFilter> filter, | |
28 mojom::URLLoaderRequest request) { | |
29 int child_id = filter->child_id(); | |
30 ResourceDispatcherHostImpl::Get()->AddUnstartedURLLoader( | |
31 child_id, | |
32 base::WrapUnique(new URLLoaderImpl(filter.get(), std::move(request)))); | |
33 } | |
34 | |
35 ~URLLoaderImpl() override {} | |
36 | |
37 void Start(int32_t request_id, | |
38 const ResourceRequest& request, | |
39 mojom::URLLoaderClientPtr client) override { | |
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
41 | |
42 ResourceMessageFilter* filter = resource_message_filter_.get(); | |
43 if (!filter) { | |
44 // TODO(yhirano): Cancel the request. | |
45 return; | |
46 } | |
47 | |
48 std::unique_ptr<mojom::URLLoader> that = | |
49 ResourceDispatcherHostImpl::Get()->TakeUnstartedURLLoader(this); | |
50 DCHECK(that); | |
51 | |
52 // TODO(yhirano): Provide the right routing ID. | |
53 const int routing_id = 0; | |
54 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
55 rdh->OnRequestResourceWithMojo(routing_id, request_id, request, | |
56 std::move(that), std::move(client), filter); | |
57 } | |
58 void FollowRedirect() override {} | |
59 void Cancel() override {} | |
60 | |
61 private: | |
62 URLLoaderImpl(ResourceMessageFilter* filter, | |
63 mojo::InterfaceRequest<mojom::URLLoader> request) | |
64 : resource_message_filter_(filter->GetWeakPtr()), | |
65 binding_(this, std::move(request)) {} | |
66 | |
67 base::WeakPtr<ResourceMessageFilter> resource_message_filter_; | |
68 mojo::Binding<mojom::URLLoader> binding_; | |
69 }; | |
70 | |
71 } // namespace | |
72 | |
73 URLLoaderFactoryImpl::URLLoaderFactoryImpl( | |
74 scoped_refptr<ResourceMessageFilter> resource_message_filter, | |
75 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) | |
76 : resource_message_filter_(resource_message_filter), | |
77 binding_(this, std::move(request)) {} | |
mmenke
2016/05/26 21:46:09
DCHECK_CURRENTLY_ON(BrowserThread::UI);?
yhirano
2016/05/27 11:30:34
Done.
| |
78 | |
79 URLLoaderFactoryImpl::~URLLoaderFactoryImpl() { | |
80 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
mmenke
2016/05/26 21:46:09
include browser_thread.h
yhirano
2016/05/27 11:30:34
Done.
| |
81 } | |
82 | |
83 void URLLoaderFactoryImpl::CreateURLLoader(mojom::URLLoaderRequest request) { | |
84 BrowserThread::PostTask( | |
85 BrowserThread::IO, FROM_HERE, | |
86 base::Bind(&URLLoaderImpl::Create, resource_message_filter_, | |
87 base::Passed(std::move(request)))); | |
mmenke
2016/05/26 21:46:09
include base/bind.h
yhirano
2016/05/27 11:30:34
Done.
| |
88 } | |
89 | |
90 } // namespace content | |
OLD | NEW |