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> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
25 #include "base/threading/sequenced_worker_pool.h" | 25 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/time.h" | 26 #include "base/time.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/cookie_store_factory.h" | 28 #include "content/public/browser/cookie_store_factory.h" |
29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
31 #include "net/cookies/canonical_cookie.h" | 31 #include "net/cookies/canonical_cookie.h" |
| 32 #include "net/cookies/cookie_constants.h" |
32 #include "net/cookies/cookie_util.h" | 33 #include "net/cookies/cookie_util.h" |
33 #include "sql/error_delegate_util.h" | 34 #include "sql/error_delegate_util.h" |
34 #include "sql/meta_table.h" | 35 #include "sql/meta_table.h" |
35 #include "sql/statement.h" | 36 #include "sql/statement.h" |
36 #include "sql/transaction.h" | 37 #include "sql/transaction.h" |
37 #include "third_party/sqlite/sqlite3.h" | 38 #include "third_party/sqlite/sqlite3.h" |
38 #include "webkit/quota/special_storage_policy.h" | 39 #include "webkit/quota/special_storage_policy.h" |
39 | 40 |
40 using base::Time; | 41 using base::Time; |
41 | 42 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 "host_key TEXT NOT NULL," | 365 "host_key TEXT NOT NULL," |
365 "name TEXT NOT NULL," | 366 "name TEXT NOT NULL," |
366 "value TEXT NOT NULL," | 367 "value TEXT NOT NULL," |
367 "path TEXT NOT NULL," | 368 "path TEXT NOT NULL," |
368 "expires_utc INTEGER NOT NULL," | 369 "expires_utc INTEGER NOT NULL," |
369 "secure INTEGER NOT NULL," | 370 "secure INTEGER NOT NULL," |
370 "httponly INTEGER NOT NULL," | 371 "httponly INTEGER NOT NULL," |
371 "last_access_utc INTEGER NOT NULL, " | 372 "last_access_utc INTEGER NOT NULL, " |
372 "has_expires INTEGER NOT NULL DEFAULT 1, " | 373 "has_expires INTEGER NOT NULL DEFAULT 1, " |
373 "persistent INTEGER NOT NULL DEFAULT 1)")) | 374 "persistent INTEGER NOT NULL DEFAULT 1)")) |
| 375 // TODO(rogerm): Add priority. |
374 return false; | 376 return false; |
375 } | 377 } |
376 | 378 |
377 // Older code created an index on creation_utc, which is already | 379 // Older code created an index on creation_utc, which is already |
378 // primary key for the table. | 380 // primary key for the table. |
379 if (!db->Execute("DROP INDEX IF EXISTS cookie_times")) | 381 if (!db->Execute("DROP INDEX IF EXISTS cookie_times")) |
380 return false; | 382 return false; |
381 | 383 |
382 if (!db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)")) | 384 if (!db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)")) |
383 return false; | 385 return false; |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 const std::set<std::string>& domains) { | 656 const std::set<std::string>& domains) { |
655 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); | 657 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); |
656 | 658 |
657 sql::Statement smt; | 659 sql::Statement smt; |
658 if (restore_old_session_cookies_) { | 660 if (restore_old_session_cookies_) { |
659 smt.Assign(db_->GetCachedStatement( | 661 smt.Assign(db_->GetCachedStatement( |
660 SQL_FROM_HERE, | 662 SQL_FROM_HERE, |
661 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 663 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
662 "secure, httponly, last_access_utc, has_expires, persistent " | 664 "secure, httponly, last_access_utc, has_expires, persistent " |
663 "FROM cookies WHERE host_key = ?")); | 665 "FROM cookies WHERE host_key = ?")); |
| 666 // TODO(rogerm): Add priority. |
664 } else { | 667 } else { |
665 smt.Assign(db_->GetCachedStatement( | 668 smt.Assign(db_->GetCachedStatement( |
666 SQL_FROM_HERE, | 669 SQL_FROM_HERE, |
667 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 670 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
668 "secure, httponly, last_access_utc, has_expires, persistent " | 671 "secure, httponly, last_access_utc, has_expires, persistent " |
669 "FROM cookies WHERE host_key = ? AND persistent = 1")); | 672 "FROM cookies WHERE host_key = ? AND persistent = 1")); |
| 673 // TODO(rogerm): Add priority. |
670 } | 674 } |
671 if (!smt.is_valid()) { | 675 if (!smt.is_valid()) { |
672 smt.Clear(); // Disconnect smt_ref from db_. | 676 smt.Clear(); // Disconnect smt_ref from db_. |
673 meta_table_.Reset(); | 677 meta_table_.Reset(); |
674 db_.reset(); | 678 db_.reset(); |
675 return false; | 679 return false; |
676 } | 680 } |
677 | 681 |
678 std::vector<net::CanonicalCookie*> cookies; | 682 std::vector<net::CanonicalCookie*> cookies; |
679 std::set<std::string>::const_iterator it = domains.begin(); | 683 std::set<std::string>::const_iterator it = domains.begin(); |
680 for (; it != domains.end(); ++it) { | 684 for (; it != domains.end(); ++it) { |
681 smt.BindString(0, *it); | 685 smt.BindString(0, *it); |
682 while (smt.Step()) { | 686 while (smt.Step()) { |
683 scoped_ptr<net::CanonicalCookie> cc( | 687 scoped_ptr<net::CanonicalCookie> cc( |
684 new net::CanonicalCookie( | 688 new net::CanonicalCookie( |
685 // The "source" URL is not used with persisted cookies. | 689 // The "source" URL is not used with persisted cookies. |
686 GURL(), // Source | 690 GURL(), // Source |
687 smt.ColumnString(2), // name | 691 smt.ColumnString(2), // name |
688 smt.ColumnString(3), // value | 692 smt.ColumnString(3), // value |
689 smt.ColumnString(1), // domain | 693 smt.ColumnString(1), // domain |
690 smt.ColumnString(4), // path | 694 smt.ColumnString(4), // path |
691 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | 695 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc |
692 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | 696 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc |
693 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | 697 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc |
694 smt.ColumnInt(6) != 0, // secure | 698 smt.ColumnInt(6) != 0, // secure |
695 smt.ColumnInt(7) != 0)); // httponly | 699 smt.ColumnInt(7) != 0, // httponly |
| 700 net::PRIORITY_DEFAULT)); // priority |
| 701 // TODO(rogerm): Change net::PRIORITY_DEFAULT above to |
| 702 // net::StringToCookiePriority(smt.ColumnString(9))? |
696 DLOG_IF(WARNING, | 703 DLOG_IF(WARNING, |
697 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | 704 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; |
698 cookies_per_origin_[CookieOrigin(cc->Domain(), cc->IsSecure())]++; | 705 cookies_per_origin_[CookieOrigin(cc->Domain(), cc->IsSecure())]++; |
699 cookies.push_back(cc.release()); | 706 cookies.push_back(cc.release()); |
700 ++num_cookies_read_; | 707 ++num_cookies_read_; |
701 } | 708 } |
702 smt.Reset(true); | 709 smt.Reset(true); |
703 } | 710 } |
704 { | 711 { |
705 base::AutoLock locked(lock_); | 712 base::AutoLock locked(lock_); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 { | 876 { |
870 base::AutoLock locked(lock_); | 877 base::AutoLock locked(lock_); |
871 pending_.swap(ops); | 878 pending_.swap(ops); |
872 num_pending_ = 0; | 879 num_pending_ = 0; |
873 } | 880 } |
874 | 881 |
875 // Maybe an old timer fired or we are already Close()'ed. | 882 // Maybe an old timer fired or we are already Close()'ed. |
876 if (!db_.get() || ops.empty()) | 883 if (!db_.get() || ops.empty()) |
877 return; | 884 return; |
878 | 885 |
| 886 // TODO(rogerm): Add priority. |
879 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 887 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
880 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " | 888 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " |
881 "expires_utc, secure, httponly, last_access_utc, has_expires, " | 889 "expires_utc, secure, httponly, last_access_utc, has_expires, " |
882 "persistent) " | 890 "persistent) " |
883 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); | 891 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); |
884 if (!add_smt.is_valid()) | 892 if (!add_smt.is_valid()) |
885 return; | 893 return; |
886 | 894 |
887 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 895 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
888 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); | 896 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); |
(...skipping 22 matching lines...) Expand all Loading... |
911 add_smt.BindString(1, po->cc().Domain()); | 919 add_smt.BindString(1, po->cc().Domain()); |
912 add_smt.BindString(2, po->cc().Name()); | 920 add_smt.BindString(2, po->cc().Name()); |
913 add_smt.BindString(3, po->cc().Value()); | 921 add_smt.BindString(3, po->cc().Value()); |
914 add_smt.BindString(4, po->cc().Path()); | 922 add_smt.BindString(4, po->cc().Path()); |
915 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); | 923 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue()); |
916 add_smt.BindInt(6, po->cc().IsSecure()); | 924 add_smt.BindInt(6, po->cc().IsSecure()); |
917 add_smt.BindInt(7, po->cc().IsHttpOnly()); | 925 add_smt.BindInt(7, po->cc().IsHttpOnly()); |
918 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); | 926 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue()); |
919 add_smt.BindInt(9, po->cc().IsPersistent()); | 927 add_smt.BindInt(9, po->cc().IsPersistent()); |
920 add_smt.BindInt(10, po->cc().IsPersistent()); | 928 add_smt.BindInt(10, po->cc().IsPersistent()); |
| 929 // TODO(rogerm): Add priority. |
921 if (!add_smt.Run()) | 930 if (!add_smt.Run()) |
922 NOTREACHED() << "Could not add a cookie to the DB."; | 931 NOTREACHED() << "Could not add a cookie to the DB."; |
923 break; | 932 break; |
924 | 933 |
925 case PendingOperation::COOKIE_UPDATEACCESS: | 934 case PendingOperation::COOKIE_UPDATEACCESS: |
926 update_access_smt.Reset(true); | 935 update_access_smt.Reset(true); |
927 update_access_smt.BindInt64(0, | 936 update_access_smt.BindInt64(0, |
928 po->cc().LastAccessDate().ToInternalValue()); | 937 po->cc().LastAccessDate().ToInternalValue()); |
929 update_access_smt.BindInt64(1, | 938 update_access_smt.BindInt64(1, |
930 po->cc().CreationDate().ToInternalValue()); | 939 po->cc().CreationDate().ToInternalValue()); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 path, | 1154 path, |
1146 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 1155 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
1147 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 1156 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
1148 BrowserThread::GetBlockingPool()->GetSequenceToken()), | 1157 BrowserThread::GetBlockingPool()->GetSequenceToken()), |
1149 restore_old_session_cookies, | 1158 restore_old_session_cookies, |
1150 storage_policy); | 1159 storage_policy); |
1151 return new net::CookieMonster(persistent_store, cookie_monster_delegate); | 1160 return new net::CookieMonster(persistent_store, cookie_monster_delegate); |
1152 } | 1161 } |
1153 | 1162 |
1154 } // namespace content | 1163 } // namespace content |
OLD | NEW |