Chromium Code Reviews| Index: chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc |
| diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc |
| index dfd7abbb0ce09b8cd0c2fc0fa3175170da75517d..3de1e72e9ea72d028e1e7f97e2d063cc47986708 100644 |
| --- a/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc |
| +++ b/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc |
| @@ -7,6 +7,7 @@ |
| #include <utility> |
| #include <vector> |
| +#include "base/auto_reset.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -22,7 +23,8 @@ PasswordsPrivateEventRouter::PasswordsPrivateEventRouter( |
| content::BrowserContext* context) |
| : context_(context), |
| event_router_(nullptr), |
| - listening_(false) { |
| + listening_(false), |
| + ignore_updates_(false) { |
| // Register with the event router so we know when renderers are listening to |
| // our events. We first check and see if there *is* an event router, because |
| // some unit tests try to create all context services, but don't initialize |
| @@ -59,7 +61,12 @@ void PasswordsPrivateEventRouter::OnListenerAdded( |
| const EventListenerInfo& details) { |
| // Start listening to change events and propagate the original lists to |
| // listeners. |
| - StartOrStopListeningForChanges(); |
| + { |
| + // Some delegates will immediately update observers. Since we dispatch the |
| + // events again below, we want to ignore this here. |
| + base::AutoReset<bool> ignore_updates(&ignore_updates_, true); |
| + StartOrStopListeningForChanges(); |
|
Devlin
2016/03/25 13:39:48
Flow:
- Starts listening
- Adds self as observer
-
stevenjb
2016/03/29 00:52:37
I'd actually rather fix this separately. I agree t
Devlin
2016/03/29 14:19:26
Unfortunately, the API test fails without this fix
|
| + } |
| SendSavedPasswordListToListeners(); |
| SendPasswordExceptionListToListeners(); |
| } |
| @@ -71,15 +78,14 @@ void PasswordsPrivateEventRouter::OnListenerRemoved( |
| } |
| void PasswordsPrivateEventRouter::OnSavedPasswordsListChanged( |
| - const std::vector<linked_ptr< |
| - api::passwords_private::PasswordUiEntry>>& entries) { |
| + const std::vector<api::passwords_private::PasswordUiEntry>& entries) { |
| cached_saved_password_parameters_ = |
| api::passwords_private::OnSavedPasswordsListChanged::Create(entries); |
| SendSavedPasswordListToListeners(); |
| } |
| void PasswordsPrivateEventRouter::SendSavedPasswordListToListeners() { |
| - if (!cached_saved_password_parameters_.get()) |
| + if (!cached_saved_password_parameters_.get() || ignore_updates_) |
| // If there is nothing to send, return early. |
| return; |
| @@ -99,7 +105,7 @@ void PasswordsPrivateEventRouter::OnPasswordExceptionsListChanged( |
| } |
| void PasswordsPrivateEventRouter::SendPasswordExceptionListToListeners() { |
| - if (!cached_password_exception_parameters_.get()) |
| + if (!cached_password_exception_parameters_.get() || ignore_updates_) |
| // If there is nothing to send, return early. |
| return; |