Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/cert/sth_distributor.h" | 5 #include "net/cert/sth_distributor.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "net/cert/signed_tree_head.h" | 9 #include "net/cert/signed_tree_head.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 const char kPilotLogID[33] = | 12 const char kPilotLogID[33] = |
| 13 "\xa4\xb9\x09\x90\xb4\x18\x58\x14\x87\xbb\x13\xa2\xcc\x67\x70\x0a\x3c\x35" | 13 "\xa4\xb9\x09\x90\xb4\x18\x58\x14\x87\xbb\x13\xa2\xcc\x67\x70\x0a\x3c\x35" |
| 14 "\x98\x04\xf9\x1b\xdf\xb8\xe3\x77\xcd\x0e\xc8\x0d\xdc\x10"; | 14 "\x98\x04\xf9\x1b\xdf\xb8\xe3\x77\xcd\x0e\xc8\x0d\xdc\x10"; |
| 15 } | 15 } |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace ct { | 19 namespace ct { |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 // Compares SignedTreeHeads by their log ID, to facilitate creation of a | |
| 24 // map of STHs where there's only one STH for each log. | |
|
Ryan Sleevi
2016/05/13 15:41:12
Documentation isn't correct because this isn't a m
Eran Messeri
2016/05/16 13:55:14
Removed the struct so the documentation is no long
| |
| 25 struct STHLogIDComparator { | |
| 26 STHLogIDComparator(const std::string& log_id) : log_id_(log_id) {} | |
| 27 bool operator()(const SignedTreeHead& other) { | |
| 28 return other.log_id == log_id_; | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 std::string log_id_; | |
| 33 }; | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 21 STHDistributor::STHDistributor() | 37 STHDistributor::STHDistributor() |
| 22 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} | 38 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} |
| 23 | 39 |
| 24 STHDistributor::~STHDistributor() {} | 40 STHDistributor::~STHDistributor() {} |
| 25 | 41 |
| 26 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { | 42 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { |
| 43 auto it = std::find_if(observed_sths_.begin(), observed_sths_.end(), | |
| 44 STHLogIDComparator(sth.log_id)); | |
|
Ryan Sleevi
2016/05/13 15:41:12
auto it = std::find_if(observed_sths_.begin(), obs
Eran Messeri
2016/05/16 13:55:14
Thanks, I wasn't aware lambdas were allowed in Chr
| |
| 45 | |
| 46 if (it == observed_sths_.end()) | |
| 47 observed_sths_.push_back(sth); | |
| 48 else | |
| 49 *it = sth; | |
| 50 | |
| 51 for (auto observed_sth : observed_sths_) { | |
| 52 if (observed_sth.log_id == sth.log_id) { | |
| 53 observed_sth = sth; | |
| 54 } | |
| 55 } | |
|
Ryan Sleevi
2016/05/13 15:41:12
Why do you do this for loop? It seems entirely red
Eran Messeri
2016/05/16 13:55:14
My bad - leftover code. Removed. You have pointed
| |
| 56 | |
| 27 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth)); | 57 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth)); |
| 28 | 58 |
| 29 if (sth.log_id.compare(0, sth.log_id.size(), kPilotLogID, | 59 if (sth.log_id.compare(0, sth.log_id.size(), kPilotLogID, |
| 30 arraysize(kPilotLogID) - 1) != 0) | 60 arraysize(kPilotLogID) - 1) != 0) |
| 31 return; | 61 return; |
| 32 | 62 |
| 33 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp; | 63 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp; |
| 34 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age, | 64 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age, |
| 35 base::TimeDelta::FromHours(1), | 65 base::TimeDelta::FromHours(1), |
| 36 base::TimeDelta::FromDays(4), 100); | 66 base::TimeDelta::FromDays(4), 100); |
| 37 } | 67 } |
| 38 | 68 |
| 39 void STHDistributor::RegisterObserver(STHObserver* observer) { | 69 void STHDistributor::RegisterObserver(STHObserver* observer) { |
| 40 observer_list_.AddObserver(observer); | 70 observer_list_.AddObserver(observer); |
| 71 for (const auto& sth : observed_sths_) | |
| 72 observer->NewSTHObserved(sth); | |
| 41 } | 73 } |
| 42 | 74 |
| 43 void STHDistributor::UnregisterObserver(STHObserver* observer) { | 75 void STHDistributor::UnregisterObserver(STHObserver* observer) { |
| 44 observer_list_.RemoveObserver(observer); | 76 observer_list_.RemoveObserver(observer); |
| 45 } | 77 } |
| 46 | 78 |
| 47 } // namespace ct | 79 } // namespace ct |
| 48 | 80 |
| 49 } // namespace net | 81 } // namespace net |
| OLD | NEW |