• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/common/content_export.h"
11 
12 namespace base {
13 class SequencedTaskRunner;
14 }
15 
16 namespace net {
17 class CookieMonsterDelegate;
18 class CookieStore;
19 }
20 
21 namespace quota {
22 class SpecialStoragePolicy;
23 }
24 
25 namespace content {
26 class CookieCryptoDelegate;
27 
28 struct CONTENT_EXPORT CookieStoreConfig {
29   // Specifies how session cookies are persisted in the backing data store.
30   //
31   // EPHEMERAL_SESSION_COOKIES specifies session cookies will not be written
32   // out in a manner that allows for restoration.
33   //
34   // PERSISTANT_SESSION_COOKIES specifies that session cookies are not restored
35   // when the cookie store is opened, however they will be written in a manner
36   // that allows for them to be restored if the cookie store is opened again
37   // using RESTORED_SESSION_COOKIES.
38   //
39   // RESTORED_SESSION_COOKIES is the: same as PERSISTANT_SESSION_COOKIES
40   // except when the cookie store is opened, the previously written session
41   // cookies are loaded first.
42   enum SessionCookieMode {
43     EPHEMERAL_SESSION_COOKIES,
44     PERSISTANT_SESSION_COOKIES,
45     RESTORED_SESSION_COOKIES
46   };
47 
48   // Convenience constructor for an in-memory cookie store with no delegate.
49   CookieStoreConfig();
50 
51   // If |path| is empty, then this specifies an in-memory cookie store.
52   // With in-memory cookie stores, |session_cookie_mode| must be
53   // EPHEMERAL_SESSION_COOKIES.
54   //
55   // Note: If |crypto_delegate| is non-NULL, it must outlive any CookieStores
56   // created using this config.
57   CookieStoreConfig(const base::FilePath& path,
58                     SessionCookieMode session_cookie_mode,
59                     quota::SpecialStoragePolicy* storage_policy,
60                     net::CookieMonsterDelegate* cookie_delegate);
61   ~CookieStoreConfig();
62 
63   const base::FilePath path;
64   const SessionCookieMode session_cookie_mode;
65   const scoped_refptr<quota::SpecialStoragePolicy> storage_policy;
66   const scoped_refptr<net::CookieMonsterDelegate> cookie_delegate;
67 
68   // The following are infrequently used cookie store parameters.
69   // Rather than clutter the constructor API, these are assigned a default
70   // value on CookieStoreConfig construction. Clients should then override
71   // them as necessary.
72 
73   // Used to provide encryption hooks for the cookie store. The
74   // CookieCryptoDelegate must outlive any cookie store created with this
75   // config.
76   content::CookieCryptoDelegate* crypto_delegate;
77 
78   // Callbacks for data load events will be performed on |client_task_runner|.
79   // If NULL, uses the task runner for BrowserThread::IO.
80   //
81   // Only used for persistent cookie stores.
82   scoped_refptr<base::SequencedTaskRunner> client_task_runner;
83 
84   // All blocking database accesses will be performed on
85   // |background_task_runner|.  If NULL, uses a SequencedTaskRunner from the
86   // BrowserThread blocking pool.
87   //
88   // Only used for persistent cookie stores.
89   scoped_refptr<base::SequencedTaskRunner> background_task_runner;
90 };
91 
92 CONTENT_EXPORT net::CookieStore* CreateCookieStore(
93     const CookieStoreConfig& config);
94 
95 }  // namespace content
96 
97 #endif  // CONTENT_PUBLIC_BROWSER_COOKIE_STORE_FACTORY_H_
98