cookie_change_notifier.h 1.6 KB

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