cookie_change_notifier.h 1.7 KB

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