Chromium Code Reviews| Index: components/password_manager/core/browser/log_router.h |
| diff --git a/components/password_manager/core/browser/log_router.h b/components/password_manager/core/browser/log_router.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3c7e5feab989d9fef9f56a7a9b0f1ed61d82ccaf |
| --- /dev/null |
| +++ b/components/password_manager/core/browser/log_router.h |
| @@ -0,0 +1,77 @@ |
| +// 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. |
| + |
| +#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ |
| +#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ |
| + |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| + |
| +namespace password_manager { |
| + |
| +class PasswordManagerClient; |
| +class PasswordManagerLogger; |
| + |
| +// The router stands between PasswordManagerClient instances and log receivers. |
| +// During the process of saving a password, the password manager code generates |
| +// the log strings, and passes them to the router. The receivers are capable of |
| +// actually displaying them to the user; the receivers can register with and |
| +// unregister from the router. The router updates the registered receivers with |
| +// new logs. It also stores all logs until the moment when there are no |
| +// registered receivers. On registration, a receiver gets all the currently |
| +// stored logs. |
|
Ilya Sherman
2014/05/02 23:38:38
Is this complexity worth it, vs. just making the i
vabr (Chromium)
2014/05/06 13:16:30
Having the internals page a singleton is only a ha
|
| +// The clients must also register, to be notified about the router toggling its |
| +// activity state. |
| +// TODO(vabr): The receivers are objects of type PasswordManagerLogger. That |
| +// type should be renamed to LogReceiver instead. |
| +class LogRouter { |
| + public: |
| + // Depending on whether the router has any receivers registered or not, it is |
| + // active or not. Logs passed to the router are forwarded during the active |
| + // state, and dropped otherwise. The clients are notified about the state on |
| + // its change, and on registration. |
| + enum RouterActivityState { ROUTER_ACTIVE, ROUTER_NOT_ACTIVE }; |
|
Ilya Sherman
2014/05/02 23:38:38
nit: "NOT_ACTIVE" -> "INACTIVE"
vabr (Chromium)
2014/05/06 13:16:30
Actually, I dropped the enum. Instead of introduci
|
| + |
| + LogRouter(); |
| + virtual ~LogRouter(); |
| + |
| + // Call this to pass logs to the router. The router may display them or drop |
| + // them, based on its activity state. |
| + void ProcessLog(const std::string& text); |
|
Ilya Sherman
2014/05/02 23:38:38
Perhaps it should be an error to call this method
vabr (Chromium)
2014/05/06 13:16:30
I'll give it a try, since I could not actually thi
|
| + |
| + // Registration methods for the PasswordManagerClient and for the receivers to |
| + // call, both return true on success. Register*() fails for already registered |
| + // objects. Unregister*() fails for not registered objects. Never pass a NULL |
| + // pointer to these methods. Every registered client and receiver must |
| + // unregister before being destroyed. |
| + bool RegisterClient(PasswordManagerClient* client); |
|
vabr (Chromium)
2014/05/02 15:33:10
TODO(vabr): Remove the failure reporting via retur
|
| + bool UnregisterClient(PasswordManagerClient* client); |
| + bool RegisterReceiver(PasswordManagerLogger* receiver); |
| + bool UnregisterReceiver(PasswordManagerLogger* receiver); |
| + |
| + private: |
| + typedef std::set<PasswordManagerClient*> ClientSet; |
| + typedef std::set<PasswordManagerLogger*> ReceiverSet; |
|
Ilya Sherman
2014/05/02 23:38:38
nit: Did you consider using an ObserverList?
vabr (Chromium)
2014/05/06 13:16:30
Thanks for pointing me to that.
While I'm not sure
|
| + |
| + // Goes through all of the clients and sends them the current state. |
| + void NotifyClients(RouterActivityState state); |
| + |
| + // Clients send log strings to the router, and are notified by the router when |
| + // logging activity changes. |
| + ClientSet clients_; |
| + |
| + // Receivers receive strings from the router. |
| + ReceiverSet receivers_; |
| + |
| + // Logs seen so far since the last time IsActive() changed from false to true. |
| + std::string accumulated_logs_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LogRouter); |
| +}; |
| + |
| +} // namespace password_manager |
| + |
| +#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ |