cookie_change_notifier.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
  5. #define SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
  6. #include <memory>
  7. #include "base/callback_list.h"
  8. #include "base/macros.h"
  9. #include "mojo/public/cpp/bindings/receiver.h"
  10. #include "services/network/public/mojom/cookie_manager.mojom.h"
  11. namespace electron {
  12. class AtomBrowserContext;
  13. struct CookieDetails;
  14. // Sends cookie-change notifications on the UI thread.
  15. class CookieChangeNotifier : public network::mojom::CookieChangeListener {
  16. public:
  17. explicit CookieChangeNotifier(AtomBrowserContext* browser_context);
  18. ~CookieChangeNotifier() override;
  19. // Register callbacks that needs to notified on any cookie store changes.
  20. std::unique_ptr<base::CallbackList<void(const CookieDetails*)>::Subscription>
  21. RegisterCookieChangeCallback(
  22. const base::Callback<void(const CookieDetails*)>& cb);
  23. private:
  24. void StartListening();
  25. void OnConnectionError();
  26. // network::mojom::CookieChangeListener implementation.
  27. void OnCookieChange(const net::CanonicalCookie& cookie,
  28. network::mojom::CookieChangeCause cause) override;
  29. AtomBrowserContext* browser_context_;
  30. base::CallbackList<void(const CookieDetails*)> cookie_change_sub_list_;
  31. mojo::Receiver<network::mojom::CookieChangeListener> receiver_;
  32. DISALLOW_COPY_AND_ASSIGN(CookieChangeNotifier);
  33. };
  34. } // namespace electron
  35. #endif // SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_