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

Unified Diff: components/password_manager/core/browser/log_router.cc

Issue 262583007: Password manager internals page service: introduction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 6 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/log_router.cc
diff --git a/components/password_manager/core/browser/log_router.cc b/components/password_manager/core/browser/log_router.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d355b47ad78fc89142586bb80b88b2882b744c58
--- /dev/null
+++ b/components/password_manager/core/browser/log_router.cc
@@ -0,0 +1,59 @@
+// Copyright 2014 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 "components/password_manager/core/browser/log_router.h"
+
+#include "base/stl_util.h"
+#include "components/password_manager/core/browser/password_manager_client.h"
+#include "components/password_manager/core/browser/password_manager_logger.h"
+
+namespace password_manager {
+
+LogRouter::LogRouter() {
+}
+
+LogRouter::~LogRouter() {
+}
+
+void LogRouter::ProcessLog(const std::string& text) {
+ // This may not be called when there are no receivers (i.e., the router is
+ // inactive), because in that case the logs cannot be displayed.
+ CHECK(receivers_.might_have_observers());
Ilya Sherman 2014/05/07 00:28:39 nit: DCHECK?
vabr (Chromium) 2014/05/07 13:42:59 I was thinking about a DCHECK, but there's a catch
Ilya Sherman 2014/05/08 03:38:52 A DCHECK doesn't mean that something is disallowed
vabr (Chromium) 2014/05/08 17:41:54 Thanks Ilya, for explaining the use-cases for CHEC
+ accumulated_logs_.append(text);
+ FOR_EACH_OBSERVER(
+ PasswordManagerLogger, receivers_, LogSavePasswordProgress(text));
+}
+
+bool LogRouter::RegisterClient(PasswordManagerClient* client) {
+ DCHECK(client);
+ clients_.AddObserver(client);
+ return receivers_.might_have_observers();
+}
+
+void LogRouter::UnregisterClient(PasswordManagerClient* client) {
+ DCHECK(client);
+ clients_.RemoveObserver(client);
+}
+
+std::string LogRouter::RegisterReceiver(PasswordManagerLogger* receiver) {
+ DCHECK(receiver);
+ DCHECK(accumulated_logs_.empty() || receivers_.might_have_observers());
+
+ // TODO(vabr): Once the clients provide API for that, notify them if the
+ // number of receivers went from 0 to 1.
+ receivers_.AddObserver(receiver);
+ return accumulated_logs_;
+}
+
+void LogRouter::UnregisterReceiver(PasswordManagerLogger* receiver) {
+ DCHECK(receiver);
Ilya Sherman 2014/05/07 00:28:39 nit: IMO DCHECK(receivers_.HasObserver(receiver))
vabr (Chromium) 2014/05/07 13:42:59 Agreed, also for the UnregisterClient. Done.
+ receivers_.RemoveObserver(receiver);
+ if (!receivers_.might_have_observers()) {
+ accumulated_logs_.clear();
+ // TODO(vabr): Once the clients provide API for that, notify them that the
+ // number of receivers went from 1 to 0.
+ }
+}
+
+} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698