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

Unified Diff: chrome/browser/extensions/api/passwords_private/passwords_private_event_router.cc

Issue 1857513002: Update code so 1:1 relation between delegate and router is more clear. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a8c0952668a84a306d01de00cc1202f1fbd2c68c..6c01b2f3211ab5ed100ed587b0d8fc431a8f4321 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
@@ -12,6 +12,7 @@
#include "base/bind_helpers.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/passwords_private.h"
@@ -22,9 +23,7 @@ namespace extensions {
PasswordsPrivateEventRouter::PasswordsPrivateEventRouter(
content::BrowserContext* context)
: context_(context),
- event_router_(nullptr),
- listening_(false),
- ignore_updates_(false) {
+ event_router_(nullptr) {
// 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
@@ -49,33 +48,16 @@ PasswordsPrivateEventRouter::~PasswordsPrivateEventRouter() {}
void PasswordsPrivateEventRouter::Shutdown() {
if (event_router_)
event_router_->UnregisterObserver(this);
-
- PasswordsPrivateDelegate* delegate =
- PasswordsPrivateDelegateFactory::GetForBrowserContext(context_,
- false /* create */);
- if (delegate)
- delegate->RemoveObserver(this);
}
void PasswordsPrivateEventRouter::OnListenerAdded(
const EventListenerInfo& details) {
- // Start listening to change events and propagate the original lists to
- // listeners.
- {
- // Some delegates will immediately update observers. Since we dispatch the
- // events again below, we want to ignore this here.
- // TODO(stevenjb): Fix this. crbug.com/598826.
- base::AutoReset<bool> ignore_updates(&ignore_updates_, true);
- StartOrStopListeningForChanges();
+ PasswordsPrivateDelegate* delegate =
+ PasswordsPrivateDelegateFactory::GetForBrowserContext(context_, true);
+ if (delegate) {
+ delegate->SendSavedPasswordsList();
+ delegate->SendPasswordExceptionsList();
}
- SendSavedPasswordListToListeners();
- SendPasswordExceptionListToListeners();
-}
-
-void PasswordsPrivateEventRouter::OnListenerRemoved(
- const EventListenerInfo& details) {
- // Stop listening to events if there are no more listeners.
- StartOrStopListeningForChanges();
}
void PasswordsPrivateEventRouter::OnSavedPasswordsListChanged(
@@ -86,7 +68,7 @@ void PasswordsPrivateEventRouter::OnSavedPasswordsListChanged(
}
void PasswordsPrivateEventRouter::SendSavedPasswordListToListeners() {
- if (!cached_saved_password_parameters_.get() || ignore_updates_)
+ if (!cached_saved_password_parameters_.get())
// If there is nothing to send, return early.
return;
@@ -106,7 +88,7 @@ void PasswordsPrivateEventRouter::OnPasswordExceptionsListChanged(
}
void PasswordsPrivateEventRouter::SendPasswordExceptionListToListeners() {
- if (!cached_password_exception_parameters_.get() || ignore_updates_)
+ if (!cached_password_exception_parameters_.get())
// If there is nothing to send, return early.
return;
@@ -136,31 +118,6 @@ void PasswordsPrivateEventRouter::OnPlaintextPasswordFetched(
event_router_->BroadcastEvent(std::move(extension_event));
}
-void PasswordsPrivateEventRouter::StartOrStopListeningForChanges() {
- bool should_listen_for_saved_password_changes =
- event_router_->HasEventListener(
- api::passwords_private::OnSavedPasswordsListChanged::kEventName);
- bool should_listen_for_password_exception_changes =
- event_router_->HasEventListener(
- api::passwords_private::OnPasswordExceptionsListChanged::kEventName);
- bool should_listen_for_plaintext_password_retrieval =
- event_router_->HasEventListener(
- api::passwords_private::OnPlaintextPasswordRetrieved::kEventName);
- bool should_listen = should_listen_for_saved_password_changes ||
- should_listen_for_password_exception_changes ||
- should_listen_for_plaintext_password_retrieval;
-
- PasswordsPrivateDelegate* delegate =
- PasswordsPrivateDelegateFactory::GetForBrowserContext(context_,
- true /* create */);
- if (should_listen && !listening_)
- delegate->AddObserver(this);
- else if (!should_listen && listening_)
- delegate->RemoveObserver(this);
-
- listening_ = should_listen;
-}
-
PasswordsPrivateEventRouter* PasswordsPrivateEventRouter::Create(
content::BrowserContext* context) {
return new PasswordsPrivateEventRouter(context);
« no previous file with comments | « chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698