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

Unified Diff: net/cert/sth_observer.cc

Issue 1845113003: Certificate Transparency: Start tracking logs' state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cert/sth_observer.h ('k') | net/net.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/sth_observer.cc
diff --git a/net/cert/sth_observer.cc b/net/cert/sth_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..abe462fe6ad7e0b8c1f610074fd5a024ea149822
--- /dev/null
+++ b/net/cert/sth_observer.cc
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/cert/sth_observer.h"
+
+#include "base/logging.h"
+
+namespace net {
+
+namespace ct {
+
+STHReporterRegistrar::STHReporterRegistrar() : reporter_(nullptr) {}
+
+STHReporterRegistrar::~STHReporterRegistrar() {
+ DCHECK(reporter_ == nullptr || pending_observers_.empty());
+}
+
+void STHReporterRegistrar::SignUpForRegistration(STHObserver* observer) {
+ pending_observers_.insert(observer);
+ if (reporter_) {
+ reporter_->RegisterObserver(observer);
+ }
+}
+
+void STHReporterRegistrar::AssignReporter(STHReporter* reporter) {
+ DCHECK(reporter_ == nullptr);
+ reporter_ = reporter;
+
+ for (auto observer : pending_observers_) {
+ reporter_->RegisterObserver(observer);
+ }
+}
+
+void STHReporterRegistrar::UnregisterAll() {
+ if (reporter_) {
+ for (auto observer : pending_observers_) {
+ reporter_->UnregisterObserver(observer);
+ }
+ }
+
+ pending_observers_.clear();
+}
+
+void STHReporterRegistrar::UnregisterObserver(STHObserver* observer) {
+ DCHECK(pending_observers_.find(observer) != pending_observers_.end());
+
+ reporter_->UnregisterObserver(observer);
+ pending_observers_.erase(observer);
+}
+
+} // namespace ct
+
+} // namespace net
« no previous file with comments | « net/cert/sth_observer.h ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698