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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 5 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
(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 // This class is an implementation of mojom::URLLoaderFactory that creates
22 // a mojom::URLLoader.
23 class URLLoaderFactoryHolder::URLLoaderFactoryImpl final
24 : public mojom::URLLoaderFactory {
25 public:
26 explicit URLLoaderFactoryImpl(
27 scoped_refptr<ResourceMessageFilter> resource_message_filter)
28 : resource_message_filter_(std::move(resource_message_filter)) {
29 DCHECK(resource_message_filter_);
30 DCHECK_CURRENTLY_ON(BrowserThread::UI);
31 }
32 ~URLLoaderFactoryImpl() override { DCHECK_CURRENTLY_ON(BrowserThread::IO); }
33
34 void CreateLoaderAndStart(mojom::URLLoaderRequest request,
35 int32_t request_id,
36 const ResourceRequest& url_request,
37 mojom::URLLoaderClientPtr client) override {
38 DCHECK_CURRENTLY_ON(BrowserThread::IO);
39
40 // TODO(yhirano): Provide the right routing ID.
41 const int routing_id = 0;
42 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
43 rdh->OnRequestResourceWithMojo(routing_id, request_id, url_request,
44 std::move(request), std::move(client),
45 resource_message_filter_.get());
46 }
47
48 void Bind(mojo::InterfaceRequest<mojom::URLLoaderFactory> request) {
49 DCHECK_CURRENTLY_ON(BrowserThread::IO);
50 binding_.reset(
51 new mojo::Binding<URLLoaderFactory>(this, std::move(request)));
52 }
53
54 private:
55 scoped_refptr<ResourceMessageFilter> resource_message_filter_;
56 std::unique_ptr<mojo::Binding<mojom::URLLoaderFactory>> binding_;
57
58 DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryImpl);
59 };
60
61 URLLoaderFactoryHolder::URLLoaderFactoryHolder(
62 scoped_refptr<ResourceMessageFilter> resource_message_filter,
63 mojo::InterfaceRequest<mojom::URLLoaderFactory> request)
64 : factory_(new URLLoaderFactoryImpl(resource_message_filter)) {
65 DCHECK_CURRENTLY_ON(BrowserThread::UI);
66 // This |Unretained| is safe because ~URLLoaderFactoryHolder is the only
67 // function that posts a |factory_| deletion task to the IO thread and
68 // ~URLLoaderFactoryHolder is called on this thread.
69 BrowserThread::PostTask(
70 BrowserThread::IO, FROM_HERE,
71 base::Bind(&URLLoaderFactoryImpl::Bind, base::Unretained(factory_.get()),
72 base::Passed(std::move(request))));
73 }
74
75 URLLoaderFactoryHolder::~URLLoaderFactoryHolder() {
76 DCHECK_CURRENTLY_ON(BrowserThread::UI);
77 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, factory_.release());
78 }
79
80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698