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 STHDistributor::STHDistributor() | 21 STHDistributor::STHDistributor() |
| 22 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} | 22 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} |
| 23 | 23 |
| 24 STHDistributor::~STHDistributor() {} | 24 STHDistributor::~STHDistributor() {} |
| 25 | 25 |
| 26 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { | 26 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { |
| 27 auto it = std::find_if(observed_sths_.begin(), observed_sths_.end(), | |
| 28 [&sth](const SignedTreeHead& other) { | |
| 29 return sth.log_id == other.log_id; | |
| 30 }); | |
| 31 | |
| 32 if (it == observed_sths_.end()) | |
| 33 observed_sths_.push_back(sth); | |
| 34 else | |
| 35 *it = sth; | |
| 36 | |
| 27 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth)); | 37 FOR_EACH_OBSERVER(STHObserver, observer_list_, NewSTHObserved(sth)); |
| 28 | 38 |
| 29 if (sth.log_id.compare(0, sth.log_id.size(), kPilotLogID, | 39 if (sth.log_id.compare(0, sth.log_id.size(), kPilotLogID, |
| 30 arraysize(kPilotLogID) - 1) != 0) | 40 arraysize(kPilotLogID) - 1) != 0) |
| 31 return; | 41 return; |
| 32 | 42 |
| 33 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp; | 43 const base::TimeDelta sth_age = base::Time::Now() - sth.timestamp; |
| 34 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age, | 44 UMA_HISTOGRAM_CUSTOM_TIMES("Net.CertificateTransparency.PilotSTHAge", sth_age, |
| 35 base::TimeDelta::FromHours(1), | 45 base::TimeDelta::FromHours(1), |
| 36 base::TimeDelta::FromDays(4), 100); | 46 base::TimeDelta::FromDays(4), 100); |
| 37 } | 47 } |
| 38 | 48 |
| 39 void STHDistributor::RegisterObserver(STHObserver* observer) { | 49 void STHDistributor::RegisterObserver(STHObserver* observer) { |
| 40 observer_list_.AddObserver(observer); | 50 observer_list_.AddObserver(observer); |
| 51 for (const auto& sth : observed_sths_) | |
| 52 observer->NewSTHObserved(sth); | |
|
Ryan Sleevi
2016/05/16 19:19:01
DESIGN/DANGER/SAFETY: It seems possible that |obse
Eran Messeri
2016/05/17 09:51:03
Good point - switched to your first suggestion of
| |
| 41 } | 53 } |
| 42 | 54 |
| 43 void STHDistributor::UnregisterObserver(STHObserver* observer) { | 55 void STHDistributor::UnregisterObserver(STHObserver* observer) { |
| 44 observer_list_.RemoveObserver(observer); | 56 observer_list_.RemoveObserver(observer); |
| 45 } | 57 } |
| 46 | 58 |
| 47 } // namespace ct | 59 } // namespace ct |
| 48 | 60 |
| 49 } // namespace net | 61 } // namespace net |
| OLD | NEW |