summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/fixed_host_resolver.cc52
-rw-r--r--net/base/fixed_host_resolver.h42
-rw-r--r--net/base/host_resolver.h12
-rw-r--r--net/net.gyp2
4 files changed, 103 insertions, 5 deletions
diff --git a/net/base/fixed_host_resolver.cc b/net/base/fixed_host_resolver.cc
new file mode 100644
index 0000000..54e48a9
--- /dev/null
+++ b/net/base/fixed_host_resolver.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/fixed_host_resolver.h"
+
+#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
+#include "net/base/host_resolver_impl.h"
+
+namespace net {
+
+FixedHostResolver::FixedHostResolver(const std::string& host_and_port)
+ : initialized_(false) {
+ std::string host;
+ int port = 0;
+ if (!ParseHostAndPort(host_and_port, &host, &port)) {
+ LOG(ERROR) << "Invalid FixedHostResolver information: " << host_and_port;
+ return;
+ }
+
+ int rv = SystemHostResolverProc(host, net::ADDRESS_FAMILY_UNSPECIFIED,
+ &address_);
+ if (rv != OK) {
+ LOG(ERROR) << "Could not resolve fixed host: " << host;
+ return;
+ }
+
+ if (port <= 0) {
+ LOG(ERROR) << "FixedHostResolver must contain a port number";
+ return;
+ }
+
+ address_.SetPort(port);
+ initialized_ = true;
+}
+
+int FixedHostResolver::Resolve(const RequestInfo& info,
+ AddressList* addresses,
+ CompletionCallback* callback,
+ RequestHandle* out_req,
+ LoadLog* load_log) {
+ if (!initialized_)
+ return ERR_NAME_NOT_RESOLVED;
+
+ DCHECK(addresses);
+ *addresses = address_;
+ return OK;
+}
+
+} // namespace net
+
diff --git a/net/base/fixed_host_resolver.h b/net/base/fixed_host_resolver.h
new file mode 100644
index 0000000..cf1bd74
--- /dev/null
+++ b/net/base/fixed_host_resolver.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_FIXED_HOST_RESOLVER_H_
+#define NET_BASE_FIXED_HOST_RESOLVER_H_
+
+#include <string>
+
+#include "net/base/address_list.h"
+#include "net/base/host_resolver.h"
+
+namespace net {
+
+// A FixedHostResolver resolves all addresses to a single address.
+class FixedHostResolver : public HostResolver {
+ public:
+ // |host_and_port| is a string representing the resolution.
+ // example: foo.myproxy.com:1234
+ explicit FixedHostResolver(const std::string& host_and_port);
+
+ // HostResolver methods:
+ virtual int Resolve(const RequestInfo& info,
+ AddressList* addresses,
+ CompletionCallback* callback,
+ RequestHandle* out_req,
+ LoadLog* load_log);
+ virtual void CancelRequest(RequestHandle req) {}
+ virtual void AddObserver(Observer* observer) {}
+ virtual void RemoveObserver(Observer* observer) {}
+ virtual HostCache* GetHostCache() { return NULL; }
+ virtual void Shutdown() {}
+
+ private:
+ AddressList address_;
+ bool initialized_;
+};
+
+} // namespace net
+
+#endif // NET_BASE_MOCK_HOST_RESOLVER_H_
+
diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h
index 998de32..9534e03 100644
--- a/net/base/host_resolver.h
+++ b/net/base/host_resolver.h
@@ -116,11 +116,13 @@ class HostResolver : public base::RefCountedThreadSafe<HostResolver> {
//
// When callback is null, the operation completes synchronously.
//
- // When callback is non-null, the operation will be performed asynchronously.
- // ERR_IO_PENDING is returned if it has been scheduled successfully. Real
- // result code will be passed to the completion callback. If |req| is
- // non-NULL, then |*req| will be filled with a handle to the async request.
- // This handle is not valid after the request has completed.
+ // When callback is non-null, the operation may be performed asynchronously.
+ // If the operation cannnot be completed synchronously, ERR_IO_PENDING will
+ // be returned and the real result code will be passed to the completion
+ // callback. Otherwise the result code is returned immediately from this
+ // call.
+ // If |req| is non-NULL, then |*req| will be filled with a handle to the
+ // async request. This handle is not valid after the request has completed.
//
// Profiling information for the request is saved to |load_log| if non-NULL.
virtual int Resolve(const RequestInfo& info,
diff --git a/net/net.gyp b/net/net.gyp
index d83f545..23154cb 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -66,6 +66,8 @@
'base/file_stream_win.cc',
'base/filter.cc',
'base/filter.h',
+ 'base/fixed_host_resolver.cc',
+ 'base/fixed_host_resolver.h',
'base/gzip_filter.cc',
'base/gzip_filter.h',
'base/gzip_header.cc',