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

Unified Diff: content/browser/loader/url_loader_factory_impl.cc

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/url_loader_factory_impl.cc
diff --git a/content/browser/loader/url_loader_factory_impl.cc b/content/browser/loader/url_loader_factory_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1f44b0c89ebab7471723c9ea7c8535c30229d4a9
--- /dev/null
+++ b/content/browser/loader/url_loader_factory_impl.cc
@@ -0,0 +1,90 @@
+// 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_impl.h"
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#include "base/memory/weak_ptr.h"
+#include "content/browser/loader/resource_dispatcher_host_impl.h"
+#include "content/browser/loader/resource_message_filter.h"
+#include "content/common/resource_messages.h"
+#include "content/common/resource_request.h"
+#include "content/common/url_loader.mojom.h"
+
+namespace content {
+
+namespace {
+
+// This class is an implementation of mojom::URLLoader which is a resource
+// loader interface with Mojo.
+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
+ public:
+ // Creates a URLLoader. This function returns nothing and registers the
+ // created instance to the ResourceDispatcherHostImpl instead.
+ static void Create(scoped_refptr<ResourceMessageFilter> filter,
+ mojom::URLLoaderRequest request) {
+ int child_id = filter->child_id();
+ ResourceDispatcherHostImpl::Get()->AddUnstartedURLLoader(
+ child_id,
+ base::WrapUnique(new URLLoaderImpl(filter.get(), std::move(request))));
+ }
+
+ ~URLLoaderImpl() override {}
+
+ void Start(int32_t request_id,
+ const ResourceRequest& request,
+ mojom::URLLoaderClientPtr client) override {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ ResourceMessageFilter* filter = resource_message_filter_.get();
+ if (!filter) {
+ // TODO(yhirano): Cancel the request.
+ return;
+ }
+
+ std::unique_ptr<mojom::URLLoader> that =
+ ResourceDispatcherHostImpl::Get()->TakeUnstartedURLLoader(this);
+ DCHECK(that);
+
+ // TODO(yhirano): Provide the right routing ID.
+ const int routing_id = 0;
+ ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
+ rdh->OnRequestResourceWithMojo(routing_id, request_id, request,
+ std::move(that), std::move(client), filter);
+ }
+ void FollowRedirect() override {}
+ void Cancel() override {}
+
+ private:
+ URLLoaderImpl(ResourceMessageFilter* filter,
+ mojo::InterfaceRequest<mojom::URLLoader> request)
+ : resource_message_filter_(filter->GetWeakPtr()),
+ binding_(this, std::move(request)) {}
+
+ base::WeakPtr<ResourceMessageFilter> resource_message_filter_;
+ mojo::Binding<mojom::URLLoader> binding_;
+};
+
+} // namespace
+
+URLLoaderFactoryImpl::URLLoaderFactoryImpl(
+ scoped_refptr<ResourceMessageFilter> resource_message_filter,
+ mojo::InterfaceRequest<mojom::URLLoaderFactory> request)
+ : resource_message_filter_(resource_message_filter),
+ 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.
+
+URLLoaderFactoryImpl::~URLLoaderFactoryImpl() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
mmenke 2016/05/26 21:46:09 include browser_thread.h
yhirano 2016/05/27 11:30:34 Done.
+}
+
+void URLLoaderFactoryImpl::CreateURLLoader(mojom::URLLoaderRequest request) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&URLLoaderImpl::Create, resource_message_filter_,
+ base::Passed(std::move(request))));
mmenke 2016/05/26 21:46:09 include base/bind.h
yhirano 2016/05/27 11:30:34 Done.
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698