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/common/network_hints.mojom.h" | |
31 #include "components/network_hints/renderer/dns_prefetch_queue.h" | 32 #include "components/network_hints/renderer/dns_prefetch_queue.h" |
32 | 33 |
33 namespace network_hints { | 34 namespace network_hints { |
34 | 35 |
36 class NetworkHints; | |
37 | |
35 // An internal interface to the network_hints component for efficiently sending | 38 // An internal interface to the network_hints component for efficiently sending |
36 // DNS prefetch requests to the net stack. | 39 // DNS prefetch requests to the net stack. |
37 class RendererDnsPrefetch { | 40 class RendererDnsPrefetch { |
38 public: | 41 public: |
39 RendererDnsPrefetch(); | 42 RendererDnsPrefetch(); |
40 ~RendererDnsPrefetch(); | 43 ~RendererDnsPrefetch(); |
41 | 44 |
42 // Push a name into the queue to be resolved. | 45 // Push a name into the queue to be resolved. |
43 void Resolve(const char* name, size_t length); | 46 void Resolve(const char* name, size_t length); |
44 | 47 |
(...skipping 25 matching lines...) Expand all Loading... | |
70 // DnsPrefetchNames does not check the buffer, and just sends names | 73 // DnsPrefetchNames does not check the buffer, and just sends names |
71 // that are already collected in the domain_map_ for DNS lookup. | 74 // that are already collected in the domain_map_ for DNS lookup. |
72 // If max_count is zero, then all available names are sent; and | 75 // If max_count is zero, then all available names are sent; and |
73 // if positive, then at most max_count names will be sent. | 76 // if positive, then at most max_count names will be sent. |
74 void DnsPrefetchNames(size_t max_count = 0); | 77 void DnsPrefetchNames(size_t max_count = 0); |
75 | 78 |
76 // Reset() restores initial state provided after construction. | 79 // Reset() restores initial state provided after construction. |
77 // This discards ALL queue entries, and map entries. | 80 // This discards ALL queue entries, and map entries. |
78 void Reset(); | 81 void Reset(); |
79 | 82 |
83 // Ensure that the Mojo connection to NetworkHints has been created. | |
84 void EnsureConnected(); | |
Sam McNally
2016/07/12 05:25:30
I would prefer a getter that returns a mojom::Netw
tibell
2016/07/12 07:14:24
Done.
| |
85 | |
80 // We use c_string_queue_ to hold lists of names supplied typically) by the | 86 // We use c_string_queue_ to hold lists of names supplied typically) by the |
81 // renderer. It queues the names, at minimal cost to the renderer's thread, | 87 // renderer. It queues the names, at minimal cost to the renderer's thread, |
82 // and allows this class to process them when time permits (in a later task). | 88 // and allows this class to process them when time permits (in a later task). |
83 DnsQueue c_string_queue_; | 89 DnsQueue c_string_queue_; |
84 | 90 |
85 | 91 |
86 // domain_map_ contains (for each domain) one of the next two constants, | 92 // domain_map_ contains (for each domain) one of the next two constants, |
87 // depending on whether we have asked the browser process to do the actual | 93 // depending on whether we have asked the browser process to do the actual |
88 // DNS lookup. | 94 // DNS lookup. |
89 static const int kLookupRequested = 0x1; | 95 static const int kLookupRequested = 0x1; |
90 static const int kPending = 0x0; | 96 static const int kPending = 0x0; |
91 typedef std::map<std::string, int> DomainUseMap; | 97 typedef std::map<std::string, int> DomainUseMap; |
92 DomainUseMap domain_map_; | 98 DomainUseMap domain_map_; |
93 | 99 |
94 // Cache a tally of the count of names that haven't yet been sent | 100 // Cache a tally of the count of names that haven't yet been sent |
95 // for DNS pre-fetching. Note that we *could* recalculate this | 101 // for DNS pre-fetching. Note that we *could* recalculate this |
96 // count by iterating over domain_map_, looking for even values. | 102 // count by iterating over domain_map_, looking for even values. |
97 size_t new_name_count_; | 103 size_t new_name_count_; |
98 | 104 |
99 // We have some metrics to examine performance. We might use | 105 // We have some metrics to examine performance. We might use |
100 // these metrics to modify buffer counts etc. some day. | 106 // these metrics to modify buffer counts etc. some day. |
101 int buffer_full_discard_count_; | 107 int buffer_full_discard_count_; |
102 int numeric_ip_discard_count_; | 108 int numeric_ip_discard_count_; |
103 | 109 |
110 // |EnsureConnected()| must be called before sending messages using | |
111 // |network_hints_|. | |
112 mojom::NetworkHintsPtr network_hints_; | |
113 | |
104 base::WeakPtrFactory<RendererDnsPrefetch> weak_factory_; | 114 base::WeakPtrFactory<RendererDnsPrefetch> weak_factory_; |
105 | 115 |
106 DISALLOW_COPY_AND_ASSIGN(RendererDnsPrefetch); | 116 DISALLOW_COPY_AND_ASSIGN(RendererDnsPrefetch); |
107 }; // class RendererDnsPrefetch | 117 }; // class RendererDnsPrefetch |
108 | 118 |
109 } // namespace network_hints | 119 } // namespace network_hints |
110 | 120 |
111 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ | 121 #endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ |
OLD | NEW |