| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/net/dns_master.h" | 5 #include "chrome/browser/net/dns_master.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/histogram.h" | 12 #include "base/histogram.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/lock.h" | 14 #include "base/lock.h" |
| 15 #include "base/stats_counters.h" | 15 #include "base/stats_counters.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "net/base/address_list.h" | 18 #include "net/base/address_list.h" |
| 19 #include "net/base/completion_callback.h" | 19 #include "net/base/completion_callback.h" |
| 20 #include "net/base/host_resolver.h" | 20 #include "net/base/host_resolver.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 | 22 |
| 23 namespace chrome_browser_net { | 23 namespace chrome_browser_net { |
| 24 | 24 |
| 25 class DnsMaster::LookupRequest { | 25 class DnsMaster::LookupRequest { |
| 26 public: | 26 public: |
| 27 LookupRequest(DnsMaster* master, | 27 LookupRequest(DnsMaster* master, |
| 28 net::HostResolver* /*host_resolver*/, | 28 net::HostResolver* host_resolver, |
| 29 const std::string& hostname) | 29 const std::string& hostname) |
| 30 : ALLOW_THIS_IN_INITIALIZER_LIST( | 30 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 31 net_callback_(this, &LookupRequest::OnLookupFinished)), | 31 net_callback_(this, &LookupRequest::OnLookupFinished)), |
| 32 master_(master), | 32 master_(master), |
| 33 hostname_(hostname) { | 33 hostname_(hostname), |
| 34 resolver_(host_resolver) { |
| 34 } | 35 } |
| 35 | 36 |
| 36 bool Start() { | 37 bool Start() { |
| 37 const int result = resolver_.Resolve(hostname_, 80, &addresses_, | 38 const int result = resolver_.Resolve(hostname_, 80, &addresses_, |
| 38 &net_callback_); | 39 &net_callback_); |
| 39 return (result == net::ERR_IO_PENDING); | 40 return (result == net::ERR_IO_PENDING); |
| 40 } | 41 } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 void OnLookupFinished(int result) { | 44 void OnLookupFinished(int result) { |
| 44 master_->OnLookupFinished(this, hostname_, result == net::OK); | 45 master_->OnLookupFinished(this, hostname_, result == net::OK); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // HostResolver will call us using this callback when resolution is complete. | 48 // HostResolver will call us using this callback when resolution is complete. |
| 48 net::CompletionCallbackImpl<LookupRequest> net_callback_; | 49 net::CompletionCallbackImpl<LookupRequest> net_callback_; |
| 49 | 50 |
| 50 DnsMaster* master_; // Master which started us. | 51 DnsMaster* master_; // Master which started us. |
| 51 | 52 |
| 52 const std::string hostname_; // Hostname to resolve. | 53 const std::string hostname_; // Hostname to resolve. |
| 53 net::HostResolver resolver_; | 54 net::SingleRequestHostResolver resolver_; |
| 54 net::AddressList addresses_; | 55 net::AddressList addresses_; |
| 55 | 56 |
| 56 DISALLOW_COPY_AND_ASSIGN(LookupRequest); | 57 DISALLOW_COPY_AND_ASSIGN(LookupRequest); |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 DnsMaster::DnsMaster(net::HostResolver* host_resolver, | 60 DnsMaster::DnsMaster(net::HostResolver* host_resolver, |
| 60 MessageLoop* host_resolver_loop, | 61 MessageLoop* host_resolver_loop, |
| 61 size_t max_concurrent) | 62 size_t max_concurrent) |
| 62 : peak_pending_lookups_(0), | 63 : peak_pending_lookups_(0), |
| 63 shutdown_(false), | 64 shutdown_(false), |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 std::string hostname(rush_queue_.front()); | 591 std::string hostname(rush_queue_.front()); |
| 591 rush_queue_.pop(); | 592 rush_queue_.pop(); |
| 592 return hostname; | 593 return hostname; |
| 593 } | 594 } |
| 594 std::string hostname(background_queue_.front()); | 595 std::string hostname(background_queue_.front()); |
| 595 background_queue_.pop(); | 596 background_queue_.pop(); |
| 596 return hostname; | 597 return hostname; |
| 597 } | 598 } |
| 598 | 599 |
| 599 } // namespace chrome_browser_net | 600 } // namespace chrome_browser_net |
| OLD | NEW |