Chromium Code Reviews| 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..9f86420594e8c2d894a7a2f58e30ae005ce60f86 |
| --- /dev/null |
| +++ b/components/network_hints/renderer/renderer_preconnect.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Deprecated (see juliatuttle)
2015/02/10 17:48:42
2015?
Pat Meenan
2015/02/10 18:44:49
Done.
|
| +// 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 <ctype.h> |
|
mmenke
2015/02/10 18:10:14
What is this needed for?
Pat Meenan
2015/02/10 18:44:49
Removed. Leftover from copying the DNS code to use
|
| + |
| +#include "base/bind.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() || !url.has_host() || !url.has_scheme()) |
|
mmenke
2015/02/10 18:10:14
GURL can't have relative URLs, I believe. So the
Pat Meenan
2015/02/10 18:44:49
Done.
|
| + 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, |
|
mmenke
2015/02/10 18:10:14
include base/location.h for FROM_HERE
Pat Meenan
2015/02/10 18:44:49
Done. The DNS prefetch code was doing the same thi
|
| + 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 (UrlRequestCountMap::iterator it = url_request_count_map_.begin(); |
| + it != url_request_count_map_.end(); ++it) { |
|
mmenke
2015/02/10 18:10:14
Use a C++x11 range loop? const auto&... (If I we
Pat Meenan
2015/02/10 18:44:49
Done.
|
| + RenderThread::Get()->Send( |
| + new NetworkHintsMsg_Preconnect(it->first, it->second)); |
| + } |
| + url_request_count_map_.clear(); |
| +} |
| + |
| +} // namespcae network_hints |
|
mmenke
2015/02/10 18:10:14
typo: namespace
Pat Meenan
2015/02/10 18:44:49
Done. Typo was copied from the DNS prefetch code s
|