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

Side by Side Diff: components/password_manager/core/browser/log_router.cc

Issue 269513003: Password manager internals page service: wiring it in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Just rebased 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/core/browser/log_router.h" 5 #include "components/password_manager/core/browser/log_router.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "components/password_manager/core/browser/password_manager_client.h" 8 #include "components/password_manager/core/browser/password_manager_client.h"
9 #include "components/password_manager/core/browser/password_manager_logger.h" 9 #include "components/password_manager/core/browser/password_manager_logger.h"
10 10
11 #if !defined(NDEBUG)
12 #include "base/memory/scoped_ptr.h"
13 #endif
14
11 namespace password_manager { 15 namespace password_manager {
12 16
17 namespace {
18
19 #if !defined(NDEBUG)
20 // Built to the image of base::DefaultDeleter, TrueSetter sets a bool* pointer's
21 // target to true, rather than deleting it.
22 struct TrueSetter {
23 inline void operator()(bool* ptr) const { *ptr = true; }
24 };
25 #endif
26
27 } // namespace
28
13 LogRouter::LogRouter() { 29 LogRouter::LogRouter() {
30 #if !defined(NDEBUG)
31 can_use_receivers_ = true;
32 #endif
14 } 33 }
15 34
16 LogRouter::~LogRouter() { 35 LogRouter::~LogRouter() {
17 } 36 }
18 37
19 void LogRouter::ProcessLog(const std::string& text) { 38 void LogRouter::ProcessLog(const std::string& text) {
20 // This may not be called when there are no receivers (i.e., the router is 39 // 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. 40 // inactive), because in that case the logs cannot be displayed.
22 DCHECK(receivers_.might_have_observers()); 41 DCHECK(receivers_.might_have_observers());
23 accumulated_logs_.append(text); 42 accumulated_logs_.append(text);
43 DCHECK(can_use_receivers_);
Ilya Sherman 2014/05/13 04:32:18 Hmm, this seems like a lot of work just for the sa
vabr (Chromium) 2014/05/13 09:27:11 Done. I agree. I double-checked that the current c
24 FOR_EACH_OBSERVER( 44 FOR_EACH_OBSERVER(
25 PasswordManagerLogger, receivers_, LogSavePasswordProgress(text)); 45 PasswordManagerLogger, receivers_, LogSavePasswordProgress(text));
26 } 46 }
27 47
28 bool LogRouter::RegisterClient(PasswordManagerClient* client) { 48 bool LogRouter::RegisterClient(PasswordManagerClient* client) {
29 DCHECK(client); 49 DCHECK(client);
30 clients_.AddObserver(client); 50 clients_.AddObserver(client);
31 return receivers_.might_have_observers(); 51 return receivers_.might_have_observers();
32 } 52 }
33 53
34 void LogRouter::UnregisterClient(PasswordManagerClient* client) { 54 void LogRouter::UnregisterClient(PasswordManagerClient* client) {
35 DCHECK(clients_.HasObserver(client)); 55 DCHECK(clients_.HasObserver(client));
36 clients_.RemoveObserver(client); 56 clients_.RemoveObserver(client);
37 } 57 }
38 58
39 std::string LogRouter::RegisterReceiver(PasswordManagerLogger* receiver) { 59 std::string LogRouter::RegisterReceiver(PasswordManagerLogger* receiver) {
40 DCHECK(receiver); 60 DCHECK(receiver);
41 DCHECK(accumulated_logs_.empty() || receivers_.might_have_observers()); 61 DCHECK(accumulated_logs_.empty() || receivers_.might_have_observers());
62 #if !defined(NDEBUG)
63 // Make sure the receivers are not dereferenced until we return. This might
64 // get called from the constructor of |receiver|.
65 DCHECK(can_use_receivers_);
66 can_use_receivers_ = false;
67 scoped_ptr<bool, TrueSetter> lock(&can_use_receivers_);
68 #endif
42 69
43 // TODO(vabr): Once the clients provide API for that, notify them if the 70 if (!receivers_.might_have_observers()) {
44 // number of receivers went from 0 to 1. 71 FOR_EACH_OBSERVER(
72 PasswordManagerClient, clients_, NotifyCanUseLogRouter(true));
73 }
45 receivers_.AddObserver(receiver); 74 receivers_.AddObserver(receiver);
46 return accumulated_logs_; 75 return accumulated_logs_;
47 } 76 }
48 77
49 void LogRouter::UnregisterReceiver(PasswordManagerLogger* receiver) { 78 void LogRouter::UnregisterReceiver(PasswordManagerLogger* receiver) {
50 DCHECK(receivers_.HasObserver(receiver)); 79 DCHECK(receivers_.HasObserver(receiver));
51 receivers_.RemoveObserver(receiver); 80 receivers_.RemoveObserver(receiver);
52 if (!receivers_.might_have_observers()) { 81 if (!receivers_.might_have_observers()) {
53 accumulated_logs_.clear(); 82 accumulated_logs_.clear();
54 // TODO(vabr): Once the clients provide API for that, notify them that the 83 FOR_EACH_OBSERVER(
55 // number of receivers went from 1 to 0. 84 PasswordManagerClient, clients_, NotifyCanUseLogRouter(false));
56 } 85 }
57 } 86 }
58 87
59 } // namespace password_manager 88 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698