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

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: Rebased. Created 5 years, 8 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 (c) 2015 The Chromium Authors. All rights reserved.
mef 2015/04/06 21:00:27 nit: loose (c)
rohitrao (ping after 24h) 2015/04/07 14:43:47 Done.
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 "content/public/browser/browser_thread.h"
17 #include "content/public/browser/cookie_store_factory.h"
18 #include "net/cookies/canonical_cookie.h"
19 #include "net/cookies/cookie_constants.h"
20 #include "net/cookies/cookie_util.h"
21 #include "net/extras/sqlite/cookie_crypto_delegate.h"
22 #include "storage/browser/quota/special_storage_policy.h"
23 #include "url/gurl.h"
24
25 namespace content {
26
27 QuotaPolicyCookieStore::QuotaPolicyCookieStore(
28 const base::FilePath& path,
29 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
30 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
31 bool restore_old_session_cookies,
32 storage::SpecialStoragePolicy* special_storage_policy,
33 net::CookieCryptoDelegate* crypto_delegate)
34 : special_storage_policy_(special_storage_policy),
35 persistent_store_(
36 new net::SQLitePersistentCookieStore(path,
37 client_task_runner,
38 background_task_runner,
39 restore_old_session_cookies,
40 crypto_delegate)) {
41 DCHECK(client_task_runner);
42 DCHECK(background_task_runner);
43 }
44
45 QuotaPolicyCookieStore::~QuotaPolicyCookieStore() {
46 if (!special_storage_policy_.get() ||
47 !special_storage_policy_->HasSessionOnlyOrigins()) {
48 return;
49 }
50
51 std::list<net::SQLitePersistentCookieStore::CookieOrigin>
52 session_only_cookies;
53 for (const auto& cookie : cookies_per_origin_) {
54 if (cookie.second <= 0) {
55 DCHECK_EQ(0, cookie.second);
56 continue;
57 }
58 const GURL url(net::cookie_util::CookieOriginToURL(cookie.first.first,
59 cookie.first.second));
60 if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url))
61 continue;
62
63 session_only_cookies.push_back(cookie.first);
64 }
65
66 persistent_store_->DeleteAllInList(session_only_cookies);
67 }
68
69 void QuotaPolicyCookieStore::Load(const LoadedCallback& loaded_callback) {
70 persistent_store_->Load(
71 base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
72 }
73
74 void QuotaPolicyCookieStore::LoadCookiesForKey(
75 const std::string& key,
76 const LoadedCallback& loaded_callback) {
77 persistent_store_->LoadCookiesForKey(
78 key,
79 base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
80 }
81
82 void QuotaPolicyCookieStore::AddCookie(const net::CanonicalCookie& cc) {
83 cookies_per_origin_[
84 net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
85 cc.IsSecure())]++;
86 persistent_store_->AddCookie(cc);
87 }
88
89 void QuotaPolicyCookieStore::UpdateCookieAccessTime(
90 const net::CanonicalCookie& cc) {
91 persistent_store_->UpdateCookieAccessTime(cc);
92 }
93
94 void QuotaPolicyCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
95 cookies_per_origin_[
96 net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
97 cc.IsSecure())]--;
98 persistent_store_->DeleteCookie(cc);
99 }
100
101 void QuotaPolicyCookieStore::SetForceKeepSessionState() {
102 special_storage_policy_ = NULL;
103 }
104
105 void QuotaPolicyCookieStore::Flush(const base::Closure& callback) {
106 persistent_store_->Flush(callback);
107 }
108
109 void QuotaPolicyCookieStore::OnLoad(
110 const LoadedCallback& loaded_callback,
111 const std::vector<net::CanonicalCookie*>& cookies) {
112 for (const auto& cookie : cookies) {
113 cookies_per_origin_[
114 net::SQLitePersistentCookieStore::CookieOrigin(cookie->Domain(),
115 cookie->IsSecure())]++;
116 }
117
118 loaded_callback.Run(cookies);
119 }
120
121 CookieStoreConfig::CookieStoreConfig()
122 : session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
123 crypto_delegate(NULL) {
124 // Default to an in-memory cookie store.
125 }
126
127 CookieStoreConfig::CookieStoreConfig(
128 const base::FilePath& path,
129 SessionCookieMode session_cookie_mode,
130 storage::SpecialStoragePolicy* storage_policy,
131 net::CookieMonsterDelegate* cookie_delegate)
132 : path(path),
133 session_cookie_mode(session_cookie_mode),
134 storage_policy(storage_policy),
135 cookie_delegate(cookie_delegate),
136 crypto_delegate(NULL) {
137 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES);
138 }
139
140 CookieStoreConfig::~CookieStoreConfig() {
141 }
142
143 net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) {
144 net::CookieMonster* cookie_monster = NULL;
145
146 if (config.path.empty()) {
147 // Empty path means in-memory store.
148 cookie_monster = new net::CookieMonster(NULL, config.cookie_delegate.get());
149 } else {
150 scoped_refptr<base::SequencedTaskRunner> client_task_runner =
151 config.client_task_runner;
152 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
153 config.background_task_runner;
154
155 if (!client_task_runner.get()) {
156 client_task_runner =
157 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
158 }
159
160 if (!background_task_runner.get()) {
161 background_task_runner =
162 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
163 BrowserThread::GetBlockingPool()->GetSequenceToken());
164 }
165
166 QuotaPolicyCookieStore* persistent_store =
167 new QuotaPolicyCookieStore(
168 config.path,
169 client_task_runner,
170 background_task_runner,
171 (config.session_cookie_mode ==
172 CookieStoreConfig::RESTORED_SESSION_COOKIES),
173 config.storage_policy.get(),
174 config.crypto_delegate);
175
176 cookie_monster =
177 new net::CookieMonster(persistent_store, config.cookie_delegate.get());
178 if ((config.session_cookie_mode ==
179 CookieStoreConfig::PERSISTANT_SESSION_COOKIES) ||
180 (config.session_cookie_mode ==
181 CookieStoreConfig::RESTORED_SESSION_COOKIES)) {
182 cookie_monster->SetPersistSessionCookies(true);
183 }
184 }
185
186 return cookie_monster;
187 }
188
189 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698