| 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( |
| 1200 bool in_memory, |
| 1198 const base::FilePath& path, | 1201 const base::FilePath& path, |
| 1199 bool restore_old_session_cookies, | 1202 SessionCookieMode session_cookie_mode, |
| 1200 quota::SpecialStoragePolicy* storage_policy, | 1203 quota::SpecialStoragePolicy* storage_policy, |
| 1201 net::CookieMonster::Delegate* cookie_monster_delegate) { | 1204 net::CookieMonsterDelegate* cookie_delegate) |
| 1205 : in_memory(in_memory), |
| 1206 path(path), |
| 1207 session_cookie_mode(session_cookie_mode), |
| 1208 storage_policy(storage_policy), |
| 1209 cookie_delegate(cookie_delegate) { |
| 1210 } |
| 1211 |
| 1212 CookieStoreConfig::~CookieStoreConfig() { |
| 1213 } |
| 1214 |
| 1215 CookieStoreConfig CookieStoreConfig::InMemory() { |
| 1216 return CookieStoreConfig(true, base::FilePath(), EPHEMERAL_SESSION_COOKIES, |
| 1217 NULL, NULL); |
| 1218 } |
| 1219 |
| 1220 CookieStoreConfig CookieStoreConfig::InMemoryWithOptions( |
| 1221 quota::SpecialStoragePolicy* storage_policy, |
| 1222 net::CookieMonsterDelegate* cookie_delegate) { |
| 1223 return CookieStoreConfig(true, base::FilePath(), |
| 1224 EPHEMERAL_SESSION_COOKIES, storage_policy, |
| 1225 cookie_delegate); |
| 1226 } |
| 1227 |
| 1228 CookieStoreConfig CookieStoreConfig::Persistent( |
| 1229 const base::FilePath& path, |
| 1230 SessionCookieMode session_cookie_mode) { |
| 1231 return CookieStoreConfig(false, path, session_cookie_mode, NULL, NULL); |
| 1232 } |
| 1233 |
| 1234 CookieStoreConfig CookieStoreConfig::PersistentWithOptions( |
| 1235 const base::FilePath& path, |
| 1236 SessionCookieMode restore_old_session_cookies, |
| 1237 quota::SpecialStoragePolicy* storage_policy, |
| 1238 net::CookieMonsterDelegate* cookie_delegate) { |
| 1239 return CookieStoreConfig(false, path, restore_old_session_cookies, |
| 1240 storage_policy, cookie_delegate); |
| 1241 } |
| 1242 |
| 1243 net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) { |
| 1244 if (config.in_memory) { |
| 1245 return new net::CookieMonster(NULL, config.cookie_delegate); |
| 1246 } |
| 1247 |
| 1202 SQLitePersistentCookieStore* persistent_store = | 1248 SQLitePersistentCookieStore* persistent_store = |
| 1203 new SQLitePersistentCookieStore( | 1249 new SQLitePersistentCookieStore( |
| 1204 path, | 1250 config.path, |
| 1205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1251 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 1206 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 1252 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 1207 BrowserThread::GetBlockingPool()->GetSequenceToken()), | 1253 BrowserThread::GetBlockingPool()->GetSequenceToken()), |
| 1208 restore_old_session_cookies, | 1254 (config.session_cookie_mode == |
| 1209 storage_policy); | 1255 CookieStoreConfig::RESTORED_SESSION_COOKIES), |
| 1256 config.storage_policy); |
| 1210 net::CookieMonster* cookie_monster = | 1257 net::CookieMonster* cookie_monster = |
| 1211 new net::CookieMonster(persistent_store, cookie_monster_delegate); | 1258 new net::CookieMonster(persistent_store, config.cookie_delegate); |
| 1259 if ((config.session_cookie_mode == |
| 1260 CookieStoreConfig::PERSISTANT_SESSION_COOKIES) || |
| 1261 (config.session_cookie_mode == |
| 1262 CookieStoreConfig::RESTORED_SESSION_COOKIES)) { |
| 1263 cookie_monster->SetPersistSessionCookies(true); |
| 1264 } |
| 1265 |
| 1266 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1267 switches::kEnableFileCookies)) { |
| 1268 cookie_monster->SetEnableFileScheme(true); |
| 1269 } |
| 1212 | 1270 |
| 1213 const std::string cookie_priority_experiment_group = | 1271 const std::string cookie_priority_experiment_group = |
| 1214 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); | 1272 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); |
| 1215 cookie_monster->SetPriorityAwareGarbageCollection( | 1273 cookie_monster->SetPriorityAwareGarbageCollection( |
| 1216 cookie_priority_experiment_group == "ExperimentOn"); | 1274 cookie_priority_experiment_group == "ExperimentOn"); |
| 1217 | 1275 |
| 1218 return cookie_monster; | 1276 return cookie_monster; |
| 1219 } | 1277 } |
| 1220 | 1278 |
| 1221 } // namespace content | 1279 } // namespace content |
| OLD | NEW |