Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Side by Side Diff: content/browser/net/quota_policy_cookie_store.cc

Issue 1016643004: Moves SQLitePersistentCookieStore to net/extras/sqlite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookies
Patch Set: Better timestamp fix. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "content/browser/net/quota_policy_cookie_store.h"
6
7 #include <list>
8
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/profiler/scoped_tracker.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/cookie_store_factory.h"
19 #include "net/cookies/canonical_cookie.h"
20 #include "net/cookies/cookie_constants.h"
21 #include "net/cookies/cookie_util.h"
22 #include "net/extras/sqlite/cookie_crypto_delegate.h"
23 #include "storage/browser/quota/special_storage_policy.h"
24 #include "url/gurl.h"
25
26 namespace content {
27
28 QuotaPolicyCookieStore::QuotaPolicyCookieStore(
29 const base::FilePath& path,
30 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
31 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
32 bool restore_old_session_cookies,
33 storage::SpecialStoragePolicy* special_storage_policy,
34 net::CookieCryptoDelegate* crypto_delegate)
35 : special_storage_policy_(special_storage_policy),
36 persistent_store_(
37 new net::SQLitePersistentCookieStore(path,
38 client_task_runner,
39 background_task_runner,
40 restore_old_session_cookies,
41 crypto_delegate)) {
Ryan Sleevi 2015/05/06 00:44:18 DESIGN: Does it make more sense to have the caller
rohitrao (ping after 24h) 2015/05/11 19:25:29 Makes sense, changed the API.
42 DCHECK(client_task_runner);
43 DCHECK(background_task_runner);
Ryan Sleevi 2015/05/06 00:44:18 These aren't needed here, are they? They're invari
rohitrao (ping after 24h) 2015/05/11 19:25:29 Obsolete now.
44 }
45
46 QuotaPolicyCookieStore::~QuotaPolicyCookieStore() {
47 if (!special_storage_policy_.get() ||
48 !special_storage_policy_->HasSessionOnlyOrigins()) {
49 return;
50 }
51
52 std::list<net::SQLitePersistentCookieStore::CookieOrigin>
53 session_only_cookies;
54 for (const auto& cookie : cookies_per_origin_) {
55 if (cookie.second <= 0) {
56 DCHECK_EQ(0, cookie.second);
57 continue;
58 }
Ryan Sleevi 2015/05/06 00:44:17 Wat? It seems like "<0" is an impossible conditio
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done. I added a new DCHECK to DeleteCookie() to c
59 const GURL url(net::cookie_util::CookieOriginToURL(cookie.first.first,
60 cookie.first.second));
61 if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url))
62 continue;
63
64 session_only_cookies.push_back(cookie.first);
65 }
66
67 persistent_store_->DeleteAllInList(session_only_cookies);
68 }
69
70 void QuotaPolicyCookieStore::Load(const LoadedCallback& loaded_callback) {
71 persistent_store_->Load(
72 base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
Ryan Sleevi 2015/05/06 00:44:18 DESIGN: It does strike me that this may be potenti
rohitrao (ping after 24h) 2015/05/11 19:25:29 Isn't the caller making lifetime assumptions that
Ryan Sleevi 2015/05/12 00:48:33 What lifetime assumptions do you see it making? I
73 }
74
75 void QuotaPolicyCookieStore::LoadCookiesForKey(
76 const std::string& key,
77 const LoadedCallback& loaded_callback) {
78 persistent_store_->LoadCookiesForKey(
79 key,
80 base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
81 }
82
83 void QuotaPolicyCookieStore::AddCookie(const net::CanonicalCookie& cc) {
84 cookies_per_origin_[
85 net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
86 cc.IsSecure())]++;
Ryan Sleevi 2015/05/06 00:44:17 This is valid, but pretty unreadable. net::SQLite
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
87 persistent_store_->AddCookie(cc);
88 }
89
90 void QuotaPolicyCookieStore::UpdateCookieAccessTime(
91 const net::CanonicalCookie& cc) {
92 persistent_store_->UpdateCookieAccessTime(cc);
93 }
94
95 void QuotaPolicyCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
96 cookies_per_origin_[
97 net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
98 cc.IsSecure())]--;
Ryan Sleevi 2015/05/06 00:44:18 ditto here
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done.
99 persistent_store_->DeleteCookie(cc);
100 }
101
102 void QuotaPolicyCookieStore::SetForceKeepSessionState() {
103 special_storage_policy_ = NULL;
Ryan Sleevi 2015/05/06 00:44:18 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
104 }
105
106 void QuotaPolicyCookieStore::Flush(const base::Closure& callback) {
107 persistent_store_->Flush(callback);
108 }
109
110 void QuotaPolicyCookieStore::OnLoad(
111 const LoadedCallback& loaded_callback,
112 const std::vector<net::CanonicalCookie*>& cookies) {
113 for (const auto& cookie : cookies) {
114 cookies_per_origin_[
115 net::SQLitePersistentCookieStore::CookieOrigin(cookie->Domain(),
116 cookie->IsSecure())]++;
117 }
118
119 loaded_callback.Run(cookies);
120 }
121
122 CookieStoreConfig::CookieStoreConfig()
Ryan Sleevi 2015/05/06 00:44:18 It seems everything from here & below isn't define
rohitrao (ping after 24h) 2015/05/11 19:25:30 This is copied straight from the old content/net/b
Ryan Sleevi 2015/05/12 00:48:33 Yeah, I think splitting it up sounds right, but ha
123 : session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
124 crypto_delegate(NULL) {
Ryan Sleevi 2015/05/06 00:44:18 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
125 // Default to an in-memory cookie store.
126 }
127
128 CookieStoreConfig::CookieStoreConfig(
129 const base::FilePath& path,
130 SessionCookieMode session_cookie_mode,
131 storage::SpecialStoragePolicy* storage_policy,
132 net::CookieMonsterDelegate* cookie_delegate)
133 : path(path),
134 session_cookie_mode(session_cookie_mode),
135 storage_policy(storage_policy),
136 cookie_delegate(cookie_delegate),
137 crypto_delegate(NULL) {
Ryan Sleevi 2015/05/06 00:44:17 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
138 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES);
139 }
140
141 CookieStoreConfig::~CookieStoreConfig() {
142 }
143
144 net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) {
145 // TODO(bcwhite): Remove ScopedTracker below once crbug.com/483686 is fixed.
146 tracked_objects::ScopedTracker tracking_profile(
147 FROM_HERE_WITH_EXPLICIT_FUNCTION("483686 content::CreateCookieStore"));
148
149 net::CookieMonster* cookie_monster = NULL;
Ryan Sleevi 2015/05/06 00:44:17 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done.
150
151 if (config.path.empty()) {
152 // Empty path means in-memory store.
153 cookie_monster = new net::CookieMonster(NULL, config.cookie_delegate.get());
154 } else {
155 scoped_refptr<base::SequencedTaskRunner> client_task_runner =
156 config.client_task_runner;
157 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
158 config.background_task_runner;
159
160 if (!client_task_runner.get()) {
161 client_task_runner =
162 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
163 }
164
165 if (!background_task_runner.get()) {
166 background_task_runner =
167 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
168 BrowserThread::GetBlockingPool()->GetSequenceToken());
169 }
170
171 QuotaPolicyCookieStore* persistent_store =
172 new QuotaPolicyCookieStore(
173 config.path,
174 client_task_runner,
175 background_task_runner,
176 (config.session_cookie_mode ==
177 CookieStoreConfig::RESTORED_SESSION_COOKIES),
Ryan Sleevi 2015/05/06 00:44:17 Is this all formatted with git cl format?
rohitrao (ping after 24h) 2015/05/11 19:25:30 Not yet. I figured we would just take the git cl
178 config.storage_policy.get(),
179 config.crypto_delegate);
180
181 cookie_monster =
182 new net::CookieMonster(persistent_store, config.cookie_delegate.get());
183 if ((config.session_cookie_mode ==
184 CookieStoreConfig::PERSISTANT_SESSION_COOKIES) ||
185 (config.session_cookie_mode ==
186 CookieStoreConfig::RESTORED_SESSION_COOKIES)) {
187 cookie_monster->SetPersistSessionCookies(true);
188 }
189 }
190
191 return cookie_monster;
192 }
193
194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698