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

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

Issue 2043753002: Declarative resource hints go through mojo IPC to //content Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/resource_hints_controller.cc
diff --git a/content/browser/loader/resource_hints_controller.cc b/content/browser/loader/resource_hints_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..df5fc7b43f1180abd7c628adb0c8997283bce87a
--- /dev/null
+++ b/content/browser/loader/resource_hints_controller.cc
@@ -0,0 +1,70 @@
+// 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/resource_hints_controller.h"
+
+#include "base/memory/ptr_util.h"
+#include "content/browser/loader/resource_dispatcher_host_impl.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/resource_context.h"
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
+#include "content/public/browser/resource_hints.h"
+#include "net/base/address_list.h"
+#include "net/dns/host_resolver.h"
+#include "net/dns/single_request_host_resolver.h"
+#include "net/url_request/url_request_context.h"
+
+namespace content {
+
+// static
+void ResourceHintsController::RegisterConnection(
+ RenderProcessHost* render_process_host,
+ mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request) {
yzshen1 2016/06/08 17:40:53 nit: in case you don't know, you can use a shorter
Charlie Harrison 2016/06/10 14:20:00 Thank you :) done.
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&ResourceHintsController::RegisterConnectionOnIOThread,
+ render_process_host->GetBrowserContext()->GetResourceContext(),
yzshen1 2016/06/08 17:40:53 Is it guaranteed that resource context outlives th
Charlie Harrison 2016/06/10 14:20:00 I'm unsure. What are the semantics of the channel'
yzshen1 2016/06/10 15:45:43 If the renderer doesn't disconnect earlier, the st
+ base::Passed(&request)));
+}
+
+// static
+void ResourceHintsController::RegisterConnectionOnIOThread(
+ ResourceContext* resource_context,
+ mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request) {
+ // Will be deleted when the connection goes away.
+ new ResourceHintsController(std::move(request), resource_context);
+}
+
+ResourceHintsController::ResourceHintsController(
+ mojo::InterfaceRequest<blink::mojom::ResourceHintsDispatcherHost> request,
+ ResourceContext* resource_context)
+ : resource_context_(resource_context), binding_(this, std::move(request)) {
+ binding_.set_connection_error_handler(
+ base::Bind(&ResourceHintsController::HostHadConnectionError,
+ base::Unretained(this)));
+}
+
+ResourceHintsController::~ResourceHintsController() {}
+
+void ResourceHintsController::HostHadConnectionError() {
+ delete this;
yzshen1 2016/06/08 17:40:53 Please take a look at strong_binding.h. It does t
kinuko 2016/06/09 07:09:19 Yeah we shouldn't need this.
Charlie Harrison 2016/06/10 14:20:00 Done. Thanks for the pointer.
+}
+
+void ResourceHintsController::DispatchPreresolve(const GURL& url) {
+ PreresolveUrl(resource_context_, url, net::CompletionCallback());
+}
+
+void ResourceHintsController::DispatchPreconnect(const GURL& url,
+ bool credentials_flag,
+ uint8_t num_connections) {
+ // TODO(csharrison): Remove HttpRequestInfo::RequestMotivation and add a
+ // better enum at the //content layer.
+ PreconnectUrl(resource_context_, url, GURL(), num_connections,
+ credentials_flag, net::HttpRequestInfo::EARLY_LOAD_MOTIVATED);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698