Chromium Code Reviews| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 402 |
| 403 if (alternative_service_info_vector.empty()) { | 403 if (alternative_service_info_vector.empty()) { |
| 404 RemoveCanonicalHost(origin); | 404 RemoveCanonicalHost(origin); |
| 405 if (it == alternative_service_map_.end()) | 405 if (it == alternative_service_map_.end()) |
| 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; |
|
Ryan Hamilton
2016/07/21 22:27:05
I think you can simplify this slightly:
bool chan
Bence
2016/07/22 16:28:54
Done.
| |
| 413 if (it != alternative_service_map_.end()) { | 413 if (it == alternative_service_map_.end()) { |
| 414 changed = true; | |
| 415 } else { | |
| 414 DCHECK(!it->second.empty()); | 416 DCHECK(!it->second.empty()); |
| 415 if (it->second.size() == alternative_service_info_vector.size()) { | 417 if (it->second.size() == alternative_service_info_vector.size()) { |
| 416 changed = !std::equal(it->second.begin(), it->second.end(), | 418 const base::Time now = base::Time::Now(); |
| 417 alternative_service_info_vector.begin()); | 419 changed = false; |
| 420 auto new_it = alternative_service_info_vector.begin(); | |
| 421 for (const auto& old : it->second) { | |
| 422 if (old.alternative_service != new_it->alternative_service) { | |
| 423 changed = true; | |
| 424 break; | |
| 425 } | |
| 426 base::Time old_time = old.expiration; | |
| 427 base::Time new_time = new_it->expiration; | |
| 428 if (new_time < old_time || | |
| 429 new_time < now + base::TimeDelta::FromHours(12) || | |
| 430 new_time - now > 2 * (old_time - now)) { | |
|
Ryan Hamilton
2016/07/21 22:27:04
nit: Can you add a comment before the if(...) whic
Bence
2016/07/22 16:28:54
Your proposed (2) is redundant with (1), so I'll j
Ryan Hamilton
2016/07/22 23:31:35
That's true. :) It makes me wonder if we would be
Bence
2016/07/27 16:30:55
Done.
| |
| 431 changed = true; | |
| 432 break; | |
| 433 } | |
| 434 ++new_it; | |
| 435 } | |
| 436 } else { | |
| 437 changed = true; | |
| 418 } | 438 } |
| 419 } | 439 } |
| 420 | 440 |
| 421 const bool previously_no_alternative_services = | 441 const bool previously_no_alternative_services = |
| 422 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 442 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 423 | 443 |
| 424 alternative_service_map_.Put(origin, alternative_service_info_vector); | 444 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 425 | 445 |
| 426 if (previously_no_alternative_services && | 446 if (previously_no_alternative_services && |
| 427 !GetAlternativeServices(origin).empty()) { | 447 !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(); | 799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 780 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 781 FROM_HERE, | 801 FROM_HERE, |
| 782 base::Bind( | 802 base::Bind( |
| 783 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 784 weak_ptr_factory_.GetWeakPtr()), | 804 weak_ptr_factory_.GetWeakPtr()), |
| 785 delay); | 805 delay); |
| 786 } | 806 } |
| 787 | 807 |
| 788 } // namespace net | 808 } // namespace net |
| OLD | NEW |