Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: net/base/host_resolver.cc

Issue 6993015: Add unit-tests for SingleRequestHostResolver. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Try to re-upload cuz patch not applying on commit bot... Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/host_resolver.h ('k') | net/base/single_request_host_resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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 #include "net/base/host_resolver.h" 5 #include "net/base/host_resolver.h"
6 6
7 #include "base/compiler_specific.h"
8 #include "base/logging.h"
9 #include "net/base/net_errors.h"
10
11 namespace net { 7 namespace net {
12 8
13 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair) 9 HostResolver::RequestInfo::RequestInfo(const HostPortPair& host_port_pair)
14 : host_port_pair_(host_port_pair), 10 : host_port_pair_(host_port_pair),
15 address_family_(ADDRESS_FAMILY_UNSPECIFIED), 11 address_family_(ADDRESS_FAMILY_UNSPECIFIED),
16 host_resolver_flags_(0), 12 host_resolver_flags_(0),
17 allow_cached_response_(true), 13 allow_cached_response_(true),
18 only_use_cached_response_(false), 14 only_use_cached_response_(false),
19 is_speculative_(false), 15 is_speculative_(false),
20 priority_(MEDIUM) { 16 priority_(MEDIUM) {
21 } 17 }
22 18
23 HostResolver::~HostResolver() { 19 HostResolver::~HostResolver() {
24 } 20 }
25 21
26 AddressFamily HostResolver::GetDefaultAddressFamily() const { 22 AddressFamily HostResolver::GetDefaultAddressFamily() const {
27 return ADDRESS_FAMILY_UNSPECIFIED; 23 return ADDRESS_FAMILY_UNSPECIFIED;
28 } 24 }
29 25
30 HostResolverImpl* HostResolver::GetAsHostResolverImpl() { 26 HostResolverImpl* HostResolver::GetAsHostResolverImpl() {
31 return NULL; 27 return NULL;
32 } 28 }
33 29
34 HostResolver::HostResolver() { 30 HostResolver::HostResolver() {
35 } 31 }
36 32
37 SingleRequestHostResolver::SingleRequestHostResolver(HostResolver* resolver)
38 : resolver_(resolver),
39 cur_request_(NULL),
40 cur_request_callback_(NULL),
41 ALLOW_THIS_IN_INITIALIZER_LIST(
42 callback_(this, &SingleRequestHostResolver::OnResolveCompletion)) {
43 DCHECK(resolver_ != NULL);
44 }
45
46 SingleRequestHostResolver::~SingleRequestHostResolver() {
47 Cancel();
48 }
49
50 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info,
51 AddressList* addresses,
52 CompletionCallback* callback,
53 const BoundNetLog& net_log) {
54 DCHECK(!cur_request_ && !cur_request_callback_) << "resolver already in use";
55
56 HostResolver::RequestHandle request = NULL;
57
58 // We need to be notified of completion before |callback| is called, so that
59 // we can clear out |cur_request_*|.
60 CompletionCallback* transient_callback = callback ? &callback_ : NULL;
61
62 int rv = resolver_->Resolve(
63 info, addresses, transient_callback, &request, net_log);
64
65 if (rv == ERR_IO_PENDING) {
66 // Cleared in OnResolveCompletion().
67 cur_request_ = request;
68 cur_request_callback_ = callback;
69 }
70
71 return rv;
72 }
73
74 void SingleRequestHostResolver::Cancel() {
75 if (cur_request_) {
76 resolver_->CancelRequest(cur_request_);
77 cur_request_ = NULL;
78 }
79 }
80
81 void SingleRequestHostResolver::OnResolveCompletion(int result) {
82 DCHECK(cur_request_ && cur_request_callback_);
83
84 CompletionCallback* callback = cur_request_callback_;
85
86 // Clear the outstanding request information.
87 cur_request_ = NULL;
88 cur_request_callback_ = NULL;
89
90 // Call the user's original callback.
91 callback->Run(result);
92 }
93
94 } // namespace net 33 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver.h ('k') | net/base/single_request_host_resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698