Chromium Code Reviews| 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 #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 } | |
|
Ilya Sherman
2014/05/02 23:38:38
nit: DCHECK that all listeners have unregistered?
vabr (Chromium)
2014/05/06 13:16:30
Done via using ObserverList with the right templat
| |
| 18 | |
| 19 void LogRouter::ProcessLog(const std::string& text) { | |
| 20 if (!receivers_.empty()) { | |
| 21 accumulated_logs_.append(text); | |
| 22 for (ReceiverSet::iterator receiver = receivers_.begin(); | |
| 23 receiver != receivers_.end(); | |
| 24 ++receiver) { | |
| 25 (*receiver)->LogSavePasswordProgress(text); | |
| 26 } | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 bool LogRouter::RegisterClient(PasswordManagerClient* client) { | |
| 31 DCHECK(client); | |
| 32 if (ContainsKey(clients_, client)) | |
| 33 return false; | |
|
Ilya Sherman
2014/05/02 23:38:38
Can this be a DCHECK instead?
vabr (Chromium)
2014/05/06 13:16:30
Done via ObserverList.
| |
| 34 clients_.insert(client); | |
| 35 // TODO(vabr): notify |client| about the activity state. | |
| 36 return true; | |
| 37 } | |
| 38 | |
| 39 bool LogRouter::UnregisterClient(PasswordManagerClient* client) { | |
| 40 DCHECK(client); | |
| 41 ClientSet::iterator it = clients_.find(client); | |
| 42 if (it == clients_.end()) | |
| 43 return false; | |
|
Ilya Sherman
2014/05/02 23:38:38
Can this be a DCHECK instead?
vabr (Chromium)
2014/05/06 13:16:30
Switched to ObserverList, which actually does not
| |
| 44 clients_.erase(it); | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 bool LogRouter::RegisterReceiver(PasswordManagerLogger* receiver) { | |
| 49 DCHECK(receiver); | |
| 50 DCHECK(accumulated_logs_.empty() || !receivers_.empty()); | |
| 51 | |
| 52 if (ContainsKey(receivers_, receiver)) | |
| 53 return false; | |
|
Ilya Sherman
2014/05/02 23:38:38
Can this be a DCHECK instead?
vabr (Chromium)
2014/05/06 13:16:30
Done via ObserverList.
| |
| 54 if (receivers_.empty()) | |
| 55 NotifyClients(ROUTER_ACTIVE); | |
| 56 receivers_.insert(receiver); | |
| 57 if (!accumulated_logs_.empty()) | |
| 58 receiver->LogSavePasswordProgress(accumulated_logs_); | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 bool LogRouter::UnregisterReceiver(PasswordManagerLogger* receiver) { | |
| 63 DCHECK(receiver); | |
| 64 ReceiverSet::iterator it = receivers_.find(receiver); | |
| 65 if (it == receivers_.end()) | |
| 66 return false; | |
|
Ilya Sherman
2014/05/02 23:38:38
Can this be a DCHECK instead?
vabr (Chromium)
2014/05/06 13:16:30
Dropped. The same as in my response in UnregisterC
| |
| 67 receivers_.erase(it); | |
| 68 if (receivers_.empty()) { | |
| 69 accumulated_logs_.clear(); | |
| 70 NotifyClients(ROUTER_NOT_ACTIVE); | |
| 71 } | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 void LogRouter::NotifyClients(RouterActivityState state) { | |
| 76 for (ClientSet::iterator client = clients_.begin(); client != clients_.end(); | |
| 77 ++client) { | |
| 78 // TODO(vabr): Pass |state| to |client|. | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 } // namespace password_manager | |
| OLD | NEW |