| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "chrome/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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 { | 654 { |
| 655 base::AutoLock locked(lock_); | 655 base::AutoLock locked(lock_); |
| 656 pending_.push_back(po.release()); | 656 pending_.push_back(po.release()); |
| 657 num_pending = ++num_pending_; | 657 num_pending = ++num_pending_; |
| 658 } | 658 } |
| 659 | 659 |
| 660 if (num_pending == 1) { | 660 if (num_pending == 1) { |
| 661 // We've gotten our first entry for this batch, fire off the timer. | 661 // We've gotten our first entry for this batch, fire off the timer. |
| 662 BrowserThread::PostDelayedTask( | 662 BrowserThread::PostDelayedTask( |
| 663 BrowserThread::DB, FROM_HERE, | 663 BrowserThread::DB, FROM_HERE, |
| 664 NewRunnableMethod(this, &Backend::Commit), kCommitIntervalMs); | 664 base::Bind(&Backend::Commit, this), kCommitIntervalMs); |
| 665 } else if (num_pending == kCommitAfterBatchSize) { | 665 } else if (num_pending == kCommitAfterBatchSize) { |
| 666 // We've reached a big enough batch, fire off a commit now. | 666 // We've reached a big enough batch, fire off a commit now. |
| 667 BrowserThread::PostTask( | 667 BrowserThread::PostTask( |
| 668 BrowserThread::DB, FROM_HERE, | 668 BrowserThread::DB, FROM_HERE, |
| 669 NewRunnableMethod(this, &Backend::Commit)); | 669 base::Bind(&Backend::Commit, this)); |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 | 672 |
| 673 void SQLitePersistentCookieStore::Backend::Commit() { | 673 void SQLitePersistentCookieStore::Backend::Commit() { |
| 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 675 | 675 |
| 676 PendingOperationsList ops; | 676 PendingOperationsList ops; |
| 677 { | 677 { |
| 678 base::AutoLock locked(lock_); | 678 base::AutoLock locked(lock_); |
| 679 pending_.swap(ops); | 679 pending_.swap(ops); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 755 } |
| 756 } | 756 } |
| 757 bool succeeded = transaction.Commit(); | 757 bool succeeded = transaction.Commit(); |
| 758 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", | 758 UMA_HISTOGRAM_ENUMERATION("Cookie.BackingStoreUpdateResults", |
| 759 succeeded ? 0 : 1, 2); | 759 succeeded ? 0 : 1, 2); |
| 760 } | 760 } |
| 761 | 761 |
| 762 void SQLitePersistentCookieStore::Backend::Flush(Task* completion_task) { | 762 void SQLitePersistentCookieStore::Backend::Flush(Task* completion_task) { |
| 763 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); | 763 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 764 BrowserThread::PostTask( | 764 BrowserThread::PostTask( |
| 765 BrowserThread::DB, FROM_HERE, NewRunnableMethod(this, &Backend::Commit)); | 765 BrowserThread::DB, FROM_HERE, base::Bind(&Backend::Commit, this)); |
| 766 if (completion_task) { | 766 if (completion_task) { |
| 767 // We want the completion task to run immediately after Commit() returns. | 767 // We want the completion task to run immediately after Commit() returns. |
| 768 // Posting it from here means there is less chance of another task getting | 768 // Posting it from here means there is less chance of another task getting |
| 769 // onto the message queue first, than if we posted it from Commit() itself. | 769 // onto the message queue first, than if we posted it from Commit() itself. |
| 770 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, completion_task); | 770 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, completion_task); |
| 771 } | 771 } |
| 772 } | 772 } |
| 773 | 773 |
| 774 // Fire off a close message to the background thread. We could still have a | 774 // Fire off a close message to the background thread. We could still have a |
| 775 // pending commit timer that will be holding a reference on us, but if/when | 775 // pending commit timer that will be holding a reference on us, but if/when |
| 776 // this fires we will already have been cleaned up and it will be ignored. | 776 // this fires we will already have been cleaned up and it will be ignored. |
| 777 void SQLitePersistentCookieStore::Backend::Close() { | 777 void SQLitePersistentCookieStore::Backend::Close() { |
| 778 if (BrowserThread::CurrentlyOn(BrowserThread::DB)) { | 778 if (BrowserThread::CurrentlyOn(BrowserThread::DB)) { |
| 779 InternalBackgroundClose(); | 779 InternalBackgroundClose(); |
| 780 } else { | 780 } else { |
| 781 // Must close the backend on the background thread. | 781 // Must close the backend on the background thread. |
| 782 BrowserThread::PostTask( | 782 BrowserThread::PostTask( |
| 783 BrowserThread::DB, FROM_HERE, | 783 BrowserThread::DB, FROM_HERE, |
| 784 NewRunnableMethod(this, &Backend::InternalBackgroundClose)); | 784 base::Bind(&Backend::InternalBackgroundClose, this)); |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 | 787 |
| 788 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { | 788 void SQLitePersistentCookieStore::Backend::InternalBackgroundClose() { |
| 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 790 // Commit any pending operations | 790 // Commit any pending operations |
| 791 Commit(); | 791 Commit(); |
| 792 | 792 |
| 793 db_.reset(); | 793 db_.reset(); |
| 794 | 794 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (backend_.get()) | 847 if (backend_.get()) |
| 848 backend_->SetClearLocalStateOnExit(clear_local_state); | 848 backend_->SetClearLocalStateOnExit(clear_local_state); |
| 849 } | 849 } |
| 850 | 850 |
| 851 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 851 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
| 852 if (backend_.get()) | 852 if (backend_.get()) |
| 853 backend_->Flush(completion_task); | 853 backend_->Flush(completion_task); |
| 854 else if (completion_task) | 854 else if (completion_task) |
| 855 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 855 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
| 856 } | 856 } |
| OLD | NEW |