| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 copy = capture_list_; | 190 copy = capture_list_; |
| 191 } | 191 } |
| 192 return copy; | 192 return copy; |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool HasBlockedRequests() const { | 195 bool HasBlockedRequests() const { |
| 196 base::AutoLock lock(lock_); | 196 base::AutoLock lock(lock_); |
| 197 return num_requests_waiting_ > num_slots_available_; | 197 return num_requests_waiting_ > num_slots_available_; |
| 198 } | 198 } |
| 199 | 199 |
| 200 private: | 200 protected: |
| 201 ~MockHostResolverProc() {} | 201 ~MockHostResolverProc() {} |
| 202 | 202 |
| 203 private: |
| 203 mutable base::Lock lock_; | 204 mutable base::Lock lock_; |
| 204 std::map<ResolveKey, AddressList> rules_; | 205 std::map<ResolveKey, AddressList> rules_; |
| 205 CaptureList capture_list_; | 206 CaptureList capture_list_; |
| 206 unsigned num_requests_waiting_; | 207 unsigned num_requests_waiting_; |
| 207 unsigned num_slots_available_; | 208 unsigned num_slots_available_; |
| 208 base::ConditionVariable requests_waiting_; | 209 base::ConditionVariable requests_waiting_; |
| 209 base::ConditionVariable slots_available_; | 210 base::ConditionVariable slots_available_; |
| 210 | 211 |
| 211 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc); | 212 DISALLOW_COPY_AND_ASSIGN(MockHostResolverProc); |
| 212 }; | 213 }; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Since any negative number is considered a network error, with -1 having | 428 // Since any negative number is considered a network error, with -1 having |
| 428 // special meaning (ERR_IO_PENDING). We could return the attempt that has | 429 // special meaning (ERR_IO_PENDING). We could return the attempt that has |
| 429 // resolved the host as a negative number. For example, if attempt number 3 | 430 // resolved the host as a negative number. For example, if attempt number 3 |
| 430 // resolves the host, then this method returns -4. | 431 // resolves the host, then this method returns -4. |
| 431 if (result == OK) | 432 if (result == OK) |
| 432 return -1 - resolved_attempt_number_; | 433 return -1 - resolved_attempt_number_; |
| 433 else | 434 else |
| 434 return result; | 435 return result; |
| 435 } | 436 } |
| 436 | 437 |
| 437 private: | 438 protected: |
| 438 virtual ~LookupAttemptHostResolverProc() {} | 439 virtual ~LookupAttemptHostResolverProc() {} |
| 439 | 440 |
| 441 private: |
| 440 int attempt_number_to_resolve_; | 442 int attempt_number_to_resolve_; |
| 441 int current_attempt_number_; // Incremented whenever Resolve is called. | 443 int current_attempt_number_; // Incremented whenever Resolve is called. |
| 442 int total_attempts_; | 444 int total_attempts_; |
| 443 int total_attempts_resolved_; | 445 int total_attempts_resolved_; |
| 444 int resolved_attempt_number_; | 446 int resolved_attempt_number_; |
| 445 | 447 |
| 446 // All attempts wait for right attempt to be resolve. | 448 // All attempts wait for right attempt to be resolve. |
| 447 base::Lock lock_; | 449 base::Lock lock_; |
| 448 base::ConditionVariable all_done_; | 450 base::ConditionVariable all_done_; |
| 449 }; | 451 }; |
| (...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 EXPECT_EQ(OK, req5->Resolve()); | 1357 EXPECT_EQ(OK, req5->Resolve()); |
| 1356 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); | 1358 EXPECT_TRUE(req5->HasOneAddress("::1", 80)); |
| 1357 | 1359 |
| 1358 // Request with upper case. | 1360 // Request with upper case. |
| 1359 Request* req6 = CreateRequest("er_IPV4", 80); | 1361 Request* req6 = CreateRequest("er_IPV4", 80); |
| 1360 EXPECT_EQ(OK, req6->Resolve()); | 1362 EXPECT_EQ(OK, req6->Resolve()); |
| 1361 EXPECT_TRUE(req6->HasOneAddress("127.0.0.1", 80)); | 1363 EXPECT_TRUE(req6->HasOneAddress("127.0.0.1", 80)); |
| 1362 } | 1364 } |
| 1363 | 1365 |
| 1364 } // namespace net | 1366 } // namespace net |
| OLD | NEW |