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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
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 "base/bind.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h"
13 #include "components/network_hints/common/network_hints_common.h"
14 #include "components/network_hints/common/network_hints_messages.h"
15 #include "content/public/renderer/render_thread.h"
16
17 using content::RenderThread;
18
19 namespace network_hints {
20
21 RendererPreconnect::RendererPreconnect()
22 : weak_factory_(this) {
23 }
24
25 RendererPreconnect::~RendererPreconnect() {
26 }
27
28 // Push URLs into the map quickly!
29 void RendererPreconnect::Preconnect(const GURL &url) {
30 if (!url.is_valid())
31 return;
32
33 // If this is the first entry in the map then a task needs to be scheduled.
34 bool needs_task = url_request_count_map_.empty();
35
36 // ints will initialize to 0 automatically so incrementing will initialize
37 // new URLs to 1 or increment existing URLs (exactly the desired behavior).
38 url_request_count_map_[url]++;
39
40 if (needs_task) {
41 weak_factory_.InvalidateWeakPtrs();
42 RenderThread::Get()->GetTaskRunner()->PostDelayedTask(
43 FROM_HERE, base::Bind(&RendererPreconnect::SubmitPreconnect,
44 weak_factory_.GetWeakPtr()),
45 base::TimeDelta::FromMilliseconds(10));
46 }
47 }
48
49 // Extract data from the Map, and then send it off the the Browser process
50 // to be preconnected.
51 void RendererPreconnect::SubmitPreconnect() {
52 DCHECK(!url_request_count_map_.empty());
53 for (const auto& entry : url_request_count_map_) {
54 RenderThread::Get()->Send(
55 new NetworkHintsMsg_Preconnect(entry.first, entry.second));
56 }
57 url_request_count_map_.clear();
58 }
59
60 } // namespace network_hints
OLDNEW
« 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