OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 RendererDnsPrefetch instance is maintained for each RenderThread. | 5 // A RendererDnsPrefetch 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 names, and send them via IPC | 9 // The processing task gathers all buffered names, and send them via IPC |
10 // to the browser, so that DNS lookups can be performed before the user attempts | 10 // to the browser, so that DNS lookups can be performed before the user attempts |
(...skipping 10 matching lines...) Expand all Loading... |
21 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ | 21 #ifndef COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ |
22 #define COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ | 22 #define COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ |
23 | 23 |
24 #include <stddef.h> | 24 #include <stddef.h> |
25 | 25 |
26 #include <map> | 26 #include <map> |
27 #include <string> | 27 #include <string> |
28 | 28 |
29 #include "base/macros.h" | 29 #include "base/macros.h" |
30 #include "base/memory/weak_ptr.h" | 30 #include "base/memory/weak_ptr.h" |
31 #include "components/network_hints/public/interfaces/network_hints.mojom.h" | |
32 #include "components/network_hints/renderer/dns_prefetch_queue.h" | 31 #include "components/network_hints/renderer/dns_prefetch_queue.h" |
33 | 32 |
34 namespace network_hints { | 33 namespace network_hints { |
35 | 34 |
36 class NetworkHints; | |
37 | |
38 // An internal interface to the network_hints component for efficiently sending | 35 // An internal interface to the network_hints component for efficiently sending |
39 // DNS prefetch requests to the net stack. | 36 // DNS prefetch requests to the net stack. |
40 class RendererDnsPrefetch { | 37 class RendererDnsPrefetch { |
41 public: | 38 public: |
42 RendererDnsPrefetch(); | 39 RendererDnsPrefetch(); |
43 ~RendererDnsPrefetch(); | 40 ~RendererDnsPrefetch(); |
44 | 41 |
45 // Push a name into the queue to be resolved. | 42 // Push a name into the queue to be resolved. |
46 void Resolve(const char* name, size_t length); | 43 void Resolve(const char* name, size_t length); |
47 | 44 |
(...skipping 25 matching lines...) Expand all Loading... |
73 // DnsPrefetchNames does not check the buffer, and just sends names | 70 // DnsPrefetchNames does not check the buffer, and just sends names |
74 // that are already collected in the domain_map_ for DNS lookup. | 71 // that are already collected in the domain_map_ for DNS lookup. |
75 // If max_count is zero, then all available names are sent; and | 72 // If max_count is zero, then all available names are sent; and |
76 // if positive, then at most max_count names will be sent. | 73 // if positive, then at most max_count names will be sent. |
77 void DnsPrefetchNames(size_t max_count = 0); | 74 void DnsPrefetchNames(size_t max_count = 0); |
78 | 75 |
79 // Reset() restores initial state provided after construction. | 76 // Reset() restores initial state provided after construction. |
80 // This discards ALL queue entries, and map entries. | 77 // This discards ALL queue entries, and map entries. |
81 void Reset(); | 78 void Reset(); |
82 | 79 |
83 // Get a connected NetworkHints. | |
84 mojom::NetworkHints& GetNetworkHints(); | |
85 | |
86 // We use c_string_queue_ to hold lists of names supplied typically) by the | 80 // We use c_string_queue_ to hold lists of names supplied typically) by the |
87 // renderer. It queues the names, at minimal cost to the renderer's thread, | 81 // renderer. It queues the names, at minimal cost to the renderer's thread, |
88 // and allows this class to process them when time permits (in a later task). | 82 // and allows this class to process them when time permits (in a later task). |
89 DnsQueue c_string_queue_; | 83 DnsQueue c_string_queue_; |
90 | 84 |
91 | 85 |
92 // domain_map_ contains (for each domain) one of the next two constants, | 86 // domain_map_ contains (for each domain) one of the next two constants, |
93 // depending on whether we have asked the browser process to do the actual | 87 // depending on whether we have asked the browser process to do the actual |
94 // DNS lookup. | 88 // DNS lookup. |
95 static const int kLookupRequested = 0x1; | 89 static const int kLookupRequested = 0x1; |
96 static const int kPending = 0x0; | 90 static const int kPending = 0x0; |
97 typedef std::map<std::string, int> DomainUseMap; | 91 typedef std::map<std::string, int> DomainUseMap; |
98 DomainUseMap domain_map_; | 92 DomainUseMap domain_map_; |
99 | 93 |
100 // Cache a tally of the count of names that haven't yet been sent | 94 // Cache a tally of the count of names that haven't yet been sent |
101 // for DNS pre-fetching. Note that we *could* recalculate this | 95 // for DNS pre-fetching. Note that we *could* recalculate this |
102 // count by iterating over domain_map_, looking for even values. | 96 // count by iterating over domain_map_, looking for even values. |
103 size_t new_name_count_; | 97 size_t new_name_count_; |
104 | 98 |
105 // We have some metrics to examine performance. We might use | 99 // We have some metrics to examine performance. We might use |
106 // these metrics to modify buffer counts etc. some day. | 100 // these metrics to modify buffer counts etc. some day. |
107 int buffer_full_discard_count_; | 101 int buffer_full_discard_count_; |
108 int numeric_ip_discard_count_; | 102 int numeric_ip_discard_count_; |
109 | 103 |
110 // Don't use directly. Instead call |GetNetworkHints()|. | |
111 mojom::NetworkHintsPtr network_hints_; | |
112 | |
113 base::WeakPtrFactory<RendererDnsPrefetch> weak_factory_; | 104 base::WeakPtrFactory<RendererDnsPrefetch> weak_factory_; |
114 | 105 |
115 DISALLOW_COPY_AND_ASSIGN(RendererDnsPrefetch); | 106 DISALLOW_COPY_AND_ASSIGN(RendererDnsPrefetch); |
116 }; // class RendererDnsPrefetch | 107 }; // class RendererDnsPrefetch |
117 | 108 |
118 } // namespace network_hints | 109 } // namespace network_hints |
119 | 110 |
120 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ | 111 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ |
OLD | NEW |