• 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   // Called on the UI thread after object creation and before any other object
21   // methods are executed on the UI thread.
22   void Initialize(CefBrowserContext::Getter browser_context_getter,
23                   CefRefPtr<CefCompletionCallback> callback);
24 
25   // CefCookieManager methods.
26   bool VisitAllCookies(CefRefPtr<CefCookieVisitor> visitor) override;
27   bool VisitUrlCookies(const CefString& url,
28                        bool includeHttpOnly,
29                        CefRefPtr<CefCookieVisitor> visitor) override;
30   bool SetCookie(const CefString& url,
31                  const CefCookie& cookie,
32                  CefRefPtr<CefSetCookieCallback> callback) override;
33   bool DeleteCookies(const CefString& url,
34                      const CefString& cookie_name,
35                      CefRefPtr<CefDeleteCookiesCallback> callback) override;
36   bool FlushStore(CefRefPtr<CefCompletionCallback> callback) override;
37 
38  private:
39   bool VisitAllCookiesInternal(CefRefPtr<CefCookieVisitor> visitor);
40   bool VisitUrlCookiesInternal(const GURL& url,
41                                bool includeHttpOnly,
42                                CefRefPtr<CefCookieVisitor> visitor);
43   bool SetCookieInternal(const GURL& url,
44                          const CefCookie& cookie,
45                          CefRefPtr<CefSetCookieCallback> callback);
46   bool DeleteCookiesInternal(const GURL& url,
47                              const CefString& cookie_name,
48                              CefRefPtr<CefDeleteCookiesCallback> callback);
49   bool FlushStoreInternal(CefRefPtr<CefCompletionCallback> callback);
50 
51   // If the context is fully initialized execute |callback|, otherwise
52   // store it until the context is fully initialized.
53   void StoreOrTriggerInitCallback(base::OnceClosure callback);
54 
55   bool ValidContext() const;
56 
57   // Only accessed on the UI thread. Will be non-null after Initialize().
58   CefBrowserContext::Getter browser_context_getter_;
59 
60   bool initialized_ = false;
61   std::vector<base::OnceClosure> init_callbacks_;
62 
63   IMPLEMENT_REFCOUNTING(CefCookieManagerImpl);
64   DISALLOW_COPY_AND_ASSIGN(CefCookieManagerImpl);
65 };
66 
67 #endif  // CEF_LIBCEF_BROWSER_NET_SERVICE_COOKIE_MANAGER_IMPL_H_
68