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 #include "base/observer_list.h" | |
13 | |
14 namespace password_manager { | |
15 | |
16 class PasswordManagerClient; | |
17 class PasswordManagerLogger; | |
18 | |
19 // The router stands between PasswordManagerClient instances and log receivers. | |
20 // During the process of saving a password, the password manager code generates | |
21 // the log strings, and passes them to the router. The router distributes the | |
22 // logs to the receivers for displaying. | |
23 // TODO(vabr): The receivers are objects of type PasswordManagerLogger. That | |
24 // type should be renamed to LogReceiver instead. | |
25 class LogRouter { | |
26 public: | |
27 LogRouter(); | |
28 virtual ~LogRouter(); | |
29 | |
30 // Passes logs to the router. Only call when there are receivers registered. | |
31 void ProcessLog(const std::string& text); | |
32 | |
33 // All four (Unr|R)egister* methods below are safe to call from the | |
34 // constructor of the registered object, because they do not call that object, | |
35 // and the router only runs on a single thread. | |
36 | |
37 // The clients must register to be notified about whether there are some | |
38 // receivers or not. RegisterClient adds |client| to the right observer list | |
39 // and returns true iff there are some receivers registered. | |
40 bool RegisterClient(PasswordManagerClient* client); | |
41 // Remove |client| from the observers list. | |
42 void UnregisterClient(PasswordManagerClient* client); | |
43 | |
44 // The receivers must register to get updates with new logs in the future. | |
45 // RegisterReceiver adds |receiver| to the right observer list, and returns | |
46 // the logs accumulated so far. (It returns by value, not const ref, to | |
47 // provide a snapshot as opposed to a link to |accumulated_logs_|.) | |
48 std::string RegisterReceiver(PasswordManagerLogger* receiver); | |
49 // Remove |receiver| from the observers list. | |
50 void UnregisterReceiver(PasswordManagerLogger* receiver); | |
51 | |
52 private: | |
53 // Observer lists for clients and receivers. The |true| in the template | |
54 // specialisation means that they will check that all observers were removed | |
55 // on destruction. | |
56 ObserverList<PasswordManagerClient, true> clients_; | |
57 ObserverList<PasswordManagerLogger, true> receivers_; | |
58 | |
59 // Logs seen so far since the first receiver was registered. | |
Ilya Sherman
2014/05/07 00:28:39
nit: "seen so far since" -> "accumulated since"
vabr (Chromium)
2014/05/07 13:42:59
Done.
| |
60 std::string accumulated_logs_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(LogRouter); | |
63 }; | |
64 | |
65 } // namespace password_manager | |
66 | |
67 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOG_ROUTER_H_ | |
OLD | NEW |