OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // See header file for description of RendererPreconnect class | |
6 | |
7 #include "components/network_hints/renderer/renderer_preconnect.h" | |
8 | |
9 #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
| |
10 | |
11 #include "base/bind.h" | |
12 #include "base/logging.h" | |
13 #include "base/message_loop/message_loop.h" | |
14 #include "components/network_hints/common/network_hints_common.h" | |
15 #include "components/network_hints/common/network_hints_messages.h" | |
16 #include "content/public/renderer/render_thread.h" | |
17 | |
18 using content::RenderThread; | |
19 | |
20 namespace network_hints { | |
21 | |
22 RendererPreconnect::RendererPreconnect() | |
23 : weak_factory_(this) { | |
24 } | |
25 | |
26 RendererPreconnect::~RendererPreconnect() { | |
27 } | |
28 | |
29 // Push URLs into the map quickly! | |
30 void RendererPreconnect::Preconnect(const GURL &url) { | |
31 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.
| |
32 return; | |
33 | |
34 // If this is the first entry in the map then a task needs to be scheduled. | |
35 bool needs_task = url_request_count_map_.empty(); | |
36 | |
37 // ints will initialize to 0 automatically so incrementing will initialize | |
38 // new URLs to 1 or increment existing URLs (exactly the desired behavior). | |
39 url_request_count_map_[url]++; | |
40 | |
41 if (needs_task) { | |
42 weak_factory_.InvalidateWeakPtrs(); | |
43 RenderThread::Get()->GetTaskRunner()->PostDelayedTask( | |
44 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
| |
45 weak_factory_.GetWeakPtr()), | |
46 base::TimeDelta::FromMilliseconds(10)); | |
47 } | |
48 } | |
49 | |
50 // Extract data from the Map, and then send it off the the Browser process | |
51 // to be preconnected. | |
52 void RendererPreconnect::SubmitPreconnect() { | |
53 DCHECK(!url_request_count_map_.empty()); | |
54 for (UrlRequestCountMap::iterator it = url_request_count_map_.begin(); | |
55 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.
| |
56 RenderThread::Get()->Send( | |
57 new NetworkHintsMsg_Preconnect(it->first, it->second)); | |
58 } | |
59 url_request_count_map_.clear(); | |
60 } | |
61 | |
62 } // 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
| |
OLD | NEW |