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

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: Use WeakPtr. 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 scoped_refptr<net::SQLitePersistentCookieStore>& cookie_store,
30 storage::SpecialStoragePolicy* special_storage_policy)
31 : special_storage_policy_(special_storage_policy),
32 persistent_store_(cookie_store) {
33 }
34
35 QuotaPolicyCookieStore::~QuotaPolicyCookieStore() {
36 if (!special_storage_policy_.get() ||
37 !special_storage_policy_->HasSessionOnlyOrigins()) {
38 return;
39 }
40
41 std::list<net::SQLitePersistentCookieStore::CookieOrigin>
42 session_only_cookies;
43 for (const auto& cookie : cookies_per_origin_) {
44 if (cookie.second == 0) {
45 continue;
46 }
47 const GURL url(net::cookie_util::CookieOriginToURL(cookie.first.first,
48 cookie.first.second));
49 if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url))
50 continue;
51
52 session_only_cookies.push_back(cookie.first);
53 }
54
55 persistent_store_->DeleteAllInList(session_only_cookies);
56 }
57
58 void QuotaPolicyCookieStore::Load(const LoadedCallback& loaded_callback) {
59 persistent_store_->Load(
60 base::Bind(&QuotaPolicyCookieStore::OnLoad,
61 AsWeakPtr(),
62 loaded_callback));
63 }
64
65 void QuotaPolicyCookieStore::LoadCookiesForKey(
66 const std::string& key,
67 const LoadedCallback& loaded_callback) {
68 persistent_store_->LoadCookiesForKey(
69 key,
70 base::Bind(&QuotaPolicyCookieStore::OnLoad,
71 AsWeakPtr(),
72 loaded_callback));
73 }
74
75 void QuotaPolicyCookieStore::AddCookie(const net::CanonicalCookie& cc) {
76 net::SQLitePersistentCookieStore::CookieOrigin origin(
77 cc.Domain(), cc.IsSecure());
78 ++cookies_per_origin_[origin];
79 persistent_store_->AddCookie(cc);
80 }
81
82 void QuotaPolicyCookieStore::UpdateCookieAccessTime(
83 const net::CanonicalCookie& cc) {
84 persistent_store_->UpdateCookieAccessTime(cc);
85 }
86
87 void QuotaPolicyCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
88 net::SQLitePersistentCookieStore::CookieOrigin origin(
89 cc.Domain(), cc.IsSecure());
90 DCHECK_GE(cookies_per_origin_[origin], 1U);
91 --cookies_per_origin_[origin];
92 persistent_store_->DeleteCookie(cc);
93 }
94
95 void QuotaPolicyCookieStore::SetForceKeepSessionState() {
96 special_storage_policy_ = nullptr;
97 }
98
99 void QuotaPolicyCookieStore::Flush(const base::Closure& callback) {
100 persistent_store_->Flush(callback);
101 }
102
103 void QuotaPolicyCookieStore::OnLoad(
104 const LoadedCallback& loaded_callback,
105 const std::vector<net::CanonicalCookie*>& cookies) {
106 for (const auto& cookie : cookies) {
107 net::SQLitePersistentCookieStore::CookieOrigin origin(
108 cookie->Domain(), cookie->IsSecure());
109 ++cookies_per_origin_[origin];
110 }
111
112 loaded_callback.Run(cookies);
113 }
114
115 CookieStoreConfig::CookieStoreConfig()
116 : session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
117 crypto_delegate(nullptr) {
118 // Default to an in-memory cookie store.
119 }
120
121 CookieStoreConfig::CookieStoreConfig(
122 const base::FilePath& path,
123 SessionCookieMode session_cookie_mode,
124 storage::SpecialStoragePolicy* storage_policy,
125 net::CookieMonsterDelegate* cookie_delegate)
126 : path(path),
127 session_cookie_mode(session_cookie_mode),
128 storage_policy(storage_policy),
129 cookie_delegate(cookie_delegate),
130 crypto_delegate(nullptr) {
131 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES);
132 }
133
134 CookieStoreConfig::~CookieStoreConfig() {
135 }
136
137 net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) {
138 // TODO(bcwhite): Remove ScopedTracker below once crbug.com/483686 is fixed.
139 tracked_objects::ScopedTracker tracking_profile(
140 FROM_HERE_WITH_EXPLICIT_FUNCTION("483686 content::CreateCookieStore"));
141
142 net::CookieMonster* cookie_monster = nullptr;
143
144 if (config.path.empty()) {
145 // Empty path means in-memory store.
146 cookie_monster = new net::CookieMonster(nullptr,
147 config.cookie_delegate.get());
148 } else {
149 scoped_refptr<base::SequencedTaskRunner> client_task_runner =
150 config.client_task_runner;
151 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
152 config.background_task_runner;
153
154 if (!client_task_runner.get()) {
155 client_task_runner =
156 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
157 }
158
159 if (!background_task_runner.get()) {
160 background_task_runner =
161 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
162 BrowserThread::GetBlockingPool()->GetSequenceToken());
163 }
164
165 scoped_refptr<net::SQLitePersistentCookieStore> sqlite_store(
166 new net::SQLitePersistentCookieStore(
167 config.path,
168 client_task_runner,
169 background_task_runner,
170 (config.session_cookie_mode ==
171 CookieStoreConfig::RESTORED_SESSION_COOKIES),
172 config.crypto_delegate));
173
174 QuotaPolicyCookieStore* persistent_store =
175 new QuotaPolicyCookieStore(
176 sqlite_store.get(),
177 config.storage_policy.get());
178
179 cookie_monster =
180 new net::CookieMonster(persistent_store, config.cookie_delegate.get());
181 if ((config.session_cookie_mode ==
182 CookieStoreConfig::PERSISTANT_SESSION_COOKIES) ||
183 (config.session_cookie_mode ==
184 CookieStoreConfig::RESTORED_SESSION_COOKIES)) {
185 cookie_monster->SetPersistSessionCookies(true);
186 }
187 }
188
189 return cookie_monster;
190 }
191
192 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698