1 // Copyright (c) 2013 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 
5 #ifndef CONTENT_PUBLIC_BROWSER_COOKIE_STORE_FACTORY_H_
6 #define CONTENT_PUBLIC_BROWSER_COOKIE_STORE_FACTORY_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/common/content_export.h"
15 
16 namespace base {
17 class SequencedTaskRunner;
18 }
19 
20 namespace net {
21 class CookieCryptoDelegate;
22 class CookieStore;
23 class NetLog;
24 }
25 
26 namespace content {
27 
28 struct CONTENT_EXPORT CookieStoreConfig {
29   // Convenience constructor for an in-memory cookie store with no delegate.
30   CookieStoreConfig();
31 
32   // If |path| is empty, then this specifies an in-memory cookie store.
33   // With in-memory cookie stores, |session_cookie_mode| must be
34   // EPHEMERAL_SESSION_COOKIES.
35   //
36   // Note: If |crypto_delegate| is non-nullptr, it must outlive any CookieStores
37   // created using this config.
38   CookieStoreConfig(const base::FilePath& path,
39                     bool restore_old_session_cookies,
40                     bool persist_session_cookies);
41   ~CookieStoreConfig();
42 
43   const base::FilePath path;
44   const bool restore_old_session_cookies;
45   const bool persist_session_cookies;
46 
47   // The following are infrequently used cookie store parameters.
48   // Rather than clutter the constructor API, these are assigned a default
49   // value on CookieStoreConfig construction. Clients should then override
50   // them as necessary.
51 
52   // Used to provide encryption hooks for the cookie store. The
53   // CookieCryptoDelegate must outlive any cookie store created with this
54   // config.
55   net::CookieCryptoDelegate* crypto_delegate;
56 
57   // Callbacks for data load events will be performed on |client_task_runner|.
58   // If nullptr, uses the task runner for BrowserThread::IO.
59   //
60   // Only used for persistent cookie stores.
61   scoped_refptr<base::SequencedTaskRunner> client_task_runner;
62 
63   // All blocking database accesses will be performed on
64   // |background_task_runner|.  If nullptr, uses a SequencedTaskRunner from the
65   // BrowserThread blocking pool.
66   //
67   // Only used for persistent cookie stores.
68   scoped_refptr<base::SequencedTaskRunner> background_task_runner;
69 
70   // If non-empty, overrides the default list of schemes that support cookies.
71   std::vector<std::string> cookieable_schemes;
72 };
73 
74 CONTENT_EXPORT std::unique_ptr<net::CookieStore> CreateCookieStore(
75     const CookieStoreConfig& config,
76     net::NetLog* net_log);
77 
78 }  // namespace content
79 
80 #endif  // CONTENT_PUBLIC_BROWSER_COOKIE_STORE_FACTORY_H_
81