cookie_manager.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2020 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 WEBLAYER_PUBLIC_COOKIE_MANAGER_H_
  5. #define WEBLAYER_PUBLIC_COOKIE_MANAGER_H_
  6. #include <string>
  7. #include "base/callback_list.h"
  8. class GURL;
  9. namespace net {
  10. struct CookieChangeInfo;
  11. }
  12. namespace weblayer {
  13. class CookieManager {
  14. public:
  15. virtual ~CookieManager() = default;
  16. // Sets a cookie for the given URL.
  17. using SetCookieCallback = base::OnceCallback<void(bool)>;
  18. virtual void SetCookie(const GURL& url,
  19. const std::string& value,
  20. SetCookieCallback callback) = 0;
  21. // Gets the cookies for the given URL.
  22. using GetCookieCallback = base::OnceCallback<void(const std::string&)>;
  23. virtual void GetCookie(const GURL& url, GetCookieCallback callback) = 0;
  24. // Gets the cookies for the given URL in the form of the 'Set-Cookie' HTTP
  25. // response header.
  26. using GetResponseCookiesCallback =
  27. base::OnceCallback<void(const std::vector<std::string>&)>;
  28. virtual void GetResponseCookies(const GURL& url,
  29. GetResponseCookiesCallback callback) = 0;
  30. // Adds a callback to listen for changes to cookies for the given URL.
  31. using CookieChangedCallbackList =
  32. base::RepeatingCallbackList<void(const net::CookieChangeInfo&)>;
  33. using CookieChangedCallback = CookieChangedCallbackList::CallbackType;
  34. virtual base::CallbackListSubscription AddCookieChangedCallback(
  35. const GURL& url,
  36. const std::string* name,
  37. CookieChangedCallback callback) = 0;
  38. };
  39. } // namespace weblayer
  40. #endif // WEBLAYER_PUBLIC_COOKIE_MANAGER_H_