OLD | NEW |
1 // Copyright (c) 2012 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 // See header file for description of RendererNetPredictor class | 5 // See header file for description of RendererNetPredictor class |
6 | 6 |
7 #include "chrome/renderer/net/renderer_net_predictor.h" | 7 #include "chrome/renderer/net/renderer_net_predictor.h" |
8 | 8 |
9 #include <ctype.h> | 9 #include <ctype.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 DnsQueue::PushResult result = c_string_queue_.Push(name, length); | 50 DnsQueue::PushResult result = c_string_queue_.Push(name, length); |
51 if (DnsQueue::SUCCESSFUL_PUSH == result) { | 51 if (DnsQueue::SUCCESSFUL_PUSH == result) { |
52 if (1 == c_string_queue_.Size()) { | 52 if (1 == c_string_queue_.Size()) { |
53 DCHECK_EQ(old_size, 0u); | 53 DCHECK_EQ(old_size, 0u); |
54 if (0 != old_size) | 54 if (0 != old_size) |
55 return; // Overkill safety net: Don't send too many InvokeLater's. | 55 return; // Overkill safety net: Don't send too many InvokeLater's. |
56 weak_factory_.InvalidateWeakPtrs(); | 56 weak_factory_.InvalidateWeakPtrs(); |
57 RenderThread::Get()->GetMessageLoop()->PostDelayedTask( | 57 RenderThread::Get()->GetMessageLoop()->PostDelayedTask( |
58 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, | 58 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, |
59 weak_factory_.GetWeakPtr()), | 59 weak_factory_.GetWeakPtr()), |
60 base::TimeDelta::FromMilliseconds(10)); | 60 10); |
61 } | 61 } |
62 return; | 62 return; |
63 } | 63 } |
64 if (DnsQueue::OVERFLOW_PUSH == result) { | 64 if (DnsQueue::OVERFLOW_PUSH == result) { |
65 ++buffer_full_discard_count_; | 65 ++buffer_full_discard_count_; |
66 return; | 66 return; |
67 } | 67 } |
68 DCHECK(DnsQueue::REDUNDANT_PUSH == result); | 68 DCHECK(DnsQueue::REDUNDANT_PUSH == result); |
69 } | 69 } |
70 | 70 |
(...skipping 14 matching lines...) Expand all Loading... |
85 | 85 |
86 // Don't overload the browser DNS lookup facility, or take too long here, | 86 // Don't overload the browser DNS lookup facility, or take too long here, |
87 // by only sending off kMAX_SUBMISSION_PER_TASK names to the Browser. | 87 // by only sending off kMAX_SUBMISSION_PER_TASK names to the Browser. |
88 // This will help to avoid overloads when a page has a TON of links. | 88 // This will help to avoid overloads when a page has a TON of links. |
89 DnsPrefetchNames(kMAX_SUBMISSION_PER_TASK); | 89 DnsPrefetchNames(kMAX_SUBMISSION_PER_TASK); |
90 if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) { | 90 if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) { |
91 weak_factory_.InvalidateWeakPtrs(); | 91 weak_factory_.InvalidateWeakPtrs(); |
92 RenderThread::Get()->GetMessageLoop()->PostDelayedTask( | 92 RenderThread::Get()->GetMessageLoop()->PostDelayedTask( |
93 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, | 93 FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, |
94 weak_factory_.GetWeakPtr()), | 94 weak_factory_.GetWeakPtr()), |
95 base::TimeDelta::FromMilliseconds(10)); | 95 10); |
96 } else { | 96 } else { |
97 // TODO(JAR): Should we only clear the map when we navigate, or reload? | 97 // TODO(JAR): Should we only clear the map when we navigate, or reload? |
98 domain_map_.clear(); | 98 domain_map_.clear(); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // Pull some hostnames from the queue, and add them to our map. | 102 // Pull some hostnames from the queue, and add them to our map. |
103 void RendererNetPredictor::ExtractBufferedNames(size_t size_goal) { | 103 void RendererNetPredictor::ExtractBufferedNames(size_t size_goal) { |
104 size_t count(0); // Number of entries to find (0 means find all). | 104 size_t count(0); // Number of entries to find (0 means find all). |
105 if (size_goal > 0) { | 105 if (size_goal > 0) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // address. | 154 // address. |
155 bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) { | 155 bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) { |
156 // Scan for a character outside our lookup list. | 156 // Scan for a character outside our lookup list. |
157 while (length-- > 0) { | 157 while (length-- > 0) { |
158 if (!isdigit(*name) && '.' != *name) | 158 if (!isdigit(*name) && '.' != *name) |
159 return false; | 159 return false; |
160 ++name; | 160 ++name; |
161 } | 161 } |
162 return true; | 162 return true; |
163 } | 163 } |
OLD | NEW |