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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "components/password_manager/core/browser/log_router.h"
6
7 #include "base/stl_util.h"
8 #include "components/password_manager/core/browser/password_manager_client.h"
9 #include "components/password_manager/core/browser/password_manager_logger.h"
10
11 namespace password_manager {
12
13 LogRouter::LogRouter() {
14 }
15
16 LogRouter::~LogRouter() {
17 }
18
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 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
23 accumulated_logs_.append(text);
24 FOR_EACH_OBSERVER(
25 PasswordManagerLogger, receivers_, LogSavePasswordProgress(text));
26 }
27
28 bool LogRouter::RegisterClient(PasswordManagerClient* client) {
29 DCHECK(client);
30 clients_.AddObserver(client);
31 return receivers_.might_have_observers();
32 }
33
34 void LogRouter::UnregisterClient(PasswordManagerClient* client) {
35 DCHECK(client);
36 clients_.RemoveObserver(client);
37 }
38
39 std::string LogRouter::RegisterReceiver(PasswordManagerLogger* receiver) {
40 DCHECK(receiver);
41 DCHECK(accumulated_logs_.empty() || receivers_.might_have_observers());
42
43 // TODO(vabr): Once the clients provide API for that, notify them if the
44 // number of receivers went from 0 to 1.
45 receivers_.AddObserver(receiver);
46 return accumulated_logs_;
47 }
48
49 void LogRouter::UnregisterReceiver(PasswordManagerLogger* receiver) {
50 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.
51 receivers_.RemoveObserver(receiver);
52 if (!receivers_.might_have_observers()) {
53 accumulated_logs_.clear();
54 // TODO(vabr): Once the clients provide API for that, notify them that the
55 // number of receivers went from 1 to 0.
56 }
57 }
58
59 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698