1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/password_manager/core/browser/log_router.h"
7 #include "base/stl_util.h"
8 #include "components/password_manager/core/browser/log_receiver.h"
9 #include "components/password_manager/core/browser/password_manager_client.h"
11 namespace password_manager
{
13 LogRouter::LogRouter() {
16 LogRouter::~LogRouter() {
19 void LogRouter::ProcessLog(const std::string
& text
) {
20 // This may not be called when there are no receivers (i.e., the router is
21 // inactive), because in that case the logs cannot be displayed.
22 DCHECK(receivers_
.might_have_observers());
23 accumulated_logs_
.append(text
);
24 FOR_EACH_OBSERVER(LogReceiver
, receivers_
, LogSavePasswordProgress(text
));
27 bool LogRouter::RegisterClient(PasswordManagerClient
* client
) {
29 clients_
.AddObserver(client
);
30 return receivers_
.might_have_observers();
33 void LogRouter::UnregisterClient(PasswordManagerClient
* client
) {
34 DCHECK(clients_
.HasObserver(client
));
35 clients_
.RemoveObserver(client
);
38 std::string
LogRouter::RegisterReceiver(LogReceiver
* receiver
) {
40 DCHECK(accumulated_logs_
.empty() || receivers_
.might_have_observers());
42 if (!receivers_
.might_have_observers()) {
44 PasswordManagerClient
, clients_
, OnLogRouterAvailabilityChanged(true));
46 receivers_
.AddObserver(receiver
);
47 return accumulated_logs_
;
50 void LogRouter::UnregisterReceiver(LogReceiver
* receiver
) {
51 DCHECK(receivers_
.HasObserver(receiver
));
52 receivers_
.RemoveObserver(receiver
);
53 if (!receivers_
.might_have_observers()) {
54 accumulated_logs_
.clear();
56 PasswordManagerClient
, clients_
, OnLogRouterAvailabilityChanged(false));
60 } // namespace password_manager