cookie_change_notifier.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "net/cookies/cookie_change_dispatcher.h"
  11. #include "services/network/public/mojom/cookie_manager.mojom.h"
  12. namespace electron {
  13. class ElectronBrowserContext;
  14. // Sends cookie-change notifications on the UI thread.
  15. class CookieChangeNotifier : public network::mojom::CookieChangeListener {
  16. public:
  17. explicit CookieChangeNotifier(ElectronBrowserContext* browser_context);
  18. ~CookieChangeNotifier() override;
  19. // Register callbacks that needs to notified on any cookie store changes.
  20. std::unique_ptr<base::CallbackList<
  21. void(const net::CookieChangeInfo& change)>::Subscription>
  22. RegisterCookieChangeCallback(
  23. const base::Callback<void(const net::CookieChangeInfo& change)>& 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::CallbackList<void(const net::CookieChangeInfo& change)>
  31. cookie_change_sub_list_;
  32. mojo::Receiver<network::mojom::CookieChangeListener> receiver_;
  33. DISALLOW_COPY_AND_ASSIGN(CookieChangeNotifier);
  34. };
  35. } // namespace electron
  36. #endif // SHELL_BROWSER_COOKIE_CHANGE_NOTIFIER_H_