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" | |
16 #include "base/file_util.h" | 15 #include "base/file_util.h" |
17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
18 #include "base/location.h" | 17 #include "base/location.h" |
19 #include "base/logging.h" | 18 #include "base/logging.h" |
20 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
22 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
23 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
24 #include "base/sequenced_task_runner.h" | 23 #include "base/sequenced_task_runner.h" |
25 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
27 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
28 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
29 #include "base/time/time.h" | 28 #include "base/time/time.h" |
30 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/cookie_store_factory.h" | 30 #include "content/public/browser/cookie_store_factory.h" |
32 #include "content/public/common/content_switches.h" | |
33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 31 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
34 #include "net/cookies/canonical_cookie.h" | 32 #include "net/cookies/canonical_cookie.h" |
35 #include "net/cookies/cookie_constants.h" | 33 #include "net/cookies/cookie_constants.h" |
36 #include "net/cookies/cookie_util.h" | 34 #include "net/cookies/cookie_util.h" |
37 #include "sql/error_delegate_util.h" | 35 #include "sql/error_delegate_util.h" |
38 #include "sql/meta_table.h" | 36 #include "sql/meta_table.h" |
39 #include "sql/statement.h" | 37 #include "sql/statement.h" |
40 #include "sql/transaction.h" | 38 #include "sql/transaction.h" |
41 #include "third_party/sqlite/sqlite3.h" | 39 #include "third_party/sqlite/sqlite3.h" |
42 #include "url/gurl.h" | 40 #include "url/gurl.h" |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 1187 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
1190 backend_->Flush(callback); | 1188 backend_->Flush(callback); |
1191 } | 1189 } |
1192 | 1190 |
1193 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 1191 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
1194 backend_->Close(); | 1192 backend_->Close(); |
1195 // We release our reference to the Backend, though it will probably still have | 1193 // We release our reference to the Backend, though it will probably still have |
1196 // a reference if the background runner has not run Close() yet. | 1194 // a reference if the background runner has not run Close() yet. |
1197 } | 1195 } |
1198 | 1196 |
1199 CookieStoreConfig::CookieStoreConfig( | 1197 net::CookieStore* CreatePersistentCookieStore( |
1200 const base::FilePath& path, | 1198 const base::FilePath& path, |
1201 SessionCookieMode session_cookie_mode, | 1199 bool restore_old_session_cookies, |
1202 quota::SpecialStoragePolicy* storage_policy, | 1200 quota::SpecialStoragePolicy* storage_policy, |
1203 net::CookieMonsterDelegate* cookie_delegate) | 1201 net::CookieMonster::Delegate* cookie_monster_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 | |
1224 SQLitePersistentCookieStore* persistent_store = | 1202 SQLitePersistentCookieStore* persistent_store = |
1225 new SQLitePersistentCookieStore( | 1203 new SQLitePersistentCookieStore( |
1226 config.path, | 1204 path, |
1227 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1228 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 1206 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
1229 BrowserThread::GetBlockingPool()->GetSequenceToken()), | 1207 BrowserThread::GetBlockingPool()->GetSequenceToken()), |
1230 (config.session_cookie_mode == | 1208 restore_old_session_cookies, |
1231 CookieStoreConfig::RESTORED_SESSION_COOKIES), | 1209 storage_policy); |
1232 config.storage_policy); | |
1233 net::CookieMonster* cookie_monster = | 1210 net::CookieMonster* cookie_monster = |
1234 new net::CookieMonster(persistent_store, config.cookie_delegate); | 1211 new net::CookieMonster(persistent_store, cookie_monster_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 } | |
1246 | 1212 |
1247 const std::string cookie_priority_experiment_group = | 1213 const std::string cookie_priority_experiment_group = |
1248 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); | 1214 base::FieldTrialList::FindFullName("CookieRetentionPriorityStudy"); |
1249 cookie_monster->SetPriorityAwareGarbageCollection( | 1215 cookie_monster->SetPriorityAwareGarbageCollection( |
1250 cookie_priority_experiment_group == "ExperimentOn"); | 1216 cookie_priority_experiment_group == "ExperimentOn"); |
1251 | 1217 |
1252 return cookie_monster; | 1218 return cookie_monster; |
1253 } | 1219 } |
1254 | 1220 |
1255 } // namespace content | 1221 } // namespace content |
OLD | NEW |