| 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 base::Time::Now() - start, | 499 base::Time::Now() - start, |
| 500 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), | 500 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(1), |
| 501 50); | 501 50); |
| 502 | 502 |
| 503 start = base::Time::Now(); | 503 start = base::Time::Now(); |
| 504 | 504 |
| 505 // Retrieve all the domains | 505 // Retrieve all the domains |
| 506 sql::Statement smt(db_->GetUniqueStatement( | 506 sql::Statement smt(db_->GetUniqueStatement( |
| 507 "SELECT DISTINCT host_key FROM cookies")); | 507 "SELECT DISTINCT host_key FROM cookies")); |
| 508 | 508 |
| 509 if (!smt) { | 509 if (!smt.is_valid()) { |
| 510 NOTREACHED() << "select statement prep failed"; | |
| 511 db_.reset(); | 510 db_.reset(); |
| 512 return false; | 511 return false; |
| 513 } | 512 } |
| 514 | 513 |
| 515 // Build a map of domain keys (always eTLD+1) to domains. | 514 // Build a map of domain keys (always eTLD+1) to domains. |
| 516 while (smt.Step()) { | 515 while (smt.Step()) { |
| 517 std::string domain = smt.ColumnString(0); | 516 std::string domain = smt.ColumnString(0); |
| 518 std::string key = | 517 std::string key = |
| 519 net::RegistryControlledDomainService::GetDomainAndRegistry(domain); | 518 net::RegistryControlledDomainService::GetDomainAndRegistry(domain); |
| 520 | 519 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 581 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 583 "secure, httponly, last_access_utc, has_expires, persistent " | 582 "secure, httponly, last_access_utc, has_expires, persistent " |
| 584 "FROM cookies WHERE host_key = ?")); | 583 "FROM cookies WHERE host_key = ?")); |
| 585 } else { | 584 } else { |
| 586 smt.Assign(db_->GetCachedStatement( | 585 smt.Assign(db_->GetCachedStatement( |
| 587 SQL_FROM_HERE, | 586 SQL_FROM_HERE, |
| 588 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 587 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 589 "secure, httponly, last_access_utc, has_expires, persistent " | 588 "secure, httponly, last_access_utc, has_expires, persistent " |
| 590 "FROM cookies WHERE host_key = ? AND persistent = 1")); | 589 "FROM cookies WHERE host_key = ? AND persistent = 1")); |
| 591 } | 590 } |
| 592 if (!smt) { | 591 if (!smt.is_valid()) { |
| 593 NOTREACHED() << "select statement prep failed"; | |
| 594 db_.reset(); | 592 db_.reset(); |
| 595 return false; | 593 return false; |
| 596 } | 594 } |
| 597 | 595 |
| 598 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 596 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
| 599 std::set<std::string>::const_iterator it = domains.begin(); | 597 std::set<std::string>::const_iterator it = domains.begin(); |
| 600 for (; it != domains.end(); ++it) { | 598 for (; it != domains.end(); ++it) { |
| 601 smt.BindString(0, *it); | 599 smt.BindString(0, *it); |
| 602 while (smt.Step()) { | 600 while (smt.Step()) { |
| 603 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 601 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 783 |
| 786 // Maybe an old timer fired or we are already Close()'ed. | 784 // Maybe an old timer fired or we are already Close()'ed. |
| 787 if (!db_.get() || ops.empty()) | 785 if (!db_.get() || ops.empty()) |
| 788 return; | 786 return; |
| 789 | 787 |
| 790 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 788 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| 791 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " | 789 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " |
| 792 "expires_utc, secure, httponly, last_access_utc, has_expires, " | 790 "expires_utc, secure, httponly, last_access_utc, has_expires, " |
| 793 "persistent) " | 791 "persistent) " |
| 794 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); | 792 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); |
| 795 if (!add_smt) { | 793 if (!add_smt.is_valid()) |
| 796 NOTREACHED(); | |
| 797 return; | 794 return; |
| 798 } | |
| 799 | 795 |
| 800 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 796 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| 801 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); | 797 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); |
| 802 if (!update_access_smt) { | 798 if (!update_access_smt.is_valid()) |
| 803 NOTREACHED(); | |
| 804 return; | 799 return; |
| 805 } | |
| 806 | 800 |
| 807 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, | 801 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, |
| 808 "DELETE FROM cookies WHERE creation_utc=?")); | 802 "DELETE FROM cookies WHERE creation_utc=?")); |
| 809 if (!del_smt) { | 803 if (!del_smt.is_valid()) |
| 810 NOTREACHED(); | |
| 811 return; | 804 return; |
| 812 } | |
| 813 | 805 |
| 814 sql::Transaction transaction(db_.get()); | 806 sql::Transaction transaction(db_.get()); |
| 815 if (!transaction.Begin()) { | 807 if (!transaction.Begin()) |
| 816 NOTREACHED(); | |
| 817 return; | 808 return; |
| 818 } | 809 |
| 819 for (PendingOperationsList::iterator it = ops.begin(); | 810 for (PendingOperationsList::iterator it = ops.begin(); |
| 820 it != ops.end(); ++it) { | 811 it != ops.end(); ++it) { |
| 821 // Free the cookies as we commit them to the database. | 812 // Free the cookies as we commit them to the database. |
| 822 scoped_ptr<PendingOperation> po(*it); | 813 scoped_ptr<PendingOperation> po(*it); |
| 823 switch (po->op()) { | 814 switch (po->op()) { |
| 824 case PendingOperation::COOKIE_ADD: | 815 case PendingOperation::COOKIE_ADD: |
| 825 add_smt.Reset(); | 816 add_smt.Reset(); |
| 826 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); | 817 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); |
| 827 add_smt.BindString(1, po->cc().Domain()); | 818 add_smt.BindString(1, po->cc().Domain()); |
| 828 add_smt.BindString(2, po->cc().Name()); | 819 add_smt.BindString(2, po->cc().Name()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 if (backend_.get()) | 954 if (backend_.get()) |
| 964 backend_->SetClearLocalStateOnExit(clear_local_state); | 955 backend_->SetClearLocalStateOnExit(clear_local_state); |
| 965 } | 956 } |
| 966 | 957 |
| 967 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 958 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
| 968 if (backend_.get()) | 959 if (backend_.get()) |
| 969 backend_->Flush(callback); | 960 backend_->Flush(callback); |
| 970 else if (!callback.is_null()) | 961 else if (!callback.is_null()) |
| 971 MessageLoop::current()->PostTask(FROM_HERE, callback); | 962 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 972 } | 963 } |
| OLD | NEW |