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

Side by Side Diff: content/browser/net/sqlite_persistent_cookie_store.cc

Issue 98603012: Revert of Encrypt all stored cookies on selected operating systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
OLDNEW
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/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
21 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
22 #include "base/sequenced_task_runner.h" 22 #include "base/sequenced_task_runner.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
26 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/cookie_crypto_delegate.h"
30 #include "content/public/browser/cookie_store_factory.h" 29 #include "content/public/browser/cookie_store_factory.h"
31 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 30 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
32 #include "net/cookies/canonical_cookie.h" 31 #include "net/cookies/canonical_cookie.h"
33 #include "net/cookies/cookie_constants.h" 32 #include "net/cookies/cookie_constants.h"
34 #include "net/cookies/cookie_util.h" 33 #include "net/cookies/cookie_util.h"
35 #include "sql/error_delegate_util.h" 34 #include "sql/error_delegate_util.h"
36 #include "sql/meta_table.h" 35 #include "sql/meta_table.h"
37 #include "sql/statement.h" 36 #include "sql/statement.h"
38 #include "sql/transaction.h" 37 #include "sql/transaction.h"
39 #include "third_party/sqlite/sqlite3.h" 38 #include "third_party/sqlite/sqlite3.h"
(...skipping 27 matching lines...) Expand all
67 // disk on the BG runner every 30 seconds, 512 operations, or call to Flush(), 66 // disk on the BG runner every 30 seconds, 512 operations, or call to Flush(),
68 // whichever occurs first. 67 // whichever occurs first.
69 class SQLitePersistentCookieStore::Backend 68 class SQLitePersistentCookieStore::Backend
70 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { 69 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> {
71 public: 70 public:
72 Backend( 71 Backend(
73 const base::FilePath& path, 72 const base::FilePath& path,
74 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, 73 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
75 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, 74 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
76 bool restore_old_session_cookies, 75 bool restore_old_session_cookies,
77 quota::SpecialStoragePolicy* special_storage_policy, 76 quota::SpecialStoragePolicy* special_storage_policy)
78 scoped_ptr<CookieCryptoDelegate> crypto_delegate)
79 : path_(path), 77 : path_(path),
80 num_pending_(0), 78 num_pending_(0),
81 force_keep_session_state_(false), 79 force_keep_session_state_(false),
82 initialized_(false), 80 initialized_(false),
83 corruption_detected_(false), 81 corruption_detected_(false),
84 restore_old_session_cookies_(restore_old_session_cookies), 82 restore_old_session_cookies_(restore_old_session_cookies),
85 special_storage_policy_(special_storage_policy), 83 special_storage_policy_(special_storage_policy),
86 num_cookies_read_(0), 84 num_cookies_read_(0),
87 client_task_runner_(client_task_runner), 85 client_task_runner_(client_task_runner),
88 background_task_runner_(background_task_runner), 86 background_task_runner_(background_task_runner),
89 num_priority_waiting_(0), 87 num_priority_waiting_(0),
90 total_priority_requests_(0), 88 total_priority_requests_(0) {}
91 crypto_(crypto_delegate.Pass()) {}
92 89
93 // Creates or loads the SQLite database. 90 // Creates or loads the SQLite database.
94 void Load(const LoadedCallback& loaded_callback); 91 void Load(const LoadedCallback& loaded_callback);
95 92
96 // Loads cookies for the domain key (eTLD+1). 93 // Loads cookies for the domain key (eTLD+1).
97 void LoadCookiesForKey(const std::string& domain, 94 void LoadCookiesForKey(const std::string& domain,
98 const LoadedCallback& loaded_callback); 95 const LoadedCallback& loaded_callback);
99 96
100 // Batch a cookie addition. 97 // Batch a cookie addition.
101 void AddCookie(const net::CanonicalCookie& cc); 98 void AddCookie(const net::CanonicalCookie& cc);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // starting/completing priority loads or completing the total load). 261 // starting/completing priority loads or completing the total load).
265 base::Lock metrics_lock_; 262 base::Lock metrics_lock_;
266 int num_priority_waiting_; 263 int num_priority_waiting_;
267 // The total number of priority requests. 264 // The total number of priority requests.
268 int total_priority_requests_; 265 int total_priority_requests_;
269 // The time when |num_priority_waiting_| incremented to 1. 266 // The time when |num_priority_waiting_| incremented to 1.
270 base::Time current_priority_wait_start_; 267 base::Time current_priority_wait_start_;
271 // The cumulative duration of time when |num_priority_waiting_| was greater 268 // The cumulative duration of time when |num_priority_waiting_| was greater
272 // than 1. 269 // than 1.
273 base::TimeDelta priority_wait_duration_; 270 base::TimeDelta priority_wait_duration_;
274 // Class with functions that do cryptographic operations (for protecting
275 // cookies stored persistently).
276 scoped_ptr<CookieCryptoDelegate> crypto_;
277 271
278 DISALLOW_COPY_AND_ASSIGN(Backend); 272 DISALLOW_COPY_AND_ASSIGN(Backend);
279 }; 273 };
280 274
281 namespace { 275 namespace {
282 276
283 // Version number of the database. 277 // Version number of the database.
284 // 278 //
285 // Version 7 adds encrypted values. Old values will continue to be used but
286 // all new values written will be encrypted on selected operating systems. New
287 // records read by old clients will simply get an empty cookie value while old
288 // records read by new clients will continue to operate with the unencrypted
289 // version. New and old clients alike will always write/update records with
290 // what they support.
291 //
292 // Version 6 adds cookie priorities. This allows developers to influence the 279 // Version 6 adds cookie priorities. This allows developers to influence the
293 // order in which cookies are evicted in order to meet domain cookie limits. 280 // order in which cookies are evicted in order to meet domain cookie limits.
294 // 281 //
295 // Version 5 adds the columns has_expires and is_persistent, so that the 282 // Version 5 adds the columns has_expires and is_persistent, so that the
296 // database can store session cookies as well as persistent cookies. Databases 283 // database can store session cookies as well as persistent cookies. Databases
297 // of version 5 are incompatible with older versions of code. If a database of 284 // of version 5 are incompatible with older versions of code. If a database of
298 // version 5 is read by older code, session cookies will be treated as normal 285 // version 5 is read by older code, session cookies will be treated as normal
299 // cookies. Currently, these fields are written, but not read anymore. 286 // cookies. Currently, these fields are written, but not read anymore.
300 // 287 //
301 // In version 4, we migrated the time epoch. If you open the DB with an older 288 // In version 4, we migrated the time epoch. If you open the DB with an older
302 // version on Mac or Linux, the times will look wonky, but the file will likely 289 // version on Mac or Linux, the times will look wonky, but the file will likely
303 // be usable. On Windows version 3 and 4 are the same. 290 // be usable. On Windows version 3 and 4 are the same.
304 // 291 //
305 // Version 3 updated the database to include the last access time, so we can 292 // Version 3 updated the database to include the last access time, so we can
306 // expire them in decreasing order of use when we've reached the maximum 293 // expire them in decreasing order of use when we've reached the maximum
307 // number of cookies. 294 // number of cookies.
308 const int kCurrentVersionNumber = 7; 295 const int kCurrentVersionNumber = 6;
309 const int kCompatibleVersionNumber = 5; 296 const int kCompatibleVersionNumber = 5;
310 297
311 // Possible values for the 'priority' column. 298 // Possible values for the 'priority' column.
312 enum DBCookiePriority { 299 enum DBCookiePriority {
313 kCookiePriorityLow = 0, 300 kCookiePriorityLow = 0,
314 kCookiePriorityMedium = 1, 301 kCookiePriorityMedium = 1,
315 kCookiePriorityHigh = 2, 302 kCookiePriorityHigh = 2,
316 }; 303 };
317 304
318 DBCookiePriority CookiePriorityToDBCookiePriority(net::CookiePriority value) { 305 DBCookiePriority CookiePriorityToDBCookiePriority(net::CookiePriority value) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 "host_key TEXT NOT NULL," 362 "host_key TEXT NOT NULL,"
376 "name TEXT NOT NULL," 363 "name TEXT NOT NULL,"
377 "value TEXT NOT NULL," 364 "value TEXT NOT NULL,"
378 "path TEXT NOT NULL," 365 "path TEXT NOT NULL,"
379 "expires_utc INTEGER NOT NULL," 366 "expires_utc INTEGER NOT NULL,"
380 "secure INTEGER NOT NULL," 367 "secure INTEGER NOT NULL,"
381 "httponly INTEGER NOT NULL," 368 "httponly INTEGER NOT NULL,"
382 "last_access_utc INTEGER NOT NULL, " 369 "last_access_utc INTEGER NOT NULL, "
383 "has_expires INTEGER NOT NULL DEFAULT 1, " 370 "has_expires INTEGER NOT NULL DEFAULT 1, "
384 "persistent INTEGER NOT NULL DEFAULT 1," 371 "persistent INTEGER NOT NULL DEFAULT 1,"
385 "priority INTEGER NOT NULL DEFAULT %d," 372 "priority INTEGER NOT NULL DEFAULT %d)",
386 "encrypted_value BLOB DEFAULT '')",
387 CookiePriorityToDBCookiePriority(net::COOKIE_PRIORITY_DEFAULT))); 373 CookiePriorityToDBCookiePriority(net::COOKIE_PRIORITY_DEFAULT)));
388 if (!db->Execute(stmt.c_str())) 374 if (!db->Execute(stmt.c_str()))
389 return false; 375 return false;
390 } 376 }
391 377
392 // Older code created an index on creation_utc, which is already 378 // Older code created an index on creation_utc, which is already
393 // primary key for the table. 379 // primary key for the table.
394 if (!db->Execute("DROP INDEX IF EXISTS cookie_times")) 380 if (!db->Execute("DROP INDEX IF EXISTS cookie_times"))
395 return false; 381 return false;
396 382
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 671 }
686 672
687 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( 673 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
688 const std::set<std::string>& domains) { 674 const std::set<std::string>& domains) {
689 DCHECK(background_task_runner_->RunsTasksOnCurrentThread()); 675 DCHECK(background_task_runner_->RunsTasksOnCurrentThread());
690 676
691 sql::Statement smt; 677 sql::Statement smt;
692 if (restore_old_session_cookies_) { 678 if (restore_old_session_cookies_) {
693 smt.Assign(db_->GetCachedStatement( 679 smt.Assign(db_->GetCachedStatement(
694 SQL_FROM_HERE, 680 SQL_FROM_HERE,
695 "SELECT creation_utc, host_key, name, value, encrypted_value, path, " 681 "SELECT creation_utc, host_key, name, value, path, expires_utc, "
696 "expires_utc, secure, httponly, last_access_utc, has_expires, " 682 "secure, httponly, last_access_utc, has_expires, persistent, priority "
697 "persistent, priority FROM cookies WHERE host_key = ?")); 683 "FROM cookies WHERE host_key = ?"));
698 } else { 684 } else {
699 smt.Assign(db_->GetCachedStatement( 685 smt.Assign(db_->GetCachedStatement(
700 SQL_FROM_HERE, 686 SQL_FROM_HERE,
701 "SELECT creation_utc, host_key, name, value, encrypted_value, path, " 687 "SELECT creation_utc, host_key, name, value, path, expires_utc, "
702 "expires_utc, secure, httponly, last_access_utc, has_expires, " 688 "secure, httponly, last_access_utc, has_expires, persistent, priority "
703 "persistent, priority FROM cookies WHERE host_key = ? " 689 "FROM cookies WHERE host_key = ? AND persistent = 1"));
704 "AND persistent = 1"));
705 } 690 }
706 if (!smt.is_valid()) { 691 if (!smt.is_valid()) {
707 smt.Clear(); // Disconnect smt_ref from db_. 692 smt.Clear(); // Disconnect smt_ref from db_.
708 meta_table_.Reset(); 693 meta_table_.Reset();
709 db_.reset(); 694 db_.reset();
710 return false; 695 return false;
711 } 696 }
712 697
713 std::vector<net::CanonicalCookie*> cookies; 698 std::vector<net::CanonicalCookie*> cookies;
714 std::set<std::string>::const_iterator it = domains.begin(); 699 std::set<std::string>::const_iterator it = domains.begin();
715 for (; it != domains.end(); ++it) { 700 for (; it != domains.end(); ++it) {
716 smt.BindString(0, *it); 701 smt.BindString(0, *it);
717 while (smt.Step()) { 702 while (smt.Step()) {
718 std::string value;
719 std::string encrypted_value = smt.ColumnString(4);
720 if (!encrypted_value.empty() && crypto_.get()) {
721 crypto_->DecryptString(encrypted_value, &value);
722 } else {
723 DCHECK(encrypted_value.empty());
724 value = smt.ColumnString(3);
725 }
726 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie( 703 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie(
727 // The "source" URL is not used with persisted cookies. 704 // The "source" URL is not used with persisted cookies.
728 GURL(), // Source 705 GURL(), // Source
729 smt.ColumnString(2), // name 706 smt.ColumnString(2), // name
730 value, // value 707 smt.ColumnString(3), // value
731 smt.ColumnString(1), // domain 708 smt.ColumnString(1), // domain
732 smt.ColumnString(5), // path 709 smt.ColumnString(4), // path
733 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc 710 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
734 Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc 711 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
735 Time::FromInternalValue(smt.ColumnInt64(9)), // last_access_utc 712 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
736 smt.ColumnInt(7) != 0, // secure 713 smt.ColumnInt(6) != 0, // secure
737 smt.ColumnInt(8) != 0, // httponly 714 smt.ColumnInt(7) != 0, // httponly
738 DBCookiePriorityToCookiePriority( 715 DBCookiePriorityToCookiePriority(
739 static_cast<DBCookiePriority>(smt.ColumnInt(12))))); // priority 716 static_cast<DBCookiePriority>(smt.ColumnInt(11))))); // priority
740 DLOG_IF(WARNING, 717 DLOG_IF(WARNING,
741 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; 718 cc->CreationDate() > Time::Now()) << L"CreationDate too recent";
742 cookies_per_origin_[CookieOrigin(cc->Domain(), cc->IsSecure())]++; 719 cookies_per_origin_[CookieOrigin(cc->Domain(), cc->IsSecure())]++;
743 cookies.push_back(cc.release()); 720 cookies.push_back(cc.release());
744 ++num_cookies_read_; 721 ++num_cookies_read_;
745 } 722 }
746 smt.Reset(true); 723 smt.Reset(true);
747 } 724 }
748 { 725 {
749 base::AutoLock locked(lock_); 726 base::AutoLock locked(lock_);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 829 }
853 ++cur_version; 830 ++cur_version;
854 meta_table_.SetVersionNumber(cur_version); 831 meta_table_.SetVersionNumber(cur_version);
855 meta_table_.SetCompatibleVersionNumber( 832 meta_table_.SetCompatibleVersionNumber(
856 std::min(cur_version, kCompatibleVersionNumber)); 833 std::min(cur_version, kCompatibleVersionNumber));
857 transaction.Commit(); 834 transaction.Commit();
858 UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV6", 835 UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV6",
859 base::TimeTicks::Now() - start_time); 836 base::TimeTicks::Now() - start_time);
860 } 837 }
861 838
862 if (cur_version == 6) {
863 const base::TimeTicks start_time = base::TimeTicks::Now();
864 sql::Transaction transaction(db_.get());
865 if (!transaction.Begin())
866 return false;
867 // Alter the table to add empty "encrypted value" column.
868 if (!db_->Execute("ALTER TABLE cookies "
869 "ADD COLUMN encrypted_value BLOB DEFAULT ''")) {
870 LOG(WARNING) << "Unable to update cookie database to version 7.";
871 return false;
872 }
873 ++cur_version;
874 meta_table_.SetVersionNumber(cur_version);
875 meta_table_.SetCompatibleVersionNumber(
876 std::min(cur_version, kCompatibleVersionNumber));
877 transaction.Commit();
878 UMA_HISTOGRAM_TIMES("Cookie.TimeDatabaseMigrationToV7",
879 base::TimeTicks::Now() - start_time);
880 }
881
882 // Put future migration cases here. 839 // Put future migration cases here.
883 840
884 if (cur_version < kCurrentVersionNumber) { 841 if (cur_version < kCurrentVersionNumber) {
885 UMA_HISTOGRAM_COUNTS_100("Cookie.CorruptMetaTable", 1); 842 UMA_HISTOGRAM_COUNTS_100("Cookie.CorruptMetaTable", 1);
886 843
887 meta_table_.Reset(); 844 meta_table_.Reset();
888 db_.reset(new sql::Connection); 845 db_.reset(new sql::Connection);
889 if (!base::DeleteFile(path_, false) || 846 if (!base::DeleteFile(path_, false) ||
890 !db_->Open(path_) || 847 !db_->Open(path_) ||
891 !meta_table_.Init( 848 !meta_table_.Init(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 base::AutoLock locked(lock_); 913 base::AutoLock locked(lock_);
957 pending_.swap(ops); 914 pending_.swap(ops);
958 num_pending_ = 0; 915 num_pending_ = 0;
959 } 916 }
960 917
961 // Maybe an old timer fired or we are already Close()'ed. 918 // Maybe an old timer fired or we are already Close()'ed.
962 if (!db_.get() || ops.empty()) 919 if (!db_.get() || ops.empty())
963 return; 920 return;
964 921
965 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, 922 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
966 "INSERT INTO cookies (creation_utc, host_key, name, value, " 923 "INSERT INTO cookies (creation_utc, host_key, name, value, path, "
967 "encrypted_value, path, expires_utc, secure, httponly, last_access_utc, " 924 "expires_utc, secure, httponly, last_access_utc, has_expires, "
968 "has_expires, persistent, priority) " 925 "persistent, priority) "
969 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")); 926 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
970 if (!add_smt.is_valid()) 927 if (!add_smt.is_valid())
971 return; 928 return;
972 929
973 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, 930 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE,
974 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); 931 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?"));
975 if (!update_access_smt.is_valid()) 932 if (!update_access_smt.is_valid())
976 return; 933 return;
977 934
978 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, 935 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
979 "DELETE FROM cookies WHERE creation_utc=?")); 936 "DELETE FROM cookies WHERE creation_utc=?"));
980 if (!del_smt.is_valid()) 937 if (!del_smt.is_valid())
981 return; 938 return;
982 939
983 sql::Transaction transaction(db_.get()); 940 sql::Transaction transaction(db_.get());
984 if (!transaction.Begin()) 941 if (!transaction.Begin())
985 return; 942 return;
986 943
987 for (PendingOperationsList::iterator it = ops.begin(); 944 for (PendingOperationsList::iterator it = ops.begin();
988 it != ops.end(); ++it) { 945 it != ops.end(); ++it) {
989 // Free the cookies as we commit them to the database. 946 // Free the cookies as we commit them to the database.
990 scoped_ptr<PendingOperation> po(*it); 947 scoped_ptr<PendingOperation> po(*it);
991 switch (po->op()) { 948 switch (po->op()) {
992 case PendingOperation::COOKIE_ADD: 949 case PendingOperation::COOKIE_ADD:
993 cookies_per_origin_[ 950 cookies_per_origin_[
994 CookieOrigin(po->cc().Domain(), po->cc().IsSecure())]++; 951 CookieOrigin(po->cc().Domain(), po->cc().IsSecure())]++;
995 add_smt.Reset(true); 952 add_smt.Reset(true);
996 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); 953 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
997 add_smt.BindString(1, po->cc().Domain()); 954 add_smt.BindString(1, po->cc().Domain());
998 add_smt.BindString(2, po->cc().Name()); 955 add_smt.BindString(2, po->cc().Name());
999 if (crypto_.get()) { 956 add_smt.BindString(3, po->cc().Value());
1000 std::string encrypted_value; 957 add_smt.BindString(4, po->cc().Path());
1001 add_smt.BindCString(3, ""); // value 958 add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue());
1002 crypto_->EncryptString(po->cc().Value(), &encrypted_value); 959 add_smt.BindInt(6, po->cc().IsSecure());
1003 // BindBlob() immediately makes an internal copy of the data. 960 add_smt.BindInt(7, po->cc().IsHttpOnly());
1004 add_smt.BindBlob(4, encrypted_value.data(), 961 add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue());
1005 static_cast<int>(encrypted_value.length())); 962 add_smt.BindInt(9, po->cc().IsPersistent());
1006 } else {
1007 add_smt.BindString(3, po->cc().Value());
1008 add_smt.BindBlob(4, "", 0); // encrypted_value
1009 }
1010 add_smt.BindString(5, po->cc().Path());
1011 add_smt.BindInt64(6, po->cc().ExpiryDate().ToInternalValue());
1012 add_smt.BindInt(7, po->cc().IsSecure());
1013 add_smt.BindInt(8, po->cc().IsHttpOnly());
1014 add_smt.BindInt64(9, po->cc().LastAccessDate().ToInternalValue());
1015 add_smt.BindInt(10, po->cc().IsPersistent()); 963 add_smt.BindInt(10, po->cc().IsPersistent());
1016 add_smt.BindInt(11, po->cc().IsPersistent());
1017 add_smt.BindInt( 964 add_smt.BindInt(
1018 12, CookiePriorityToDBCookiePriority(po->cc().Priority())); 965 11, CookiePriorityToDBCookiePriority(po->cc().Priority()));
1019 if (!add_smt.Run()) 966 if (!add_smt.Run())
1020 NOTREACHED() << "Could not add a cookie to the DB."; 967 NOTREACHED() << "Could not add a cookie to the DB.";
1021 break; 968 break;
1022 969
1023 case PendingOperation::COOKIE_UPDATEACCESS: 970 case PendingOperation::COOKIE_UPDATEACCESS:
1024 update_access_smt.Reset(true); 971 update_access_smt.Reset(true);
1025 update_access_smt.BindInt64(0, 972 update_access_smt.BindInt64(0,
1026 po->cc().LastAccessDate().ToInternalValue()); 973 po->cc().LastAccessDate().ToInternalValue());
1027 update_access_smt.BindInt64(1, 974 update_access_smt.BindInt64(1,
1028 po->cc().CreationDate().ToInternalValue()); 975 po->cc().CreationDate().ToInternalValue());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 LOG(WARNING) << "Failed to post task from " << origin.ToString() 1141 LOG(WARNING) << "Failed to post task from " << origin.ToString()
1195 << " to client_task_runner_."; 1142 << " to client_task_runner_.";
1196 } 1143 }
1197 } 1144 }
1198 1145
1199 SQLitePersistentCookieStore::SQLitePersistentCookieStore( 1146 SQLitePersistentCookieStore::SQLitePersistentCookieStore(
1200 const base::FilePath& path, 1147 const base::FilePath& path,
1201 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, 1148 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
1202 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, 1149 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
1203 bool restore_old_session_cookies, 1150 bool restore_old_session_cookies,
1204 quota::SpecialStoragePolicy* special_storage_policy, 1151 quota::SpecialStoragePolicy* special_storage_policy)
1205 scoped_ptr<CookieCryptoDelegate> crypto_delegate)
1206 : backend_(new Backend(path, 1152 : backend_(new Backend(path,
1207 client_task_runner, 1153 client_task_runner,
1208 background_task_runner, 1154 background_task_runner,
1209 restore_old_session_cookies, 1155 restore_old_session_cookies,
1210 special_storage_policy, 1156 special_storage_policy)) {
1211 crypto_delegate.Pass())) {
1212 } 1157 }
1213 1158
1214 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { 1159 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
1215 backend_->Load(loaded_callback); 1160 backend_->Load(loaded_callback);
1216 } 1161 }
1217 1162
1218 void SQLitePersistentCookieStore::LoadCookiesForKey( 1163 void SQLitePersistentCookieStore::LoadCookiesForKey(
1219 const std::string& key, 1164 const std::string& key,
1220 const LoadedCallback& loaded_callback) { 1165 const LoadedCallback& loaded_callback) {
1221 backend_->LoadCookiesForKey(key, loaded_callback); 1166 backend_->LoadCookiesForKey(key, loaded_callback);
(...skipping 25 matching lines...) Expand all
1247 // We release our reference to the Backend, though it will probably still have 1192 // We release our reference to the Backend, though it will probably still have
1248 // a reference if the background runner has not run Close() yet. 1193 // a reference if the background runner has not run Close() yet.
1249 } 1194 }
1250 1195
1251 net::CookieStore* CreatePersistentCookieStore( 1196 net::CookieStore* CreatePersistentCookieStore(
1252 const base::FilePath& path, 1197 const base::FilePath& path,
1253 bool restore_old_session_cookies, 1198 bool restore_old_session_cookies,
1254 quota::SpecialStoragePolicy* storage_policy, 1199 quota::SpecialStoragePolicy* storage_policy,
1255 net::CookieMonster::Delegate* cookie_monster_delegate, 1200 net::CookieMonster::Delegate* cookie_monster_delegate,
1256 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, 1201 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
1257 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, 1202 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner) {
1258 scoped_ptr<CookieCryptoDelegate> crypto_delegate) {
1259 SQLitePersistentCookieStore* persistent_store = 1203 SQLitePersistentCookieStore* persistent_store =
1260 new SQLitePersistentCookieStore( 1204 new SQLitePersistentCookieStore(
1261 path, 1205 path,
1262 client_task_runner, 1206 client_task_runner,
1263 background_task_runner, 1207 background_task_runner,
1264 restore_old_session_cookies, 1208 restore_old_session_cookies,
1265 storage_policy, 1209 storage_policy);
1266 crypto_delegate.Pass());
1267 return new net::CookieMonster(persistent_store, cookie_monster_delegate); 1210 return new net::CookieMonster(persistent_store, cookie_monster_delegate);
1268 } 1211 }
1269 1212
1270 net::CookieStore* CreatePersistentCookieStore( 1213 net::CookieStore* CreatePersistentCookieStore(
1271 const base::FilePath& path, 1214 const base::FilePath& path,
1272 bool restore_old_session_cookies, 1215 bool restore_old_session_cookies,
1273 quota::SpecialStoragePolicy* storage_policy, 1216 quota::SpecialStoragePolicy* storage_policy,
1274 net::CookieMonster::Delegate* cookie_monster_delegate, 1217 net::CookieMonster::Delegate* cookie_monster_delegate) {
1275 scoped_ptr<CookieCryptoDelegate> crypto_delegate) {
1276 return CreatePersistentCookieStore( 1218 return CreatePersistentCookieStore(
1277 path, 1219 path,
1278 restore_old_session_cookies, 1220 restore_old_session_cookies,
1279 storage_policy, 1221 storage_policy,
1280 cookie_monster_delegate, 1222 cookie_monster_delegate,
1281 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 1223 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
1282 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( 1224 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
1283 BrowserThread::GetBlockingPool()->GetSequenceToken()), 1225 BrowserThread::GetBlockingPool()->GetSequenceToken()));
1284 crypto_delegate.Pass());
1285 } 1226 }
1286 1227
1287 } // namespace content 1228 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/net/sqlite_persistent_cookie_store.h ('k') | content/browser/net/sqlite_persistent_cookie_store_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698