OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 #include "net/base/fixed_host_resolver.h" |
| 6 |
| 7 #include "net/base/net_errors.h" |
| 8 #include "net/base/net_util.h" |
| 9 #include "net/base/host_resolver_impl.h" |
| 10 |
| 11 namespace net { |
| 12 |
| 13 FixedHostResolver::FixedHostResolver(const std::string& host_and_port) |
| 14 : initialized_(false) { |
| 15 std::string host; |
| 16 int port = 0; |
| 17 if (!ParseHostAndPort(host_and_port, &host, &port)) { |
| 18 LOG(ERROR) << "Invalid FixedHostResolver information: " << host_and_port; |
| 19 return; |
| 20 } |
| 21 |
| 22 int rv = SystemHostResolverProc(host, net::ADDRESS_FAMILY_UNSPECIFIED, |
| 23 &address_); |
| 24 if (rv != OK) { |
| 25 LOG(ERROR) << "Could not resolve fixed host: " << host; |
| 26 return; |
| 27 } |
| 28 |
| 29 if (port <= 0) { |
| 30 LOG(ERROR) << "FixedHostResolver must contain a port number"; |
| 31 return; |
| 32 } |
| 33 |
| 34 address_.SetPort(port); |
| 35 initialized_ = true; |
| 36 } |
| 37 |
| 38 int FixedHostResolver::Resolve(const RequestInfo& info, |
| 39 AddressList* addresses, |
| 40 CompletionCallback* callback, |
| 41 RequestHandle* out_req, |
| 42 LoadLog* load_log) { |
| 43 if (!initialized_) |
| 44 return ERR_NAME_NOT_RESOLVED; |
| 45 |
| 46 DCHECK(addresses); |
| 47 *addresses = address_; |
| 48 return OK; |
| 49 } |
| 50 |
| 51 } // namespace net |
| 52 |
OLD | NEW |