[go: nahoru, domu]

blob: e46463cea196ccff4bd1df1b599e92da21443827 [file] [log] [blame]
Avi Drissman64595482022-09-14 20:52:291// Copyright 2012 The Chromium Authors
rohitrao1860223c2015-05-16 01:07:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_
6#define NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_
7
8#include <list>
9#include <string>
10#include <utility>
11#include <vector>
12
Francois Doray45bdc4c32018-09-17 19:35:0013#include "base/component_export.h"
Avi Drissman41c4a412023-01-11 22:45:3714#include "base/functional/callback_forward.h"
Lei Zhang58a10822022-11-08 04:23:2015#include "base/memory/scoped_refptr.h"
Etienne Pierre-Doray87bb331b2018-09-18 17:27:1216#include "base/task/task_traits.h"
rohitrao1860223c2015-05-16 01:07:1417#include "net/cookies/cookie_monster.h"
Will Harris75362d72024-01-12 19:14:1618#include "net/extras/sqlite/cookie_crypto_delegate.h"
Helen Li92a29f102018-08-15 23:02:2619#include "net/log/net_log_with_source.h"
rohitrao1860223c2015-05-16 01:07:1420
rohitrao1860223c2015-05-16 01:07:1421namespace base {
22class FilePath;
23class SequencedTaskRunner;
24} // namespace base
25
26namespace net {
27class CanonicalCookie;
rohitrao1860223c2015-05-16 01:07:1428
Etienne Pierre-Doray87bb331b2018-09-18 17:27:1229// Returns recommended task priority for |background_task_runner|.
30base::TaskPriority COMPONENT_EXPORT(NET_EXTRAS)
31 GetCookieStoreBackgroundSequencePriority();
32
rohitrao1860223c2015-05-16 01:07:1433// Implements the PersistentCookieStore interface in terms of a SQLite database.
34// For documentation about the actual member functions consult the documentation
35// of the parent class |CookieMonster::PersistentCookieStore|.
Francois Doray45bdc4c32018-09-17 19:35:0036class COMPONENT_EXPORT(NET_EXTRAS) SQLitePersistentCookieStore
rohitrao1860223c2015-05-16 01:07:1437 : public CookieMonster::PersistentCookieStore {
38 public:
39 // Contains the origin and a bool indicating whether or not the
40 // origin is secure.
41 typedef std::pair<std::string, bool> CookieOrigin;
42
Dylan Cutlerc880aeb2021-09-15 20:35:2743 // Port number to use for cookies whose source port is unknown at the time of
44 // database migration to V13. The value -1 comes from url::PORT_UNSPECIFIED.
Peter Kastinga622c5f2023-10-17 00:00:5545 static constexpr int kDefaultUnknownPort = -1;
Dylan Cutlerc880aeb2021-09-15 20:35:2746
rohitrao1860223c2015-05-16 01:07:1447 // All blocking database accesses will be performed on
48 // |background_task_runner|, while |client_task_runner| is used to invoke
Will Harris711a5ec2023-04-04 21:43:3749 // callbacks. If |enable_exclusive_access| is set to true then sqlite will
50 // be asked to open the database with flag `exclusive=1`. In practice, this is
51 // only respected on Windows.
rohitrao1860223c2015-05-16 01:07:1452 SQLitePersistentCookieStore(
53 const base::FilePath& path,
54 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
55 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
56 bool restore_old_session_cookies,
Will Harris75362d72024-01-12 19:14:1657 std::unique_ptr<CookieCryptoDelegate> crypto_delegate,
Will Harris711a5ec2023-04-04 21:43:3758 bool enable_exclusive_access);
rohitrao1860223c2015-05-16 01:07:1459
Peter Boström407869b2021-10-07 04:42:4860 SQLitePersistentCookieStore(const SQLitePersistentCookieStore&) = delete;
61 SQLitePersistentCookieStore& operator=(const SQLitePersistentCookieStore&) =
62 delete;
63
rohitrao1860223c2015-05-16 01:07:1464 // Deletes the cookies whose origins match those given in |cookies|.
65 void DeleteAllInList(const std::list<CookieOrigin>& cookies);
66
rohitrao1860223c2015-05-16 01:07:1467 // CookieMonster::PersistentCookieStore:
Maks Orlovich108cb4c2019-03-26 20:24:5768 void Load(LoadedCallback loaded_callback,
Helen Li92a29f102018-08-15 23:02:2669 const NetLogWithSource& net_log) override;
rohitrao1860223c2015-05-16 01:07:1470 void LoadCookiesForKey(const std::string& key,
Maks Orlovich108cb4c2019-03-26 20:24:5771 LoadedCallback callback) override;
rohitrao1860223c2015-05-16 01:07:1472 void AddCookie(const CanonicalCookie& cc) override;
73 void UpdateCookieAccessTime(const CanonicalCookie& cc) override;
74 void DeleteCookie(const CanonicalCookie& cc) override;
75 void SetForceKeepSessionState() override;
Lily Chen9934f7e2019-03-13 19:16:5576 void SetBeforeCommitCallback(base::RepeatingClosure callback) override;
rdsmith7ac81712017-06-22 17:09:5477 void Flush(base::OnceClosure callback) override;
rohitrao1860223c2015-05-16 01:07:1478
Maks Orlovich1a9ffad82018-09-14 23:05:5379 // Returns how many operations are currently queued. For test use only;
80 // and the background thread needs to be wedged for accessing this to be
81 // non-racey. Also requires the client thread to be current.
82 size_t GetQueueLengthForTesting();
83
rohitrao1860223c2015-05-16 01:07:1484 private:
85 ~SQLitePersistentCookieStore() override;
Maks Orlovich108cb4c2019-03-26 20:24:5786 void CompleteLoad(LoadedCallback callback,
Helen Li92a29f102018-08-15 23:02:2687 std::vector<std::unique_ptr<CanonicalCookie>> cookie_list);
88 void CompleteKeyedLoad(
89 const std::string& key,
Maks Orlovich108cb4c2019-03-26 20:24:5790 LoadedCallback callback,
Helen Li92a29f102018-08-15 23:02:2691 std::vector<std::unique_ptr<CanonicalCookie>> cookie_list);
rohitrao1860223c2015-05-16 01:07:1492
93 class Backend;
94
Helen Liedd838a2018-08-14 23:27:2995 const scoped_refptr<Backend> backend_;
Helen Li92a29f102018-08-15 23:02:2696 NetLogWithSource net_log_;
rohitrao1860223c2015-05-16 01:07:1497};
98
99} // namespace net
100
101#endif // NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_