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) 14 : initialized_(false) { 15 int port; 16 std::string parsed_host; 17 if (!ParseHostAndPort(host, &parsed_host, &port)) { 18 LOG(DFATAL) << "Invalid FixedHostResolver information: " << host; 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 initialized_ = true; 30 } 31 32 int FixedHostResolver::Resolve(const RequestInfo& info, 33 AddressList* addresses, 34 CompletionCallback* callback, 35 RequestHandle* out_req, 36 LoadLog* load_log) { 37 if (!initialized_) 38 return ERR_NAME_NOT_RESOLVED; 39 40 DCHECK(addresses); 41 addresses->Copy(address_.head()); 42 addresses->SetPort(info.port()); 43 return OK; 44 } 45 46 } // namespace net 47