| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/common/net/cookie_monster_sqlite.h" | 5 #include "chrome/common/net/cookie_monster_sqlite.h" |
| 6 | 6 |
| 7 #include <list> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 10 #include "base/thread.h" | 12 #include "base/thread.h" |
| 11 #include "chrome/common/sqlite_compiled_statement.h" | 13 #include "chrome/common/sqlite_compiled_statement.h" |
| 12 #include "chrome/common/sqlite_utils.h" | 14 #include "chrome/common/sqlite_utils.h" |
| 13 | 15 |
| 14 // This class is designed to be shared between any calling threads and the | 16 // This class is designed to be shared between any calling threads and the |
| 15 // database thread. It batches operations and commits them on a timer. | 17 // database thread. It batches operations and commits them on a timer. |
| 16 class SQLitePersistentCookieStore::Backend | 18 class SQLitePersistentCookieStore::Backend |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 BatchOperation(PendingOperation::COOKIE_DELETE, std::string(), cc); | 99 BatchOperation(PendingOperation::COOKIE_DELETE, std::string(), cc); |
| 98 } | 100 } |
| 99 | 101 |
| 100 void SQLitePersistentCookieStore::Backend::BatchOperation( | 102 void SQLitePersistentCookieStore::Backend::BatchOperation( |
| 101 PendingOperation::OperationType op, | 103 PendingOperation::OperationType op, |
| 102 const std::string& key, | 104 const std::string& key, |
| 103 const net::CookieMonster::CanonicalCookie& cc) { | 105 const net::CookieMonster::CanonicalCookie& cc) { |
| 104 // Commit every 30 seconds. | 106 // Commit every 30 seconds. |
| 105 static const int kCommitIntervalMs = 30 * 1000; | 107 static const int kCommitIntervalMs = 30 * 1000; |
| 106 // Commit right away if we have more than 512 outstanding operations. | 108 // Commit right away if we have more than 512 outstanding operations. |
| 107 static const int kCommitAfterBatchSize = 512; | 109 static const size_t kCommitAfterBatchSize = 512; |
| 108 DCHECK(MessageLoop::current() != background_loop_); | 110 DCHECK(MessageLoop::current() != background_loop_); |
| 109 | 111 |
| 110 // We do a full copy of the cookie here, and hopefully just here. | 112 // We do a full copy of the cookie here, and hopefully just here. |
| 111 scoped_ptr<PendingOperation> po(new PendingOperation(op, key, cc)); | 113 scoped_ptr<PendingOperation> po(new PendingOperation(op, key, cc)); |
| 112 CHECK(po.get()); | 114 CHECK(po.get()); |
| 113 | 115 |
| 114 PendingOperationsList::size_type num_pending; | 116 PendingOperationsList::size_type num_pending; |
| 115 { | 117 { |
| 116 AutoLock locked(pending_lock_); | 118 AutoLock locked(pending_lock_); |
| 117 pending_.push_back(po.release()); | 119 pending_.push_back(po.release()); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 if (backend_.get()) | 347 if (backend_.get()) |
| 346 backend_->AddCookie(key, cc); | 348 backend_->AddCookie(key, cc); |
| 347 } | 349 } |
| 348 | 350 |
| 349 void SQLitePersistentCookieStore::DeleteCookie( | 351 void SQLitePersistentCookieStore::DeleteCookie( |
| 350 const net::CookieMonster::CanonicalCookie& cc) { | 352 const net::CookieMonster::CanonicalCookie& cc) { |
| 351 if (backend_.get()) | 353 if (backend_.get()) |
| 352 backend_->DeleteCookie(cc); | 354 backend_->DeleteCookie(cc); |
| 353 } | 355 } |
| 354 | 356 |
| OLD | NEW |