OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
17 #include "base/location.h" | 18 #include "base/location.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
21 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
22 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
23 #include "base/sequenced_task_runner.h" | 24 #include "base/sequenced_task_runner.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
26 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
27 #include "base/threading/sequenced_worker_pool.h" | 28 #include "base/threading/sequenced_worker_pool.h" |
28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/cookie_store_factory.h" | 31 #include "content/public/browser/cookie_store_factory.h" |
| 32 #include "content/public/common/content_switches.h" |
31 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
32 #include "net/cookies/canonical_cookie.h" | 34 #include "net/cookies/canonical_cookie.h" |
33 #include "net/cookies/cookie_constants.h" | 35 #include "net/cookies/cookie_constants.h" |
34 #include "net/cookies/cookie_util.h" | 36 #include "net/cookies/cookie_util.h" |
35 #include "sql/error_delegate_util.h" | 37 #include "sql/error_delegate_util.h" |
36 #include "sql/meta_table.h" | 38 #include "sql/meta_table.h" |
37 #include "sql/statement.h" | 39 #include "sql/statement.h" |
38 #include "sql/transaction.h" | 40 #include "sql/transaction.h" |
39 #include "third_party/sqlite/sqlite3.h" | 41 #include "third_party/sqlite/sqlite3.h" |
40 #include "url/gurl.h" | 42 #include "url/gurl.h" |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 1189 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
1188 backend_->Flush(callback); | 1190 backend_->Flush(callback); |
1189 } | 1191 } |
1190 | 1192 |
1191 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 1193 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
1192 backend_->Close(); | 1194 backend_->Close(); |
1193 // We release our reference to the Backend, though it will probably still have | 1195 // We release our reference to the Backend, though it will probably still have |
1194 // a reference if the background runner has not run Close() yet. | 1196 // a reference if the background runner has not run Close() yet. |
1195 } | 1197 } |
1196 | 1198 |
1197 net::CookieStore* CreatePersistentCookieStore( | 1199 CookieStoreConfig::CookieStoreConfig( |
1198 const base::FilePath& path, | 1200 const base::FilePath& path, |
1199 bool restore_old_session_cookies, | 1201 SessionCookieMode session_cookie_mode, |
1200 quota::SpecialStoragePolicy* storage_policy, | 1202 quota::SpecialStoragePolicy* storage_policy, |
1201 net::CookieMonster::Delegate* cookie_monster_delegate) { | 1203 net::CookieMonsterDelegate* cookie_delegate) |
| 1204 : path(path), |
| 1205 session_cookie_mode(session_cookie_mode), |
| 1206 storage_policy(storage_policy), |
| 1207 cookie_delegate(cookie_delegate) { |
| 1208 CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES); |
| 1209 } |
| 1210 |
| 1211 CookieStoreConfig::CookieStoreConfig() |
| 1212 : session_cookie_mode(EPHEMERAL_SESSION_COOKIES) { |
| 1213 // Default to an in-memory cookie store. |
| 1214 } |
| 1215 |
| 1216 CookieStoreConfig::~CookieStoreConfig() { |
| 1217 } |
| 1218 |
| 1219 net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) { |
| 1220 if (config.path.empty()) { |
| 1221 return new net::CookieMonster(NULL, config.cookie_delegate); |
| 1222 } |
| 1223 |
1202 SQLitePersistentCookieStore* persistent_store = | 1224 SQLitePersistentCookieStore* persistent_store = |
1203 new SQLitePersistentCookieStore( | 1225 new SQLitePersistentCookieStore( |
1204 path, | 1226 config.path, |
1205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1227 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1206 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 1228 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
1207 BrowserThread::GetBlockingPool()->GetSequenceToken()), | 1229 BrowserThread::GetBlockingPool()->GetSequenceToken()), |
1208 restore_old_session_cookies, | 1230 (config.session_cookie_mode == |
1209 storage_policy); | 1231 CookieStoreConfig::RESTORED_SESSION_COOKIES), |
| 1232 config.storage_policy); |
1210 net::CookieMonster* cookie_monster = | 1233 net::CookieMonster* cookie_monster = |
1211 new net::CookieMonster(persistent_store, cookie_monster_delegate); | 1234 new net::CookieMonster(persistent_store, config.cookie_delegate); |
| 1235 if ((config.session_cookie_mode == |
| 1236 CookieStoreConfig::PERSISTANT_SESSION_COOKIES) || |
| 1237 (config.session_cookie_mode == |
| 1238 CookieStoreConfig::RESTORED_SESSION_COOKIES)) { |
| 1239 cookie_monster->SetPersistSessionCookies(true); |
| 1240 } |
| 1241 |
| 1242 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1243 switches::kEnableFileCookies)) { |
| 1244 cookie_monster->SetEnableFileScheme(true); |
| 1245 } |
1212 | 1246 |
1213 const std::string cookie_priority_experiment_group = | 1247 const std::string cookie_priority_experiment_group = |
1214 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); | 1248 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); |
1215 cookie_monster->SetPriorityAwareGarbageCollection( | 1249 cookie_monster->SetPriorityAwareGarbageCollection( |
1216 cookie_priority_experiment_group == "ExperimentOn"); | 1250 cookie_priority_experiment_group == "ExperimentOn"); |
1217 | 1251 |
1218 return cookie_monster; | 1252 return cookie_monster; |
1219 } | 1253 } |
1220 | 1254 |
1221 } // namespace content | 1255 } // namespace content |
OLD | NEW |