• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_
6 #define CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_
7 
8 #include "include/cef_cookie.h"
9 #include "libcef/browser/browser_context.h"
10 #include "libcef/browser/thread_util.h"
11 
12 #include "base/files/file_path.h"
13 
14 // Implementation of the CefCookieManager interface. May be created on any
15 // thread.
16 class CefCookieManagerImpl : public CefCookieManager {
17  public:
18   CefCookieManagerImpl();
19 
20   CefCookieManagerImpl(const CefCookieManagerImpl&) = delete;
21   CefCookieManagerImpl& operator=(const CefCookieManagerImpl&) = delete;
22 
23   // Called on the UI thread after object creation and before any other object
24   // methods are executed on the UI thread.
25   void Initialize(CefBrowserContext::Getter browser_context_getter,
26                   CefRefPtr<CefCompletionCallback> callback);
27 
28   // CefCookieManager methods.
29   bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) override;
30   bool VisitUrlCookies(const CefString& url,
31                        bool includeHttpOnly,
32                        CefRefPtr<CefCookieVisitor> visitor) override;
33   bool SetCookie(const CefString& url,
34                  const CefCookie& cookie,
35                  CefRefPtr<CefSetCookieCallback> callback) override;
36   bool DeleteCookies(const CefString& url,
37                      const CefString& cookie_name,
38                      CefRefPtr<CefDeleteCookiesCallback> callback) override;
39   bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
40 
41  private:
42   bool VisitAllCookiesInternal(CefRefPtr<CefCookieVisitor> visitor);
43   bool VisitUrlCookiesInternal(const GURL& url,
44                                bool includeHttpOnly,
45                                CefRefPtr<CefCookieVisitor> visitor);
46   bool SetCookieInternal(const GURL& url,
47                          const CefCookie& cookie,
48                          CefRefPtr<CefSetCookieCallback> callback);
49   bool DeleteCookiesInternal(const GURL& url,
50                              const CefString& cookie_name,
51                              CefRefPtr<CefDeleteCookiesCallback> callback);
52   bool FlushStoreInternal(CefRefPtr<CefCompletionCallback> callback);
53 
54   // If the context is fully initialized execute |callback|, otherwise
55   // store it until the context is fully initialized.
56   void StoreOrTriggerInitCallback(base::OnceClosure callback);
57 
58   bool ValidContext() const;
59 
60   // Only accessed on the UI thread. Will be non-null after Initialize().
61   CefBrowserContext::Getter browser_context_getter_;
62 
63   bool initialized_ = false;
64   std::vector<base::OnceClosure> init_callbacks_;
65 
66   IMPLEMENT_REFCOUNTING(CefCookieManagerImpl);
67 };
68 
69 #endif  // CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_
70