OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ | |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ | |
7 | |
8 #include <set> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | |
12 | |
13 namespace password_manager { | |
14 | |
15 class PasswordManagerClient; | |
16 class PasswordManagerLogger; | |
17 | |
18 // The router stands between PasswordManagerClient instances and log receivers. | |
19 // During the process of saving a password, the password manager code generates | |
20 // the log strings, and passes them to the router. The receivers are capable of | |
21 // actually displaying them to the user; the receivers can register with and | |
22 // unregister from the router. The router updates the registered receivers with | |
23 // new logs. It also stores all logs until the moment when there are no | |
24 // registered receivers. On registration, a receiver gets all the currently | |
25 // 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
| |
26 // The clients must also register, to be notified about the router toggling its | |
27 // activity state. | |
28 // TODO(vabr): The receivers are objects of type PasswordManagerLogger. That | |
29 // type should be renamed to LogReceiver instead. | |
30 class LogRouter { | |
31 public: | |
32 // Depending on whether the router has any receivers registered or not, it is | |
33 // active or not. Logs passed to the router are forwarded during the active | |
34 // state, and dropped otherwise. The clients are notified about the state on | |
35 // its change, and on registration. | |
36 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
| |
37 | |
38 LogRouter(); | |
39 virtual ~LogRouter(); | |
40 | |
41 // Call this to pass logs to the router. The router may display them or drop | |
42 // them, based on its activity state. | |
43 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
| |
44 | |
45 // Registration methods for the PasswordManagerClient and for the receivers to | |
46 // call, both return true on success. Register*() fails for already registered | |
47 // objects. Unregister*() fails for not registered objects. Never pass a NULL | |
48 // pointer to these methods. Every registered client and receiver must | |
49 // unregister before being destroyed. | |
50 bool RegisterClient(PasswordManagerClient* client); | |
vabr (Chromium)
2014/05/02 15:33:10
TODO(vabr): Remove the failure reporting via retur
| |
51 bool UnregisterClient(PasswordManagerClient* client); | |
52 bool RegisterReceiver(PasswordManagerLogger* receiver); | |
53 bool UnregisterReceiver(PasswordManagerLogger* receiver); | |
54 | |
55 private: | |
56 typedef std::set<PasswordManagerClient*> ClientSet; | |
57 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
| |
58 | |
59 // Goes through all of the clients and sends them the current state. | |
60 void NotifyClients(RouterActivityState state); | |
61 | |
62 // Clients send log strings to the router, and are notified by the router when | |
63 // logging activity changes. | |
64 ClientSet clients_; | |
65 | |
66 // Receivers receive strings from the router. | |
67 ReceiverSet receivers_; | |
68 | |
69 // Logs seen so far since the last time IsActive() changed from false to true. | |
70 std::string accumulated_logs_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(LogRouter); | |
73 }; | |
74 | |
75 } // namespace password_manager | |
76 | |
77 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ | |
OLD | NEW |