1// Copyright (c) 2012 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// A sqlite implementation of a cookie monster persistent store.
6
7#ifndef CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_
8#define CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_
9
10#include <string>
11#include <vector>
12
13#include "base/callback_forward.h"
14#include "base/compiler_specific.h"
15#include "base/memory/ref_counted.h"
16#include "content/common/content_export.h"
17#include "net/cookies/cookie_monster.h"
18
19class Task;
20
21namespace base {
22class FilePath;
23class SequencedTaskRunner;
24}
25
26namespace net {
27class CanonicalCookie;
28}
29
30namespace quota {
31class SpecialStoragePolicy;
32}
33
34namespace content {
35
36// Implements the PersistentCookieStore interface in terms of a SQLite database.
37// For documentation about the actual member functions consult the documentation
38// of the parent class |net::CookieMonster::PersistentCookieStore|.
39// If provided, a |SpecialStoragePolicy| is consulted when the SQLite database
40// is closed to decide which cookies to keep.
41class CONTENT_EXPORT SQLitePersistentCookieStore
42    : public net::CookieMonster::PersistentCookieStore {
43 public:
44  // All blocking database accesses will be performed on
45  // |background_task_runner|, while |client_task_runner| is used to invoke
46  // callbacks.
47  SQLitePersistentCookieStore(
48      const base::FilePath& path,
49      const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
50      const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
51      bool restore_old_session_cookies,
52      quota::SpecialStoragePolicy* special_storage_policy);
53
54  // net::CookieMonster::PersistentCookieStore:
55  virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE;
56  virtual void LoadCookiesForKey(const std::string& key,
57      const LoadedCallback& callback) OVERRIDE;
58  virtual void AddCookie(const net::CanonicalCookie& cc) OVERRIDE;
59  virtual void UpdateCookieAccessTime(const net::CanonicalCookie& cc) OVERRIDE;
60  virtual void DeleteCookie(const net::CanonicalCookie& cc) OVERRIDE;
61  virtual void SetForceKeepSessionState() OVERRIDE;
62  virtual void Flush(const base::Closure& callback) OVERRIDE;
63
64 protected:
65   virtual ~SQLitePersistentCookieStore();
66
67 private:
68  class Backend;
69
70  scoped_refptr<Backend> backend_;
71
72  DISALLOW_COPY_AND_ASSIGN(SQLitePersistentCookieStore);
73};
74
75}  // namespace content
76
77#endif  // CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_
78