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

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

Issue 525084: Cancel any outstanding host resolve when calling SOCKSClientSocket::Disconnec... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Address wtc's comments Created 10 years, 11 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/socket/socks5_client_socket.cc » ('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) 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 "net/base/host_resolver.h" 5 #include "net/base/host_resolver.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 SingleRequestHostResolver::SingleRequestHostResolver(HostResolver* resolver) 13 SingleRequestHostResolver::SingleRequestHostResolver(HostResolver* resolver)
14 : resolver_(resolver), 14 : resolver_(resolver),
15 cur_request_(NULL), 15 cur_request_(NULL),
16 cur_request_callback_(NULL), 16 cur_request_callback_(NULL),
17 ALLOW_THIS_IN_INITIALIZER_LIST( 17 ALLOW_THIS_IN_INITIALIZER_LIST(
18 callback_(this, &SingleRequestHostResolver::OnResolveCompletion)) { 18 callback_(this, &SingleRequestHostResolver::OnResolveCompletion)) {
19 DCHECK(resolver_ != NULL); 19 DCHECK(resolver_ != NULL);
20 } 20 }
21 21
22 SingleRequestHostResolver::~SingleRequestHostResolver() { 22 SingleRequestHostResolver::~SingleRequestHostResolver() {
23 if (cur_request_) { 23 Cancel();
24 resolver_->CancelRequest(cur_request_);
25 }
26 } 24 }
27 25
28 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info, 26 int SingleRequestHostResolver::Resolve(const HostResolver::RequestInfo& info,
29 AddressList* addresses, 27 AddressList* addresses,
30 CompletionCallback* callback, 28 CompletionCallback* callback,
31 LoadLog* load_log) { 29 LoadLog* load_log) {
32 DCHECK(!cur_request_ && !cur_request_callback_) << "resolver already in use"; 30 DCHECK(!cur_request_ && !cur_request_callback_) << "resolver already in use";
33 31
34 HostResolver::RequestHandle request = NULL; 32 HostResolver::RequestHandle request = NULL;
35 33
36 // We need to be notified of completion before |callback| is called, so that 34 // We need to be notified of completion before |callback| is called, so that
37 // we can clear out |cur_request_*|. 35 // we can clear out |cur_request_*|.
38 CompletionCallback* transient_callback = callback ? &callback_ : NULL; 36 CompletionCallback* transient_callback = callback ? &callback_ : NULL;
39 37
40 int rv = resolver_->Resolve( 38 int rv = resolver_->Resolve(
41 info, addresses, transient_callback, &request, load_log); 39 info, addresses, transient_callback, &request, load_log);
42 40
43 if (rv == ERR_IO_PENDING) { 41 if (rv == ERR_IO_PENDING) {
44 // Cleared in OnResolveCompletion(). 42 // Cleared in OnResolveCompletion().
45 cur_request_ = request; 43 cur_request_ = request;
46 cur_request_callback_ = callback; 44 cur_request_callback_ = callback;
47 } 45 }
48 46
49 return rv; 47 return rv;
50 } 48 }
51 49
50 void SingleRequestHostResolver::Cancel() {
51 if (cur_request_) {
52 resolver_->CancelRequest(cur_request_);
53 cur_request_ = NULL;
54 }
55 }
56
52 void SingleRequestHostResolver::OnResolveCompletion(int result) { 57 void SingleRequestHostResolver::OnResolveCompletion(int result) {
53 DCHECK(cur_request_ && cur_request_callback_); 58 DCHECK(cur_request_ && cur_request_callback_);
54 59
55 CompletionCallback* callback = cur_request_callback_; 60 CompletionCallback* callback = cur_request_callback_;
56 61
57 // Clear the outstanding request information. 62 // Clear the outstanding request information.
58 cur_request_ = NULL; 63 cur_request_ = NULL;
59 cur_request_callback_ = NULL; 64 cur_request_callback_ = NULL;
60 65
61 // Call the user's original callback. 66 // Call the user's original callback.
62 callback->Run(result); 67 callback->Run(result);
63 } 68 }
64 69
65 } // namespace net 70 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_resolver.h ('k') | net/socket/socks5_client_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698