Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: net/cert/sth_distributor.cc

Issue 1968053002: Certificate Transparency: Notify STH Observers of known STHs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 internal {
22
23 bool STHLogIDComparator::operator()(const SignedTreeHead& first,
24 const SignedTreeHead& second) {
25 return first.log_id < second.log_id;
26 }
27
28 } // namespace internal
29
21 STHDistributor::STHDistributor() 30 STHDistributor::STHDistributor()
22 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {} 31 : observer_list_(base::ObserverList<STHObserver>::NOTIFY_EXISTING_ONLY) {}
23 32
24 STHDistributor::~STHDistributor() {} 33 STHDistributor::~STHDistributor() {}
25 34
26 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) { 35 void STHDistributor::NewSTHObserved(const SignedTreeHead& sth) {
36 observed_sths_.insert(sth);
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 SignedTreeHead& sth : observed_sths_)
Ryan Sleevi 2016/05/12 19:51:28 const auto& is fine here.
Eran Messeri 2016/05/13 09:04:08 Done.
52 observer->NewSTHObserved(sth);
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698