Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1416)

Side by Side Diff: chrome/browser/net/sqlite_persistent_cookie_store.cc

Issue 9365030: More SQL statement usage regularization. Back-touch some (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.is_valid()) { 591 if (!smt.is_valid()) {
593 NOTREACHED() << "select statement prep failed";
594 smt.Clear(); // Disconnect smt_ref from db_. 592 smt.Clear(); // Disconnect smt_ref from db_.
595 db_.reset(); 593 db_.reset();
596 return false; 594 return false;
597 } 595 }
598 596
599 std::vector<net::CookieMonster::CanonicalCookie*> cookies; 597 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
600 std::set<std::string>::const_iterator it = domains.begin(); 598 std::set<std::string>::const_iterator it = domains.begin();
601 for (; it != domains.end(); ++it) { 599 for (; it != domains.end(); ++it) {
602 smt.BindString(0, *it); 600 smt.BindString(0, *it);
603 while (smt.Step()) { 601 while (smt.Step()) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 784
787 // Maybe an old timer fired or we are already Close()'ed. 785 // Maybe an old timer fired or we are already Close()'ed.
788 if (!db_.get() || ops.empty()) 786 if (!db_.get() || ops.empty())
789 return; 787 return;
790 788
791 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE, 789 sql::Statement add_smt(db_->GetCachedStatement(SQL_FROM_HERE,
792 "INSERT INTO cookies (creation_utc, host_key, name, value, path, " 790 "INSERT INTO cookies (creation_utc, host_key, name, value, path, "
793 "expires_utc, secure, httponly, last_access_utc, has_expires, " 791 "expires_utc, secure, httponly, last_access_utc, has_expires, "
794 "persistent) " 792 "persistent) "
795 "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); 793 "VALUES (?,?,?,?,?,?,?,?,?,?,?)"));
796 if (!add_smt) { 794 if (!add_smt.is_valid())
797 NOTREACHED();
798 return; 795 return;
799 }
800 796
801 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE, 797 sql::Statement update_access_smt(db_->GetCachedStatement(SQL_FROM_HERE,
802 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?")); 798 "UPDATE cookies SET last_access_utc=? WHERE creation_utc=?"));
803 if (!update_access_smt) { 799 if (!update_access_smt.is_valid())
804 NOTREACHED();
805 return; 800 return;
806 }
807 801
808 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE, 802 sql::Statement del_smt(db_->GetCachedStatement(SQL_FROM_HERE,
809 "DELETE FROM cookies WHERE creation_utc=?")); 803 "DELETE FROM cookies WHERE creation_utc=?"));
810 if (!del_smt) { 804 if (!del_smt.is_valid())
811 NOTREACHED();
812 return; 805 return;
813 }
814 806
815 sql::Transaction transaction(db_.get()); 807 sql::Transaction transaction(db_.get());
816 if (!transaction.Begin()) { 808 if (!transaction.Begin())
817 NOTREACHED();
818 return; 809 return;
819 } 810
820 for (PendingOperationsList::iterator it = ops.begin(); 811 for (PendingOperationsList::iterator it = ops.begin();
821 it != ops.end(); ++it) { 812 it != ops.end(); ++it) {
822 // Free the cookies as we commit them to the database. 813 // Free the cookies as we commit them to the database.
823 scoped_ptr<PendingOperation> po(*it); 814 scoped_ptr<PendingOperation> po(*it);
824 switch (po->op()) { 815 switch (po->op()) {
825 case PendingOperation::COOKIE_ADD: 816 case PendingOperation::COOKIE_ADD:
826 add_smt.Reset(); 817 add_smt.Reset();
827 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue()); 818 add_smt.BindInt64(0, po->cc().CreationDate().ToInternalValue());
828 add_smt.BindString(1, po->cc().Domain()); 819 add_smt.BindString(1, po->cc().Domain());
829 add_smt.BindString(2, po->cc().Name()); 820 add_smt.BindString(2, po->cc().Name());
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 if (backend_.get()) 955 if (backend_.get())
965 backend_->SetClearLocalStateOnExit(clear_local_state); 956 backend_->SetClearLocalStateOnExit(clear_local_state);
966 } 957 }
967 958
968 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) { 959 void SQLitePersistentCookieStore::Flush(const base::Closure& callback) {
969 if (backend_.get()) 960 if (backend_.get())
970 backend_->Flush(callback); 961 backend_->Flush(callback);
971 else if (!callback.is_null()) 962 else if (!callback.is_null())
972 MessageLoop::current()->PostTask(FROM_HERE, callback); 963 MessageLoop::current()->PostTask(FROM_HERE, callback);
973 } 964 }
OLDNEW
« no previous file with comments | « chrome/browser/net/sqlite_origin_bound_cert_store.cc ('k') | chrome/browser/password_manager/login_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698