Chromium Code Reviews| 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_holder.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/memory/ptr_util.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_request.h" | |
| 14 #include "content/common/url_loader.mojom.h" | |
| 15 #include "content/common/url_loader_factory.mojom.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "mojo/public/cpp/bindings/binding.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // This class is an implementation of mojom::URLLoader which is a resource | |
| 24 // loader interface with Mojo. | |
| 25 class URLLoaderImpl final : public mojom::URLLoader { | |
| 26 public: | |
| 27 explicit URLLoaderImpl(mojo::InterfaceRequest<mojom::URLLoader> request) | |
| 28 : binding_(this, std::move(request)) {} | |
| 29 ~URLLoaderImpl() override {} | |
| 30 | |
| 31 void FollowRedirect() override {} | |
| 32 void Cancel() override {} | |
|
mmenke
2016/06/13 20:56:58
NOTREACHED() for both of these, and a TODO about h
yhirano
2016/07/12 10:49:11
Ah, it's a good idea. Thank you.
| |
| 33 | |
| 34 private: | |
| 35 mojo::Binding<mojom::URLLoader> binding_; | |
| 36 | |
| 37 DISALLOW_COPY_AND_ASSIGN(URLLoaderImpl); | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 // This class is an implementation of mojom::URLLoaderFactory that creates | |
| 43 // a mojom::URLLoader. | |
| 44 class URLLoaderFactoryHolder::URLLoaderFactoryImpl final | |
| 45 : public mojom::URLLoaderFactory { | |
| 46 public: | |
| 47 explicit URLLoaderFactoryImpl( | |
| 48 scoped_refptr<ResourceMessageFilter> resource_message_filter) | |
| 49 : resource_message_filter_(std::move(resource_message_filter)) { | |
| 50 DCHECK(resource_message_filter_); | |
| 51 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 52 } | |
| 53 ~URLLoaderFactoryImpl() override { DCHECK_CURRENTLY_ON(BrowserThread::IO); } | |
| 54 | |
| 55 void CreateLoaderAndStart(mojom::URLLoaderRequest request, | |
| 56 int32_t request_id, | |
| 57 const ResourceRequest& url_request, | |
| 58 mojom::URLLoaderClientPtr client) override { | |
| 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 60 | |
| 61 std::unique_ptr<mojom::URLLoader> loader( | |
| 62 new URLLoaderImpl(std::move(request))); | |
| 63 | |
| 64 // TODO(yhirano): Provide the right routing ID. | |
| 65 const int routing_id = 0; | |
| 66 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | |
| 67 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request, | |
| 68 std::move(loader), std::move(client), | |
| 69 resource_message_filter_.get()); | |
| 70 } | |
| 71 | |
| 72 void Bind(mojo::InterfaceRequest<mojom::URLLoaderFactory> request) { | |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 74 binding_.reset( | |
| 75 new mojo::Binding<URLLoaderFactory>(this, std::move(request))); | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 scoped_refptr<ResourceMessageFilter> resource_message_filter_; | |
| 80 std::unique_ptr<mojo::Binding<mojom::URLLoaderFactory>> binding_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImpl); | |
| 83 }; | |
| 84 | |
| 85 URLLoaderFactoryHolder::URLLoaderFactoryHolder( | |
| 86 scoped_refptr<ResourceMessageFilter> resource_message_filter, | |
| 87 mojo::InterfaceRequest<mojom::URLLoaderFactory> request) | |
| 88 : factory_(new URLLoaderFactoryImpl(resource_message_filter)) { | |
|
mmenke
2016/06/13 20:56:58
Why is this cross-thread dongle necessary? Can we
kinuko
2016/06/14 08:45:29
While this sounds like a better direction I feel t
yhirano
2016/07/12 10:49:11
I'm planning to create a URLLoaderFactory for a Re
| |
| 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 90 // This |Unretained| is safe because ~URLLoaderFactoryHolder is the only | |
| 91 // function that posts a |factory_| deletion task to the IO thread and | |
| 92 // ~URLLoaderFactoryHolder is called on this thread. | |
| 93 BrowserThread::PostTask( | |
| 94 BrowserThread::IO, FROM_HERE, | |
| 95 base::Bind(&URLLoaderFactoryImpl::Bind, base::Unretained(factory_.get()), | |
| 96 base::Passed(std::move(request)))); | |
| 97 } | |
| 98 | |
| 99 URLLoaderFactoryHolder::~URLLoaderFactoryHolder() { | |
| 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 101 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, factory_.release()); | |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |