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

Unified Diff: components/network_hints/renderer/renderer_preconnect.cc

Issue 899883004: Added chrome-side support for link rel=preconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed formatting nit Created 5 years, 10 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
« no previous file with comments | « components/network_hints/renderer/renderer_preconnect.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/network_hints/renderer/renderer_preconnect.cc
diff --git a/components/network_hints/renderer/renderer_preconnect.cc b/components/network_hints/renderer/renderer_preconnect.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4588b45a74a0faa0f3b70fca592a16e94e4ead2d
--- /dev/null
+++ b/components/network_hints/renderer/renderer_preconnect.cc
@@ -0,0 +1,60 @@
+// Copyright 2015 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.
+
+// See header file for description of RendererPreconnect class
+
+#include "components/network_hints/renderer/renderer_preconnect.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "components/network_hints/common/network_hints_common.h"
+#include "components/network_hints/common/network_hints_messages.h"
+#include "content/public/renderer/render_thread.h"
+
+using content::RenderThread;
+
+namespace network_hints {
+
+RendererPreconnect::RendererPreconnect()
+ : weak_factory_(this) {
+}
+
+RendererPreconnect::~RendererPreconnect() {
+}
+
+// Push URLs into the map quickly!
+void RendererPreconnect::Preconnect(const GURL &url) {
+ if (!url.is_valid())
+ return;
+
+ // If this is the first entry in the map then a task needs to be scheduled.
+ bool needs_task = url_request_count_map_.empty();
+
+ // ints will initialize to 0 automatically so incrementing will initialize
+ // new URLs to 1 or increment existing URLs (exactly the desired behavior).
+ url_request_count_map_[url]++;
+
+ if (needs_task) {
+ weak_factory_.InvalidateWeakPtrs();
+ RenderThread::Get()->GetTaskRunner()->PostDelayedTask(
+ FROM_HERE, base::Bind(&RendererPreconnect::SubmitPreconnect,
+ weak_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(10));
+ }
+}
+
+// Extract data from the Map, and then send it off the the Browser process
+// to be preconnected.
+void RendererPreconnect::SubmitPreconnect() {
+ DCHECK(!url_request_count_map_.empty());
+ for (const auto& entry : url_request_count_map_) {
+ RenderThread::Get()->Send(
+ new NetworkHintsMsg_Preconnect(entry.first, entry.second));
+ }
+ url_request_count_map_.clear();
+}
+
+} // namespace network_hints
« no previous file with comments | « components/network_hints/renderer/renderer_preconnect.h ('k') | ipc/ipc_message_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698