| 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/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 return false; | 406 return false; |
| 407 | 407 |
| 408 alternative_service_map_.Erase(it); | 408 alternative_service_map_.Erase(it); |
| 409 return true; | 409 return true; |
| 410 } | 410 } |
| 411 | 411 |
| 412 bool changed = true; | 412 bool changed = true; |
| 413 if (it != alternative_service_map_.end()) { | 413 if (it != alternative_service_map_.end()) { |
| 414 DCHECK(!it->second.empty()); | 414 DCHECK(!it->second.empty()); |
| 415 if (it->second.size() == alternative_service_info_vector.size()) { | 415 if (it->second.size() == alternative_service_info_vector.size()) { |
| 416 changed = !std::equal(it->second.begin(), it->second.end(), | 416 const base::Time now = base::Time::Now(); |
| 417 alternative_service_info_vector.begin()); | 417 changed = false; |
| 418 auto new_it = alternative_service_info_vector.begin(); |
| 419 for (const auto& old : it->second) { |
| 420 // Persist to disk immediately if new entry has different scheme, host, |
| 421 // or port. |
| 422 if (old.alternative_service != new_it->alternative_service) { |
| 423 changed = true; |
| 424 break; |
| 425 } |
| 426 // Also persist to disk if new expiration it more that twice as far or |
| 427 // less than half as far in the future. |
| 428 base::Time old_time = old.expiration; |
| 429 base::Time new_time = new_it->expiration; |
| 430 if (new_time - now > 2 * (old_time - now) || |
| 431 2 * (new_time - now) < (old_time - now)) { |
| 432 changed = true; |
| 433 break; |
| 434 } |
| 435 ++new_it; |
| 436 } |
| 418 } | 437 } |
| 419 } | 438 } |
| 420 | 439 |
| 421 const bool previously_no_alternative_services = | 440 const bool previously_no_alternative_services = |
| 422 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 441 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 423 | 442 |
| 424 alternative_service_map_.Put(origin, alternative_service_info_vector); | 443 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 425 | 444 |
| 426 if (previously_no_alternative_services && | 445 if (previously_no_alternative_services && |
| 427 !GetAlternativeServices(origin).empty()) { | 446 !GetAlternativeServices(origin).empty()) { |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 798 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 780 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 799 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 781 FROM_HERE, | 800 FROM_HERE, |
| 782 base::Bind( | 801 base::Bind( |
| 783 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 802 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 784 weak_ptr_factory_.GetWeakPtr()), | 803 weak_ptr_factory_.GetWeakPtr()), |
| 785 delay); | 804 delay); |
| 786 } | 805 } |
| 787 | 806 |
| 788 } // namespace net | 807 } // namespace net |
| OLD | NEW |