| 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // Otherwise notify on IO thread. | 559 // Otherwise notify on IO thread. |
| 560 if (load_success && keys_to_load_.size() > 0) { | 560 if (load_success && keys_to_load_.size() > 0) { |
| 561 BrowserThread::PostTask( | 561 BrowserThread::PostTask( |
| 562 BrowserThread::DB, FROM_HERE, | 562 BrowserThread::DB, FROM_HERE, |
| 563 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); | 563 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); |
| 564 } else { | 564 } else { |
| 565 BrowserThread::PostTask( | 565 BrowserThread::PostTask( |
| 566 BrowserThread::IO, FROM_HERE, | 566 BrowserThread::IO, FROM_HERE, |
| 567 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, | 567 base::Bind(&SQLitePersistentCookieStore::Backend::CompleteLoadOnIOThread, |
| 568 this, loaded_callback, load_success)); | 568 this, loaded_callback, load_success)); |
| 569 if (!restore_old_session_cookies_) | 569 if (load_success && !restore_old_session_cookies_) |
| 570 DeleteSessionCookies(); | 570 DeleteSessionCookies(); |
| 571 } | 571 } |
| 572 } | 572 } |
| 573 | 573 |
| 574 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( | 574 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( |
| 575 const std::set<std::string>& domains) { | 575 const std::set<std::string>& domains) { |
| 576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 577 | 577 |
| 578 sql::Statement smt; | 578 sql::Statement smt; |
| 579 if (restore_old_session_cookies_) { | 579 if (restore_old_session_cookies_) { |
| 580 smt.Assign(db_->GetCachedStatement( | 580 smt.Assign(db_->GetCachedStatement( |
| 581 SQL_FROM_HERE, | 581 SQL_FROM_HERE, |
| 582 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 582 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 583 "secure, httponly, last_access_utc, has_expires, persistent " | 583 "secure, httponly, last_access_utc, has_expires, persistent " |
| 584 "FROM cookies WHERE host_key = ?")); | 584 "FROM cookies WHERE host_key = ?")); |
| 585 } else { | 585 } else { |
| 586 smt.Assign(db_->GetCachedStatement( | 586 smt.Assign(db_->GetCachedStatement( |
| 587 SQL_FROM_HERE, | 587 SQL_FROM_HERE, |
| 588 "SELECT creation_utc, host_key, name, value, path, expires_utc, " | 588 "SELECT creation_utc, host_key, name, value, path, expires_utc, " |
| 589 "secure, httponly, last_access_utc, has_expires, persistent " | 589 "secure, httponly, last_access_utc, has_expires, persistent " |
| 590 "FROM cookies WHERE host_key = ? AND persistent = 1")); | 590 "FROM cookies WHERE host_key = ? AND persistent = 1")); |
| 591 } | 591 } |
| 592 if (!smt) { | 592 if (!smt.is_valid()) { |
| 593 NOTREACHED() << "select statement prep failed"; | 593 NOTREACHED() << "select statement prep failed"; |
| 594 smt.Clear(); // Disconnect smt_ref from db_. |
| 594 db_.reset(); | 595 db_.reset(); |
| 595 return false; | 596 return false; |
| 596 } | 597 } |
| 597 | 598 |
| 598 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 599 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
| 599 std::set<std::string>::const_iterator it = domains.begin(); | 600 std::set<std::string>::const_iterator it = domains.begin(); |
| 600 for (; it != domains.end(); ++it) { | 601 for (; it != domains.end(); ++it) { |
| 601 smt.BindString(0, *it); | 602 smt.BindString(0, *it); |
| 602 while (smt.Step()) { | 603 while (smt.Step()) { |
| 603 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 604 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 if (backend_.get()) | 964 if (backend_.get()) |
| 964 backend_->SetClearLocalStateOnExit(clear_local_state); | 965 backend_->SetClearLocalStateOnExit(clear_local_state); |
| 965 } | 966 } |
| 966 | 967 |
| 967 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { | 968 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { |
| 968 if (backend_.get()) | 969 if (backend_.get()) |
| 969 backend_->Flush(callback); | 970 backend_->Flush(callback); |
| 970 else if (!callback.is_null()) | 971 else if (!callback.is_null()) |
| 971 MessageLoop::current()->PostTask(FROM_HERE, callback); | 972 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 972 } | 973 } |
| OLD | NEW |