cookie_change_notifier.h 1.6 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 ELECTRON_SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
  5. #define ELECTRON_SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
  6. #include "base/callback_list.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "mojo/public/cpp/bindings/receiver.h"
  9. #include "net/cookies/cookie_change_dispatcher.h"
  10. #include "services/network/public/mojom/cookie_manager.mojom.h"
  11. namespace electron {
  12. class ElectronBrowserContext;
  13. // Sends cookie-change notifications on the UI thread.
  14. class CookieChangeNotifier : public network::mojom::CookieChangeListener {
  15. public:
  16. explicit CookieChangeNotifier(ElectronBrowserContext* browser_context);
  17. ~CookieChangeNotifier() override;
  18. // disable copy
  19. CookieChangeNotifier(const CookieChangeNotifier&) = delete;
  20. CookieChangeNotifier& operator=(const CookieChangeNotifier&) = delete;
  21. // Register callbacks that needs to notified on any cookie store changes.
  22. base::CallbackListSubscription RegisterCookieChangeCallback(
  23. const base::RepeatingCallback<void(const net::CookieChangeInfo& change)>&
  24. cb);
  25. private:
  26. void StartListening();
  27. void OnConnectionError();
  28. // network::mojom::CookieChangeListener implementation.
  29. void OnCookieChange(const net::CookieChangeInfo& change) override;
  30. raw_ptr<ElectronBrowserContext> browser_context_;
  31. base::RepeatingCallbackList<void(const net::CookieChangeInfo& change)>
  32. cookie_change_sub_list_;
  33. mojo::Receiver<network::mojom::CookieChangeListener> receiver_;
  34. };
  35. } // namespace electron
  36. #endif // ELECTRON_SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_