cookie_change_notifier.h 1.5 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 ATOM_BROWSER_COOKIE_CHANGE_NOTIFIER_H_
  5. #define ATOM_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/binding.h"
  10. #include "services/network/public/mojom/cookie_manager.mojom.h"
  11. namespace atom {
  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::Binding<network::mojom::CookieChangeListener> binding_;
  32. DISALLOW_COPY_AND_ASSIGN(CookieChangeNotifier);
  33. };
  34. } // namespace atom
  35. #endif // ATOM_BROWSER_COOKIE_CHANGE_NOTIFIER_H_