| Index: content/browser/loader/url_loader_factory_holder.cc
|
| diff --git a/content/browser/loader/url_loader_factory_holder.cc b/content/browser/loader/url_loader_factory_holder.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..942209b5985c138d4dee2d17ea9957fde8485ff3
|
| --- /dev/null
|
| +++ b/content/browser/loader/url_loader_factory_holder.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/loader/url_loader_factory_holder.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "content/browser/loader/resource_dispatcher_host_impl.h"
|
| +#include "content/browser/loader/resource_message_filter.h"
|
| +#include "content/common/resource_request.h"
|
| +#include "content/common/url_loader.mojom.h"
|
| +#include "content/common/url_loader_factory.mojom.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +
|
| +namespace content {
|
| +
|
| +// This class is an implementation of mojom::URLLoaderFactory that creates
|
| +// a mojom::URLLoader.
|
| +class URLLoaderFactoryHolder::URLLoaderFactoryImpl final
|
| + : public mojom::URLLoaderFactory {
|
| + public:
|
| + explicit URLLoaderFactoryImpl(
|
| + scoped_refptr<ResourceMessageFilter> resource_message_filter)
|
| + : resource_message_filter_(std::move(resource_message_filter)) {
|
| + DCHECK(resource_message_filter_);
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + }
|
| + ~URLLoaderFactoryImpl() override { DCHECK_CURRENTLY_ON(BrowserThread::IO); }
|
| +
|
| + void CreateLoaderAndStart(mojom::URLLoaderRequest request,
|
| + int32_t request_id,
|
| + const ResourceRequest& url_request,
|
| + mojom::URLLoaderClientPtr client) override {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| + // TODO(yhirano): Provide the right routing ID.
|
| + const int routing_id = 0;
|
| + ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
|
| + rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
|
| + std::move(request), std::move(client),
|
| + resource_message_filter_.get());
|
| + }
|
| +
|
| + void Bind(mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + binding_.reset(
|
| + new mojo::Binding<URLLoaderFactory>(this, std::move(request)));
|
| + }
|
| +
|
| + private:
|
| + scoped_refptr<ResourceMessageFilter> resource_message_filter_;
|
| + std::unique_ptr<mojo::Binding<mojom::URLLoaderFactory>> binding_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImpl);
|
| +};
|
| +
|
| +URLLoaderFactoryHolder::URLLoaderFactoryHolder(
|
| + scoped_refptr<ResourceMessageFilter> resource_message_filter,
|
| + mojo::InterfaceRequest<mojom::URLLoaderFactory> request)
|
| + : factory_(new URLLoaderFactoryImpl(resource_message_filter)) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + // This |Unretained| is safe because ~URLLoaderFactoryHolder is the only
|
| + // function that posts a |factory_| deletion task to the IO thread and
|
| + // ~URLLoaderFactoryHolder is called on this thread.
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&URLLoaderFactoryImpl::Bind, base::Unretained(factory_.get()),
|
| + base::Passed(std::move(request))));
|
| +}
|
| +
|
| +URLLoaderFactoryHolder::~URLLoaderFactoryHolder() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, factory_.release());
|
| +}
|
| +
|
| +} // namespace content
|
|
|