OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A RendererPreconnect instance is maintained for each RenderThread. | 5 // A RendererPreconnect instance is maintained for each RenderThread. |
6 // URL strings are typically added to the embedded queue during rendering. | 6 // URL strings are typically added to the embedded queue during rendering. |
7 // The first addition to the queue (transitioning from empty to having | 7 // The first addition to the queue (transitioning from empty to having |
8 // some names) causes a processing task to be added to the Renderer Thread. | 8 // some names) causes a processing task to be added to the Renderer Thread. |
9 // The processing task gathers all buffered URLs, and send them via IPC | 9 // The processing task gathers all buffered URLs, and send them via IPC |
10 // to the browser. | 10 // to the browser. |
11 // This class counts repeated requests for the same URL and requests that | 11 // This class counts repeated requests for the same URL and requests that |
12 // number of connections be preconnected. If multiple requests are sent | 12 // number of connections be preconnected. If multiple requests are sent |
13 // separately the net stack will just keep re-using the first pending | 13 // separately the net stack will just keep re-using the first pending |
14 // connection so we allow for the time between the parsing of the tags and | 14 // connection so we allow for the time between the parsing of the tags and |
15 // when the task is scheduled to accumulate multiple requests. | 15 // when the task is scheduled to accumulate multiple requests. |
16 | 16 |
17 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ | 17 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ |
18 #define COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ | 18 #define COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ |
19 | 19 |
20 #include <map> | |
21 | |
22 #include "base/basictypes.h" | |
23 #include "base/memory/weak_ptr.h" | |
24 #include "url/gurl.h" | 20 #include "url/gurl.h" |
25 | 21 |
26 namespace network_hints { | 22 namespace network_hints { |
27 | 23 |
28 // An internal interface to the network_hints component for efficiently sending | 24 // An internal interface to the network_hints component for efficiently sending |
29 // DNS prefetch requests to the net stack. | 25 // DNS prefetch requests to the net stack. |
30 class RendererPreconnect { | 26 class RendererPreconnect { |
31 public: | 27 public: |
32 RendererPreconnect(); | 28 RendererPreconnect(); |
33 ~RendererPreconnect(); | 29 ~RendererPreconnect(); |
34 | 30 |
35 // Push a name into the queue to be preconnected. | 31 // Submit a preconnect request for a single connection. |
36 void Preconnect(const GURL &url); | 32 void Preconnect(const GURL &url); |
37 | 33 |
38 // SubmitPreconnect processes the buffered URLs, and submits them for | |
39 // preconnecting. Multiple requests for the same URL will increase the number | |
40 // of connections requested. | |
41 void SubmitPreconnect(); | |
42 | |
43 private: | 34 private: |
44 // url_request_count_map_ contains (for each URL) a count for the number of | |
45 // times it was requested. | |
46 typedef std::map<GURL, int> UrlRequestCountMap; | |
47 UrlRequestCountMap url_request_count_map_; | |
48 | |
49 base::WeakPtrFactory<RendererPreconnect> weak_factory_; | |
50 | 35 |
51 DISALLOW_COPY_AND_ASSIGN(RendererPreconnect); | 36 DISALLOW_COPY_AND_ASSIGN(RendererPreconnect); |
52 }; // class RendererPreconnect | 37 }; // class RendererPreconnect |
53 | 38 |
54 } // namespace network_hints | 39 } // namespace network_hints |
55 | 40 |
56 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ | 41 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_PRECONNECT_H_ |
OLD | NEW |