| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #ifndef NET_BASE_HOST_RESOLVER_UNITTEST_H_ | 5 #ifndef NET_BASE_HOST_RESOLVER_UNITTEST_H_ |
| 6 #define NET_BASE_HOST_RESOLVER_UNITTEST_H_ | 6 #define NET_BASE_HOST_RESOLVER_UNITTEST_H_ |
| 7 | 7 |
| 8 #ifdef UNIT_TEST | 8 #ifdef UNIT_TEST |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // to the previously set HostMapper (see SetHostMapper). This is true for all | 118 // to the previously set HostMapper (see SetHostMapper). This is true for all |
| 119 // mappers defined in this file. If no HostMapper matches a given hostname, then | 119 // mappers defined in this file. If no HostMapper matches a given hostname, then |
| 120 // the hostname will be unmodified. | 120 // the hostname will be unmodified. |
| 121 class ScopedHostMapper { | 121 class ScopedHostMapper { |
| 122 public: | 122 public: |
| 123 ScopedHostMapper(HostMapper* mapper) : current_host_mapper_(mapper) { | 123 ScopedHostMapper(HostMapper* mapper) : current_host_mapper_(mapper) { |
| 124 previous_host_mapper_ = SetHostMapper(current_host_mapper_.get()); | 124 previous_host_mapper_ = SetHostMapper(current_host_mapper_.get()); |
| 125 current_host_mapper_->set_previous_mapper(previous_host_mapper_.get()); | 125 current_host_mapper_->set_previous_mapper(previous_host_mapper_.get()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 ScopedHostMapper() {} |
| 129 |
| 128 ~ScopedHostMapper() { | 130 ~ScopedHostMapper() { |
| 129 HostMapper* old_mapper = SetHostMapper(previous_host_mapper_.get()); | 131 HostMapper* old_mapper = SetHostMapper(previous_host_mapper_.get()); |
| 130 // The lifetimes of multiple instances must be nested. | 132 // The lifetimes of multiple instances must be nested. |
| 131 CHECK(old_mapper == current_host_mapper_.get()); | 133 CHECK(old_mapper == current_host_mapper_.get()); |
| 132 } | 134 } |
| 133 | 135 |
| 136 void Init(HostMapper* mapper) { |
| 137 current_host_mapper_ = mapper; |
| 138 previous_host_mapper_ = SetHostMapper(current_host_mapper_.get()); |
| 139 current_host_mapper_->set_previous_mapper(previous_host_mapper_.get()); |
| 140 } |
| 141 |
| 134 private: | 142 private: |
| 135 scoped_refptr<HostMapper> current_host_mapper_; | 143 scoped_refptr<HostMapper> current_host_mapper_; |
| 136 scoped_refptr<HostMapper> previous_host_mapper_; | 144 scoped_refptr<HostMapper> previous_host_mapper_; |
| 137 }; | 145 }; |
| 138 | 146 |
| 139 } // namespace net | 147 } // namespace net |
| 140 | 148 |
| 141 #endif // UNIT_TEST | 149 #endif // UNIT_TEST |
| 142 | 150 |
| 143 #endif // NET_BASE_HOST_RESOLVER_UNITTEST_H_ | 151 #endif // NET_BASE_HOST_RESOLVER_UNITTEST_H_ |
| OLD | NEW |