Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_) { | |
|
mmenke
2015/02/10 18:49:59
nit: for (const auto& entry : url_request_count_m
Pat Meenan
2015/02/10 19:05:37
Done.
| |
| 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 | |
| OLD | NEW |