| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 // A RendererNetPredictor instance is maintained for each RenderThread. | |
| 6 // URL strings are typically added to the embedded queue during rendering. | |
| 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. | |
| 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 | |
| 11 // to traverse a link. | |
| 12 // This class removed some duplicates, and discards numeric IP addresss | |
| 13 // (which wouldn't looked up in DNS anyway). | |
| 14 // To limit the time during the processing task (and avoid stalling the Render | |
| 15 // thread), several limits are placed on how much of the queue to process. | |
| 16 // If the processing task is not able to completely empty the queue, it | |
| 17 // schedules a future continuation of the task, and keeps the map of already | |
| 18 // sent names. If the entire queue is processed, then the list of "sent names" | |
| 19 // is cleared so that future gatherings might again pass along the same names. | |
| 20 | |
| 21 #ifndef CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ | |
| 22 #define CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ | |
| 23 | |
| 24 #include <map> | |
| 25 #include <string> | |
| 26 #include <vector> | |
| 27 | |
| 28 #include "base/basictypes.h" | |
| 29 #include "base/task.h" | |
| 30 #include "chrome/renderer/net/render_dns_queue.h" | |
| 31 | |
| 32 // Global API consists to do Prefetching in renderer. This uses IPC to reach | |
| 33 // the Browser's global functions. | |
| 34 void DnsPrefetchCString(const char* hostname, size_t length); | |
| 35 | |
| 36 class RendererNetPredictor { | |
| 37 public: | |
| 38 RendererNetPredictor(); | |
| 39 | |
| 40 ~RendererNetPredictor() {} | |
| 41 | |
| 42 // Push a name into the queue to be resolved. | |
| 43 void Resolve(const char* name, size_t length); | |
| 44 | |
| 45 // SubmitHosts processes the buffered names, and submits them for DNS | |
| 46 // prefetching. | |
| 47 // Note that browser process may decide which names should be looked up (to | |
| 48 // pre-warm the cache) based on what has been (or not been) looked up | |
| 49 // recently. | |
| 50 // If sending for DNS lookup is incomplete (queue is not empty, or not all | |
| 51 // names in map are sent, or ...) then a task to continue processing is | |
| 52 // sent to our thread loop. | |
| 53 void SubmitHostnames(); | |
| 54 | |
| 55 // The following is private, but exposed for testing purposes only. | |
| 56 static bool is_numeric_ip(const char* name, size_t length); | |
| 57 | |
| 58 private: | |
| 59 // ExtractBufferedNames pulls names from queue into the map, reducing or | |
| 60 // eliminating a waiting queue. | |
| 61 // The size_goal argument can be used to reduce the amount of | |
| 62 // processing done in this method, and can leave some data | |
| 63 // in the buffer under some circumstances. | |
| 64 // If size_goal is zero, then extraction proceeds until | |
| 65 // the queue is empty. If size goal is positive, then | |
| 66 // extraction continues until the domain_map_ contains | |
| 67 // at least the specified number of names, or the buffer is empty. | |
| 68 void ExtractBufferedNames(size_t size_goal = 0); | |
| 69 | |
| 70 // DnsPrefetchNames does not check the buffer, and just sends names | |
| 71 // that are already collected in the domain_map_ for DNS lookup. | |
| 72 // If max_count is zero, then all available names are sent; and | |
| 73 // if positive, then at most max_count names will be sent. | |
| 74 void DnsPrefetchNames(size_t max_count = 0); | |
| 75 | |
| 76 // Reset() restores initial state provided after construction. | |
| 77 // This discards ALL queue entries, and map entries. | |
| 78 void Reset(); | |
| 79 | |
| 80 // 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, | |
| 82 // and allows this class to process them when time permits (in a later task). | |
| 83 DnsQueue c_string_queue_; | |
| 84 | |
| 85 | |
| 86 // 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 | |
| 88 // DNS lookup. | |
| 89 static const int kLookupRequested = 0x1; | |
| 90 static const int kPending = 0x0; | |
| 91 typedef std::map<std::string, int> DomainUseMap; | |
| 92 DomainUseMap domain_map_; | |
| 93 | |
| 94 // 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 | |
| 96 // count by iterating over domain_map_, looking for even values. | |
| 97 size_t new_name_count_; | |
| 98 | |
| 99 // We have some metrics to examine performance. We might use | |
| 100 // these metrics to modify buffer counts etc. some day. | |
| 101 int buffer_full_discard_count_; | |
| 102 int numeric_ip_discard_count_; | |
| 103 | |
| 104 ScopedRunnableMethodFactory<RendererNetPredictor> renderer_predictor_factory_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(RendererNetPredictor); | |
| 107 }; // class RendererNetPredictor | |
| 108 | |
| 109 #endif // CHROME_RENDERER_NET_RENDER_DNS_MASTER_H_ | |
| OLD | NEW |