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

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

Issue 1142693003: Implement the chrome.passwordsPrivate API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h
diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h b/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h
new file mode 100644
index 0000000000000000000000000000000000000000..74022a8a587bf33a36d2480b51127a963b573671
--- /dev/null
+++ b/chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h
@@ -0,0 +1,71 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_PASSWORDS_PRIVATE_PASSWORDS_PRIVATE_EVENT_ROUTER_H_
+#define CHROME_BROWSER_EXTENSIONS_API_PASSWORDS_PRIVATE_PASSWORDS_PRIVATE_EVENT_ROUTER_H_
+
+#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "extensions/browser/event_router.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace extensions {
+
+// An event router that observes changes to saved passwords and password
+// exceptions and notifies listeners to the onSavedPasswordsListChanged and
+// onPasswordExceptionsListChanged events of changes.
+class PasswordsPrivateEventRouter :
+ public KeyedService,
+ public EventRouter::Observer,
+ public PasswordsPrivateDelegate::Observer {
+ public:
+ static PasswordsPrivateEventRouter* Create(
+ content::BrowserContext* browser_context);
+ ~PasswordsPrivateEventRouter() override;
+
+ protected:
+ explicit PasswordsPrivateEventRouter(content::BrowserContext* context);
+
+ // KeyedService overrides:
+ void Shutdown() override;
+
+ // EventRouter::Observer overrides:
+ void OnListenerAdded(const EventListenerInfo& details) override;
+ void OnListenerRemoved(const EventListenerInfo& details) override;
+
+ // PasswordsPrivateDelegate::Observer overrides:
+ void OnSavedPasswordsListChanged(const std::vector<linked_ptr<
+ api::passwords_private::PasswordUiEntry>>& entries) override;
+ void OnPasswordExceptionsListChanged(
+ const std::vector<std::string>& exceptions) override;
+
+ private:
+ // Either listens or unlistens for changes to TODO!!!!!, depending on
+ // whether clients are listening to the passwordsPrivate API events.
+ void StartOrStopListeningForChanges();
+
+ void SendSavedPasswordListToListeners();
+ void SendPasswordExceptionListToListeners();
+
+ content::BrowserContext* context_;
+
+ EventRouter* event_router_;
+
+ // Cached parameters which are saved so that when new listeners are added, the
+ // most up-to-date lists can be sent to them immediately.
+ scoped_ptr<base::ListValue> cached_saved_password_parameters_;
+ scoped_ptr<base::ListValue> cached_password_exception_parameters_;
+
+ // Whether this class is currently listening for changes to |TODO!!!!!|.
+ bool listening_;
+
+ DISALLOW_COPY_AND_ASSIGN(PasswordsPrivateEventRouter);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_PASSWORDS_PRIVATE_PASSWORDS_PRIVATE_EVENT_ROUTER_H_

Powered by Google App Engine
This is Rietveld 408576698