cookie_manager_impl.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef FUCHSIA_WEB_WEBENGINE_BROWSER_COOKIE_MANAGER_IMPL_H_
  5. #define FUCHSIA_WEB_WEBENGINE_BROWSER_COOKIE_MANAGER_IMPL_H_
  6. #include <fuchsia/web/cpp/fidl.h>
  7. #include "base/callback.h"
  8. #include "fuchsia_web/webengine/web_engine_export.h"
  9. #include "mojo/public/cpp/bindings/remote.h"
  10. #include "services/network/public/mojom/cookie_manager.mojom.h"
  11. namespace network {
  12. namespace mojom {
  13. class NetworkContext;
  14. } // namespace mojom
  15. } // namespace network
  16. class WEB_ENGINE_EXPORT CookieManagerImpl final
  17. : public fuchsia::web::CookieManager {
  18. public:
  19. // Used to request the BrowserContext's CookieManager. Since the
  20. // NetworkContext may change, e.g. if the NetworkService crashes, the returned
  21. // pointer will be used immediately, and not cached by the CookieManagerImpl.
  22. using GetNetworkContextCallback =
  23. base::RepeatingCallback<network::mojom::NetworkContext*()>;
  24. // |get_network_context| will be called to (re)connect to CookieManager,
  25. // on-demand, in response to query/observation requests.
  26. explicit CookieManagerImpl(GetNetworkContextCallback get_network_context);
  27. CookieManagerImpl(const CookieManagerImpl&) = delete;
  28. CookieManagerImpl& operator=(const CookieManagerImpl&) = delete;
  29. ~CookieManagerImpl() override;
  30. // fuchsia::web::CookieManager implementation:
  31. void ObserveCookieChanges(
  32. fidl::StringPtr url,
  33. fidl::StringPtr name,
  34. fidl::InterfaceRequest<fuchsia::web::CookiesIterator> changes) override;
  35. void GetCookieList(
  36. fidl::StringPtr url,
  37. fidl::StringPtr name,
  38. fidl::InterfaceRequest<fuchsia::web::CookiesIterator> cookies) override;
  39. // Used by tests to monitor for the Mojo CookieManager disconnecting
  40. void set_on_mojo_disconnected_for_test(base::OnceClosure on_disconnected) {
  41. on_mojo_disconnected_for_test_ = std::move(on_disconnected);
  42. }
  43. private:
  44. // (Re)connects |cookie_manager_| if not currently connected.
  45. void EnsureCookieManager();
  46. // Handles errors on the |cookie_manager_| Mojo channel.
  47. void OnMojoDisconnect();
  48. const GetNetworkContextCallback get_network_context_;
  49. mojo::Remote<network::mojom::CookieManager> cookie_manager_;
  50. base::OnceClosure on_mojo_disconnected_for_test_;
  51. };
  52. #endif // FUCHSIA_WEB_WEBENGINE_BROWSER_COOKIE_MANAGER_IMPL_H_