| 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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" | 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> |
| 8 #include <set> | 9 #include <set> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | |
| 19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/profiler/scoped_tracker.h" | 20 #include "base/profiler/scoped_tracker.h" |
| 21 #include "base/sequenced_task_runner.h" | 21 #include "base/sequenced_task_runner.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.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/time.h" | 26 #include "base/time/time.h" |
| 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 27 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 28 #include "net/cookies/canonical_cookie.h" | 28 #include "net/cookies/canonical_cookie.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 const base::Closure& task); | 235 const base::Closure& task); |
| 236 void PostClientTask(const tracked_objects::Location& origin, | 236 void PostClientTask(const tracked_objects::Location& origin, |
| 237 const base::Closure& task); | 237 const base::Closure& task); |
| 238 | 238 |
| 239 // Shared code between the different load strategies to be used after all | 239 // Shared code between the different load strategies to be used after all |
| 240 // cookies have been loaded. | 240 // cookies have been loaded. |
| 241 void FinishedLoadingCookies(const LoadedCallback& loaded_callback, | 241 void FinishedLoadingCookies(const LoadedCallback& loaded_callback, |
| 242 bool success); | 242 bool success); |
| 243 | 243 |
| 244 const base::FilePath path_; | 244 const base::FilePath path_; |
| 245 scoped_ptr<sql::Connection> db_; | 245 std::unique_ptr<sql::Connection> db_; |
| 246 sql::MetaTable meta_table_; | 246 sql::MetaTable meta_table_; |
| 247 | 247 |
| 248 typedef std::list<PendingOperation*> PendingOperationsList; | 248 typedef std::list<PendingOperation*> PendingOperationsList; |
| 249 PendingOperationsList pending_; | 249 PendingOperationsList pending_; |
| 250 PendingOperationsList::size_type num_pending_; | 250 PendingOperationsList::size_type num_pending_; |
| 251 // Guard |cookies_|, |pending_|, |num_pending_|. | 251 // Guard |cookies_|, |pending_|, |num_pending_|. |
| 252 base::Lock lock_; | 252 base::Lock lock_; |
| 253 | 253 |
| 254 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce | 254 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce |
| 255 // the number of messages sent to the client runner. Sent back in response to | 255 // the number of messages sent to the client runner. Sent back in response to |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 sql::Statement& smt = *statement; | 812 sql::Statement& smt = *statement; |
| 813 while (smt.Step()) { | 813 while (smt.Step()) { |
| 814 std::string value; | 814 std::string value; |
| 815 std::string encrypted_value = smt.ColumnString(4); | 815 std::string encrypted_value = smt.ColumnString(4); |
| 816 if (!encrypted_value.empty() && crypto_) { | 816 if (!encrypted_value.empty() && crypto_) { |
| 817 if (!crypto_->DecryptString(encrypted_value, &value)) | 817 if (!crypto_->DecryptString(encrypted_value, &value)) |
| 818 continue; | 818 continue; |
| 819 } else { | 819 } else { |
| 820 value = smt.ColumnString(3); | 820 value = smt.ColumnString(3); |
| 821 } | 821 } |
| 822 scoped_ptr<CanonicalCookie> cc(new CanonicalCookie( | 822 std::unique_ptr<CanonicalCookie> cc(new CanonicalCookie( |
| 823 // The "source" URL is not used with persisted cookies. | 823 // The "source" URL is not used with persisted cookies. |
| 824 GURL(), // Source | 824 GURL(), // Source |
| 825 smt.ColumnString(2), // name | 825 smt.ColumnString(2), // name |
| 826 value, // value | 826 value, // value |
| 827 smt.ColumnString(1), // domain | 827 smt.ColumnString(1), // domain |
| 828 smt.ColumnString(5), // path | 828 smt.ColumnString(5), // path |
| 829 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | 829 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc |
| 830 Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc | 830 Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc |
| 831 Time::FromInternalValue(smt.ColumnInt64(10)), // last_access_utc | 831 Time::FromInternalValue(smt.ColumnInt64(10)), // last_access_utc |
| 832 smt.ColumnInt(7) != 0, // secure | 832 smt.ColumnInt(7) != 0, // secure |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 void SQLitePersistentCookieStore::Backend::BatchOperation( | 1074 void SQLitePersistentCookieStore::Backend::BatchOperation( |
| 1075 PendingOperation::OperationType op, | 1075 PendingOperation::OperationType op, |
| 1076 const CanonicalCookie& cc) { | 1076 const CanonicalCookie& cc) { |
| 1077 // Commit every 30 seconds. | 1077 // Commit every 30 seconds. |
| 1078 static const int kCommitIntervalMs = 30 * 1000; | 1078 static const int kCommitIntervalMs = 30 * 1000; |
| 1079 // Commit right away if we have more than 512 outstanding operations. | 1079 // Commit right away if we have more than 512 outstanding operations. |
| 1080 static const size_t kCommitAfterBatchSize = 512; | 1080 static const size_t kCommitAfterBatchSize = 512; |
| 1081 DCHECK(!background_task_runner_->RunsTasksOnCurrentThread()); | 1081 DCHECK(!background_task_runner_->RunsTasksOnCurrentThread()); |
| 1082 | 1082 |
| 1083 // We do a full copy of the cookie here, and hopefully just here. | 1083 // We do a full copy of the cookie here, and hopefully just here. |
| 1084 scoped_ptr<PendingOperation> po(new PendingOperation(op, cc)); | 1084 std::unique_ptr<PendingOperation> po(new PendingOperation(op, cc)); |
| 1085 | 1085 |
| 1086 PendingOperationsList::size_type num_pending; | 1086 PendingOperationsList::size_type num_pending; |
| 1087 { | 1087 { |
| 1088 base::AutoLock locked(lock_); | 1088 base::AutoLock locked(lock_); |
| 1089 pending_.push_back(po.release()); | 1089 pending_.push_back(po.release()); |
| 1090 num_pending = ++num_pending_; | 1090 num_pending = ++num_pending_; |
| 1091 } | 1091 } |
| 1092 | 1092 |
| 1093 if (num_pending == 1) { | 1093 if (num_pending == 1) { |
| 1094 // We've gotten our first entry for this batch, fire off the timer. | 1094 // We've gotten our first entry for this batch, fire off the timer. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 if (!del_smt.is_valid()) | 1137 if (!del_smt.is_valid()) |
| 1138 return; | 1138 return; |
| 1139 | 1139 |
| 1140 sql::Transaction transaction(db_.get()); | 1140 sql::Transaction transaction(db_.get()); |
| 1141 if (!transaction.Begin()) | 1141 if (!transaction.Begin()) |
| 1142 return; | 1142 return; |
| 1143 | 1143 |
| 1144 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end(); | 1144 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end(); |
| 1145 ++it) { | 1145 ++it) { |
| 1146 // Free the cookies as we commit them to the database. | 1146 // Free the cookies as we commit them to the database. |
| 1147 scoped_ptr<PendingOperation> po(*it); | 1147 std::unique_ptr<PendingOperation> po(*it); |
| 1148 switch (po->op()) { | 1148 switch (po->op()) { |
| 1149 case PendingOperation::COOKIE_ADD: | 1149 case PendingOperation::COOKIE_ADD: |
| 1150 add_smt.Reset(true); | 1150 add_smt.Reset(true); |
| 1151 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); | 1151 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); |
| 1152 add_smt.BindString(1, po->cc().Domain()); | 1152 add_smt.BindString(1, po->cc().Domain()); |
| 1153 add_smt.BindString(2, po->cc().Name()); | 1153 add_smt.BindString(2, po->cc().Name()); |
| 1154 if (crypto_ && crypto_->ShouldEncrypt()) { | 1154 if (crypto_ && crypto_->ShouldEncrypt()) { |
| 1155 std::string encrypted_value; | 1155 std::string encrypted_value; |
| 1156 if (!crypto_->EncryptString(po->cc().Value(), &encrypted_value)) | 1156 if (!crypto_->EncryptString(po->cc().Value(), &encrypted_value)) |
| 1157 continue; | 1157 continue; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 1440 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
| 1441 if (backend_) | 1441 if (backend_) |
| 1442 backend_->Flush(callback); | 1442 backend_->Flush(callback); |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 1445 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
| 1446 Close(base::Closure()); | 1446 Close(base::Closure()); |
| 1447 } | 1447 } |
| 1448 | 1448 |
| 1449 } // namespace net | 1449 } // namespace net |
| OLD | NEW |