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

Side by Side Diff: chrome/browser/webdata/web_database.cc

Issue 28292: Convert encryptor.cc and friends to string16. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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) 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/browser/webdata/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Keys used in the meta table. 111 // Keys used in the meta table.
112 static const char* kDefaultSearchProviderKey = "Default Search Provider ID"; 112 static const char* kDefaultSearchProviderKey = "Default Search Provider ID";
113 static const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; 113 static const char* kBuiltinKeywordVersion = "Builtin Keyword Version";
114 114
115 std::string JoinStrings(const std::string& separator, 115 std::string JoinStrings(const std::string& separator,
116 const std::vector<std::string>& strings) { 116 const std::vector<std::string>& strings) {
117 if (strings.empty()) 117 if (strings.empty())
118 return std::string(); 118 return std::string();
119 std::vector<std::string>::const_iterator i(strings.begin()); 119 std::vector<std::string>::const_iterator i(strings.begin());
120 std::string result(*i); 120 std::string result(*i);
121 while(++i != strings.end()) 121 while (++i != strings.end())
122 result += separator + *i; 122 result += separator + *i;
123 return result; 123 return result;
124 } 124 }
125 125
126 WebDatabase::WebDatabase() : db_(NULL), transaction_nesting_(0) { 126 WebDatabase::WebDatabase() : db_(NULL), transaction_nesting_(0) {
127 } 127 }
128 128
129 WebDatabase::~WebDatabase() { 129 WebDatabase::~WebDatabase() {
130 if (db_) { 130 if (db_) {
131 DCHECK(transaction_nesting_ == 0) << 131 DCHECK(transaction_nesting_ == 0) <<
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") != SQLITE_OK) { 634 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") != SQLITE_OK) {
635 NOTREACHED() << "Statement prepare failed"; 635 NOTREACHED() << "Statement prepare failed";
636 return false; 636 return false;
637 } 637 }
638 638
639 s.bind_string(0, form.origin.spec()); 639 s.bind_string(0, form.origin.spec());
640 s.bind_string(1, form.action.spec()); 640 s.bind_string(1, form.action.spec());
641 s.bind_wstring(2, form.username_element); 641 s.bind_wstring(2, form.username_element);
642 s.bind_wstring(3, form.username_value); 642 s.bind_wstring(3, form.username_value);
643 s.bind_wstring(4, form.password_element); 643 s.bind_wstring(4, form.password_element);
644 Encryptor::EncryptWideString(form.password_value, &encrypted_password); 644 Encryptor::EncryptString16(WideToUTF16Hack(form.password_value),
645 &encrypted_password);
645 s.bind_blob(5, encrypted_password.data(), 646 s.bind_blob(5, encrypted_password.data(),
646 static_cast<int>(encrypted_password.length())); 647 static_cast<int>(encrypted_password.length()));
647 s.bind_wstring(6, form.submit_element); 648 s.bind_wstring(6, form.submit_element);
648 s.bind_string(7, form.signon_realm); 649 s.bind_string(7, form.signon_realm);
649 s.bind_int(8, form.ssl_valid); 650 s.bind_int(8, form.ssl_valid);
650 s.bind_int(9, form.preferred); 651 s.bind_int(9, form.preferred);
651 s.bind_int64(10, form.date_created.ToTimeT()); 652 s.bind_int64(10, form.date_created.ToTimeT());
652 s.bind_int(11, form.blacklisted_by_user); 653 s.bind_int(11, form.blacklisted_by_user);
653 s.bind_int(12, form.scheme); 654 s.bind_int(12, form.scheme);
654 if (s.step() != SQLITE_DONE) { 655 if (s.step() != SQLITE_DONE) {
(...skipping 14 matching lines...) Expand all
669 "WHERE origin_url = ? AND " 670 "WHERE origin_url = ? AND "
670 "username_element = ? AND " 671 "username_element = ? AND "
671 "username_value = ? AND " 672 "username_value = ? AND "
672 "password_element = ? AND " 673 "password_element = ? AND "
673 "signon_realm = ?") != SQLITE_OK) { 674 "signon_realm = ?") != SQLITE_OK) {
674 NOTREACHED() << "Statement prepare failed"; 675 NOTREACHED() << "Statement prepare failed";
675 return false; 676 return false;
676 } 677 }
677 678
678 s.bind_string(0, form.action.spec()); 679 s.bind_string(0, form.action.spec());
679 Encryptor::EncryptWideString(form.password_value, &encrypted_password); 680 Encryptor::EncryptString16(WideToUTF16Hack(form.password_value),
681 &encrypted_password);
680 s.bind_blob(1, encrypted_password.data(), 682 s.bind_blob(1, encrypted_password.data(),
681 static_cast<int>(encrypted_password.length())); 683 static_cast<int>(encrypted_password.length()));
682 s.bind_int(2, form.ssl_valid); 684 s.bind_int(2, form.ssl_valid);
683 s.bind_int(3, form.preferred); 685 s.bind_int(3, form.preferred);
684 s.bind_string(4, form.origin.spec()); 686 s.bind_string(4, form.origin.spec());
685 s.bind_wstring(5, form.username_element); 687 s.bind_wstring(5, form.username_element);
686 s.bind_wstring(6, form.username_value); 688 s.bind_wstring(6, form.username_value);
687 s.bind_wstring(7, form.password_element); 689 s.bind_wstring(7, form.password_element);
688 s.bind_string(8, form.signon_realm); 690 s.bind_string(8, form.signon_realm);
689 691
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 std::numeric_limits<int64>::max() : 752 std::numeric_limits<int64>::max() :
751 delete_end.ToTimeT()); 753 delete_end.ToTimeT());
752 754
753 return s1.step() == SQLITE_DONE && s2.step() == SQLITE_DONE; 755 return s1.step() == SQLITE_DONE && s2.step() == SQLITE_DONE;
754 } 756 }
755 757
756 static void InitPasswordFormFromStatement(PasswordForm* form, 758 static void InitPasswordFormFromStatement(PasswordForm* form,
757 SQLStatement* s) { 759 SQLStatement* s) {
758 std::string encrypted_password; 760 std::string encrypted_password;
759 std::string tmp; 761 std::string tmp;
762 string16 decrypted_password;
760 s->column_string(0, &tmp); 763 s->column_string(0, &tmp);
761 form->origin = GURL(tmp); 764 form->origin = GURL(tmp);
762 s->column_string(1, &tmp); 765 s->column_string(1, &tmp);
763 form->action = GURL(tmp); 766 form->action = GURL(tmp);
764 s->column_wstring(2, &form->username_element); 767 s->column_wstring(2, &form->username_element);
765 s->column_wstring(3, &form->username_value); 768 s->column_wstring(3, &form->username_value);
766 s->column_wstring(4, &form->password_element); 769 s->column_wstring(4, &form->password_element);
767 s->column_blob_as_string(5, &encrypted_password); 770 s->column_blob_as_string(5, &encrypted_password);
768 Encryptor::DecryptWideString(encrypted_password, &form->password_value); 771 Encryptor::DecryptString16(encrypted_password, &decrypted_password);
772 form->password_value = UTF16ToWideHack(decrypted_password);
769 s->column_wstring(6, &form->submit_element); 773 s->column_wstring(6, &form->submit_element);
770 s->column_string(7, &tmp); 774 s->column_string(7, &tmp);
771 form->signon_realm = tmp; 775 form->signon_realm = tmp;
772 form->ssl_valid = (s->column_int(8) > 0); 776 form->ssl_valid = (s->column_int(8) > 0);
773 form->preferred = (s->column_int(9) > 0); 777 form->preferred = (s->column_int(9) > 0);
774 form->date_created = Time::FromTimeT(s->column_int64(10)); 778 form->date_created = Time::FromTimeT(s->column_int64(10));
775 form->blacklisted_by_user = (s->column_int(11) > 0); 779 form->blacklisted_by_user = (s->column_int(11) > 0);
776 int scheme_int = s->column_int(12); 780 int scheme_int = s->column_int(12);
777 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER)); 781 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER));
778 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); 782 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 } 860 }
857 861
858 std::set<int64> ids; 862 std::set<int64> ids;
859 int result; 863 int result;
860 while ((result = s.step()) == SQLITE_ROW) 864 while ((result = s.step()) == SQLITE_ROW)
861 ids.insert(s.column_int64(0)); 865 ids.insert(s.column_int64(0));
862 866
863 bool success = true; 867 bool success = true;
864 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); 868 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end();
865 ++iter) { 869 ++iter) {
866 if (!RemoveFormElement(*iter)) 870 if (!RemoveFormElement(*iter))
867 success = false; 871 success = false;
868 } 872 }
869 873
870 return success; 874 return success;
871 } 875 }
872 876
873 bool WebDatabase::GetIDAndCountOfFormElement( 877 bool WebDatabase::GetIDAndCountOfFormElement(
874 const AutofillForm::Element& element, int64* pair_id, int* count) { 878 const AutofillForm::Element& element, int64* pair_id, int* count) {
875 SQLStatement s; 879 SQLStatement s;
876 880
877 if (s.prepare(db_, "SELECT pair_id, count FROM autofill " 881 if (s.prepare(db_, "SELECT pair_id, count FROM autofill "
878 " WHERE name = ? AND value = ?") != SQLITE_OK) { 882 " WHERE name = ? AND value = ?") != SQLITE_OK) {
879 NOTREACHED() << "Statement prepare failed"; 883 NOTREACHED() << "Statement prepare failed";
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 bool WebDatabase::RemoveFormElementsAddedBetween(const Time delete_begin, 1056 bool WebDatabase::RemoveFormElementsAddedBetween(const Time delete_begin,
1053 const Time delete_end) { 1057 const Time delete_end) {
1054 SQLStatement s; 1058 SQLStatement s;
1055 if (s.prepare(db_, 1059 if (s.prepare(db_,
1056 "SELECT DISTINCT pair_id FROM autofill_dates WHERE " 1060 "SELECT DISTINCT pair_id FROM autofill_dates WHERE "
1057 "date_created >= ? AND date_created < ?") != SQLITE_OK) { 1061 "date_created >= ? AND date_created < ?") != SQLITE_OK) {
1058 NOTREACHED() << "Statement 1 prepare failed"; 1062 NOTREACHED() << "Statement 1 prepare failed";
1059 return false; 1063 return false;
1060 } 1064 }
1061 s.bind_int64(0, delete_begin.ToTimeT()); 1065 s.bind_int64(0, delete_begin.ToTimeT());
1062 s.bind_int64(1, 1066 s.bind_int64(1,
1063 delete_end.is_null() ? 1067 delete_end.is_null() ?
1064 std::numeric_limits<int64>::max() : 1068 std::numeric_limits<int64>::max() :
1065 delete_end.ToTimeT()); 1069 delete_end.ToTimeT());
1066 1070
1067 std::vector<int64> pair_ids; 1071 std::vector<int64> pair_ids;
1068 int result; 1072 int result;
1069 while ((result = s.step()) == SQLITE_ROW) 1073 while ((result = s.step()) == SQLITE_ROW)
1070 pair_ids.push_back(s.column_int64(0)); 1074 pair_ids.push_back(s.column_int64(0));
1071 1075
1072 if (result != SQLITE_DONE) { 1076 if (result != SQLITE_DONE) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 delete_end.ToTimeT()); 1110 delete_end.ToTimeT());
1107 1111
1108 bool result = (s.step() == SQLITE_DONE); 1112 bool result = (s.step() == SQLITE_DONE);
1109 if (how_many) 1113 if (how_many)
1110 *how_many = sqlite3_changes(db_); 1114 *how_many = sqlite3_changes(db_);
1111 1115
1112 return result; 1116 return result;
1113 } 1117 }
1114 1118
1115 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { 1119 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) {
1116 int count=0; 1120 int count = 0;
1117 1121
1118 if (!GetCountOfFormElement(pair_id, &count)) 1122 if (!GetCountOfFormElement(pair_id, &count))
1119 return false; 1123 return false;
1120 1124
1121 if (count + delta == 0) { 1125 if (count + delta == 0) {
1122 if (!RemoveFormElement(pair_id)) 1126 if (!RemoveFormElement(pair_id))
1123 return false; 1127 return false;
1124 } else { 1128 } else {
1125 if (!SetCountOfFormElement(pair_id, count + delta)) 1129 if (!SetCountOfFormElement(pair_id, count + delta))
1126 return false; 1130 return false;
(...skipping 11 matching lines...) Expand all
1138 s.bind_int64(0, pair_id); 1142 s.bind_int64(0, pair_id);
1139 if (s.step() != SQLITE_DONE) 1143 if (s.step() != SQLITE_DONE)
1140 return false; 1144 return false;
1141 1145
1142 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL); 1146 return RemoveFormElementForTimeRange(pair_id, Time(), Time(), NULL);
1143 } 1147 }
1144 1148
1145 void WebDatabase::MigrateOldVersionsAsNeeded() { 1149 void WebDatabase::MigrateOldVersionsAsNeeded() {
1146 // Migrate if necessary. 1150 // Migrate if necessary.
1147 int current_version = meta_table_.GetVersionNumber(); 1151 int current_version = meta_table_.GetVersionNumber();
1148 switch(current_version) { 1152 switch (current_version) {
1149 // Versions 1 - 19 are unhandled. Version numbers greater than 1153 // Versions 1 - 19 are unhandled. Version numbers greater than
1150 // kCurrentVersionNumber should have already been weeded out by the caller. 1154 // kCurrentVersionNumber should have already been weeded out by the caller.
1151 default: 1155 default:
1152 // When the version is too old, we just try to continue anyway. There 1156 // When the version is too old, we just try to continue anyway. There
1153 // should not be a released product that makes a database too old for us 1157 // should not be a released product that makes a database too old for us
1154 // to handle. 1158 // to handle.
1155 LOG(WARNING) << "Web database version " << current_version << 1159 LOG(WARNING) << "Web database version " << current_version <<
1156 " is too old to handle."; 1160 " is too old to handle.";
1157 return; 1161 return;
1158 1162
(...skipping 22 matching lines...) Expand all
1181 1185
1182 // Add successive versions here. Each should set the version number and 1186 // Add successive versions here. Each should set the version number and
1183 // compatible version number as appropriate, then fall through to the next 1187 // compatible version number as appropriate, then fall through to the next
1184 // case. 1188 // case.
1185 1189
1186 case kCurrentVersionNumber: 1190 case kCurrentVersionNumber:
1187 // No migration needed. 1191 // No migration needed.
1188 return; 1192 return;
1189 } 1193 }
1190 } 1194 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/encryptor_unittest.cc ('k') | chrome/common/temp_scaffolding_stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698