OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // show_in_default_list | 49 // show_in_default_list |
50 // safe_for_autoreplace | 50 // safe_for_autoreplace |
51 // originating_url | 51 // originating_url |
52 // date_created This column was added after we allowed keywords. | 52 // date_created This column was added after we allowed keywords. |
53 // Keywords created before we started tracking | 53 // Keywords created before we started tracking |
54 // creation date have a value of 0 for this. | 54 // creation date have a value of 0 for this. |
55 // usage_count | 55 // usage_count |
56 // input_encodings Semicolon separated list of supported input | 56 // input_encodings Semicolon separated list of supported input |
57 // encodings, may be empty. | 57 // encodings, may be empty. |
58 // suggest_url | 58 // suggest_url |
59 // prepopulate_id See TemplateURL::prepoulate_id. | 59 // prepopulate_id See TemplateURL::prepopulate_id. |
60 // autogenerate_keyword | 60 // autogenerate_keyword |
| 61 // logo_id See TemplateURL::logo_id |
61 // | 62 // |
62 // logins | 63 // logins |
63 // origin_url | 64 // origin_url |
64 // action_url | 65 // action_url |
65 // username_element | 66 // username_element |
66 // username_value | 67 // username_value |
67 // password_element | 68 // password_element |
68 // password_value | 69 // password_value |
69 // submit_element | 70 // submit_element |
70 // signon_realm The authority (scheme, host, port). | 71 // signon_realm The authority (scheme, host, port). |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // | 151 // |
151 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
152 | 153 |
153 using base::Time; | 154 using base::Time; |
154 | 155 |
155 namespace { | 156 namespace { |
156 | 157 |
157 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; | 158 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; |
158 | 159 |
159 // Current version number. | 160 // Current version number. |
160 const int kCurrentVersionNumber = 24; | 161 const int kCurrentVersionNumber = 25; |
161 const int kCompatibleVersionNumber = 21; | 162 const int kCompatibleVersionNumber = 25; |
| 163 const int kUrlIdPosition = 14; |
162 | 164 |
163 // Keys used in the meta table. | 165 // Keys used in the meta table. |
164 const char* kDefaultSearchProviderKey = "Default Search Provider ID"; | 166 const char* kDefaultSearchProviderKey = "Default Search Provider ID"; |
165 const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; | 167 const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; |
166 | 168 |
167 // The maximum length allowed for form data. | 169 // The maximum length allowed for form data. |
168 const size_t kMaxDataLength = 1024; | 170 const size_t kMaxDataLength = 1024; |
169 | 171 |
170 std::string JoinStrings(const std::string& separator, | 172 std::string JoinStrings(const std::string& separator, |
171 const std::vector<std::string>& strings) { | 173 const std::vector<std::string>& strings) { |
(...skipping 30 matching lines...) Expand all Loading... |
202 s->BindInt64(6, url.date_created().ToTimeT()); | 204 s->BindInt64(6, url.date_created().ToTimeT()); |
203 s->BindInt(7, url.usage_count()); | 205 s->BindInt(7, url.usage_count()); |
204 s->BindString(8, JoinStrings(";", url.input_encodings())); | 206 s->BindString(8, JoinStrings(";", url.input_encodings())); |
205 s->BindInt(9, url.show_in_default_list() ? 1 : 0); | 207 s->BindInt(9, url.show_in_default_list() ? 1 : 0); |
206 if (url.suggestions_url()) | 208 if (url.suggestions_url()) |
207 s->BindString(10, url.suggestions_url()->url()); | 209 s->BindString(10, url.suggestions_url()->url()); |
208 else | 210 else |
209 s->BindString(10, std::string()); | 211 s->BindString(10, std::string()); |
210 s->BindInt(11, url.prepopulate_id()); | 212 s->BindInt(11, url.prepopulate_id()); |
211 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0); | 213 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0); |
| 214 s->BindInt(13, url.logo_id()); |
212 } | 215 } |
213 | 216 |
214 void InitPasswordFormFromStatement(PasswordForm* form, sql::Statement* s) { | 217 void InitPasswordFormFromStatement(PasswordForm* form, sql::Statement* s) { |
215 std::string tmp; | 218 std::string tmp; |
216 string16 decrypted_password; | 219 string16 decrypted_password; |
217 tmp = s->ColumnString(0); | 220 tmp = s->ColumnString(0); |
218 form->origin = GURL(tmp); | 221 form->origin = GURL(tmp); |
219 tmp = s->ColumnString(1); | 222 tmp = s->ColumnString(1); |
220 form->action = GURL(tmp); | 223 form->action = GURL(tmp); |
221 form->username_element = s->ColumnString16(2); | 224 form->username_element = s->ColumnString16(2); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 "favicon_url VARCHAR NOT NULL," | 619 "favicon_url VARCHAR NOT NULL," |
617 "url VARCHAR NOT NULL," | 620 "url VARCHAR NOT NULL," |
618 "show_in_default_list INTEGER," | 621 "show_in_default_list INTEGER," |
619 "safe_for_autoreplace INTEGER," | 622 "safe_for_autoreplace INTEGER," |
620 "originating_url VARCHAR," | 623 "originating_url VARCHAR," |
621 "date_created INTEGER DEFAULT 0," | 624 "date_created INTEGER DEFAULT 0," |
622 "usage_count INTEGER DEFAULT 0," | 625 "usage_count INTEGER DEFAULT 0," |
623 "input_encodings VARCHAR," | 626 "input_encodings VARCHAR," |
624 "suggest_url VARCHAR," | 627 "suggest_url VARCHAR," |
625 "prepopulate_id INTEGER DEFAULT 0," | 628 "prepopulate_id INTEGER DEFAULT 0," |
626 "autogenerate_keyword INTEGER DEFAULT 0)")) { | 629 "autogenerate_keyword INTEGER DEFAULT 0," |
| 630 "logo_id INTEGER DEFAULT 0)")) { |
627 NOTREACHED(); | 631 NOTREACHED(); |
628 return false; | 632 return false; |
629 } | 633 } |
630 } | 634 } |
631 return true; | 635 return true; |
632 } | 636 } |
633 | 637 |
634 bool WebDatabase::InitLoginsTable() { | 638 bool WebDatabase::InitLoginsTable() { |
635 if (!db_.DoesTableExist("logins")) { | 639 if (!db_.DoesTableExist("logins")) { |
636 if (!db_.Execute("CREATE TABLE logins (" | 640 if (!db_.Execute("CREATE TABLE logins (" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 return true; | 826 return true; |
823 } | 827 } |
824 | 828 |
825 bool WebDatabase::AddKeyword(const TemplateURL& url) { | 829 bool WebDatabase::AddKeyword(const TemplateURL& url) { |
826 DCHECK(url.id()); | 830 DCHECK(url.id()); |
827 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, | 831 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, |
828 "INSERT INTO keywords " | 832 "INSERT INTO keywords " |
829 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " | 833 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " |
830 "originating_url, date_created, usage_count, input_encodings, " | 834 "originating_url, date_created, usage_count, input_encodings, " |
831 "show_in_default_list, suggest_url, prepopulate_id, " | 835 "show_in_default_list, suggest_url, prepopulate_id, " |
832 "autogenerate_keyword, id) VALUES " | 836 "autogenerate_keyword, logo_id, id) VALUES " |
833 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 837 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
834 if (!s) { | 838 if (!s) { |
835 NOTREACHED() << "Statement prepare failed"; | 839 NOTREACHED() << "Statement prepare failed"; |
836 return false; | 840 return false; |
837 } | 841 } |
838 BindURLToStatement(url, &s); | 842 BindURLToStatement(url, &s); |
839 s.BindInt64(13, url.id()); | 843 s.BindInt64(kUrlIdPosition, url.id()); |
840 if (!s.Run()) { | 844 if (!s.Run()) { |
841 NOTREACHED(); | 845 NOTREACHED(); |
842 return false; | 846 return false; |
843 } | 847 } |
844 return true; | 848 return true; |
845 } | 849 } |
846 | 850 |
847 bool WebDatabase::RemoveKeyword(TemplateURL::IDType id) { | 851 bool WebDatabase::RemoveKeyword(TemplateURL::IDType id) { |
848 DCHECK(id); | 852 DCHECK(id); |
849 sql::Statement s(db_.GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); | 853 sql::Statement s(db_.GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); |
850 if (!s) { | 854 if (!s) { |
851 NOTREACHED() << "Statement prepare failed"; | 855 NOTREACHED() << "Statement prepare failed"; |
852 return false; | 856 return false; |
853 } | 857 } |
854 s.BindInt64(0, id); | 858 s.BindInt64(0, id); |
855 return s.Run(); | 859 return s.Run(); |
856 } | 860 } |
857 | 861 |
858 bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { | 862 bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { |
859 sql::Statement s(db_.GetUniqueStatement( | 863 sql::Statement s(db_.GetUniqueStatement( |
860 "SELECT id, short_name, keyword, favicon_url, url, " | 864 "SELECT id, short_name, keyword, favicon_url, url, " |
861 "safe_for_autoreplace, originating_url, date_created, " | 865 "safe_for_autoreplace, originating_url, date_created, " |
862 "usage_count, input_encodings, show_in_default_list, " | 866 "usage_count, input_encodings, show_in_default_list, " |
863 "suggest_url, prepopulate_id, autogenerate_keyword " | 867 "suggest_url, prepopulate_id, autogenerate_keyword, logo_id " |
864 "FROM keywords ORDER BY id ASC")); | 868 "FROM keywords ORDER BY id ASC")); |
865 if (!s) { | 869 if (!s) { |
866 NOTREACHED() << "Statement prepare failed"; | 870 NOTREACHED() << "Statement prepare failed"; |
867 return false; | 871 return false; |
868 } | 872 } |
869 while (s.Step()) { | 873 while (s.Step()) { |
870 TemplateURL* template_url = new TemplateURL(); | 874 TemplateURL* template_url = new TemplateURL(); |
871 template_url->set_id(s.ColumnInt64(0)); | 875 template_url->set_id(s.ColumnInt64(0)); |
872 | 876 |
873 std::string tmp; | 877 std::string tmp; |
(...skipping 27 matching lines...) Expand all Loading... |
901 | 905 |
902 template_url->set_show_in_default_list(s.ColumnInt(10) == 1); | 906 template_url->set_show_in_default_list(s.ColumnInt(10) == 1); |
903 | 907 |
904 tmp = s.ColumnString(11); | 908 tmp = s.ColumnString(11); |
905 template_url->SetSuggestionsURL(tmp, 0, 0); | 909 template_url->SetSuggestionsURL(tmp, 0, 0); |
906 | 910 |
907 template_url->set_prepopulate_id(s.ColumnInt(12)); | 911 template_url->set_prepopulate_id(s.ColumnInt(12)); |
908 | 912 |
909 template_url->set_autogenerate_keyword(s.ColumnInt(13) == 1); | 913 template_url->set_autogenerate_keyword(s.ColumnInt(13) == 1); |
910 | 914 |
| 915 template_url->set_logo_id(s.ColumnInt(14)); |
| 916 |
911 urls->push_back(template_url); | 917 urls->push_back(template_url); |
912 } | 918 } |
913 return s.Succeeded(); | 919 return s.Succeeded(); |
914 } | 920 } |
915 | 921 |
916 bool WebDatabase::UpdateKeyword(const TemplateURL& url) { | 922 bool WebDatabase::UpdateKeyword(const TemplateURL& url) { |
917 DCHECK(url.id()); | 923 DCHECK(url.id()); |
918 sql::Statement s(db_.GetUniqueStatement( | 924 sql::Statement s(db_.GetUniqueStatement( |
919 "UPDATE keywords " | 925 "UPDATE keywords " |
920 "SET short_name=?, keyword=?, favicon_url=?, url=?, " | 926 "SET short_name=?, keyword=?, favicon_url=?, url=?, " |
921 "safe_for_autoreplace=?, originating_url=?, date_created=?, " | 927 "safe_for_autoreplace=?, originating_url=?, date_created=?, " |
922 "usage_count=?, input_encodings=?, show_in_default_list=?, " | 928 "usage_count=?, input_encodings=?, show_in_default_list=?, " |
923 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=? " | 929 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, " |
924 "WHERE id=?")); | 930 "logo_id=? WHERE id=?")); |
925 if (!s) { | 931 if (!s) { |
926 NOTREACHED() << "Statement prepare failed"; | 932 NOTREACHED() << "Statement prepare failed"; |
927 return false; | 933 return false; |
928 } | 934 } |
929 BindURLToStatement(url, &s); | 935 BindURLToStatement(url, &s); |
930 s.BindInt64(13, url.id()); | 936 s.BindInt64(kUrlIdPosition, url.id()); |
931 return s.Run(); | 937 return s.Run(); |
932 } | 938 } |
933 | 939 |
934 bool WebDatabase::SetDefaultSearchProviderID(int64 id) { | 940 bool WebDatabase::SetDefaultSearchProviderID(int64 id) { |
935 return meta_table_.SetValue(kDefaultSearchProviderKey, id); | 941 return meta_table_.SetValue(kDefaultSearchProviderKey, id); |
936 } | 942 } |
937 | 943 |
938 int64 WebDatabase::GetDefaulSearchProviderID() { | 944 int64 WebDatabase::GetDefaulSearchProviderID() { |
939 int64 value = 0; | 945 int64 value = 0; |
940 meta_table_.GetValue(kDefaultSearchProviderKey, &value); | 946 meta_table_.GetValue(kDefaultSearchProviderKey, &value); |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 NOTREACHED(); | 1973 NOTREACHED(); |
1968 LOG(WARNING) << "Unable to update web database to version 24."; | 1974 LOG(WARNING) << "Unable to update web database to version 24."; |
1969 return; | 1975 return; |
1970 } | 1976 } |
1971 | 1977 |
1972 meta_table_.SetVersionNumber(24); | 1978 meta_table_.SetVersionNumber(24); |
1973 | 1979 |
1974 // FALL THROUGH | 1980 // FALL THROUGH |
1975 } | 1981 } |
1976 | 1982 |
| 1983 case 24: |
| 1984 // Add the logo_id column. |
| 1985 if (!db_.Execute("ALTER TABLE keywords ADD COLUMN logo_id " |
| 1986 "INTEGER DEFAULT 0")) { |
| 1987 NOTREACHED(); |
| 1988 LOG(WARNING) << "Unable to update web database to version 25."; |
| 1989 return; |
| 1990 } |
| 1991 meta_table_.SetVersionNumber(25); |
| 1992 meta_table_.SetCompatibleVersionNumber( |
| 1993 std::min(25, kCompatibleVersionNumber)); |
| 1994 // FALL THROUGH |
| 1995 |
1977 // Add successive versions here. Each should set the version number and | 1996 // Add successive versions here. Each should set the version number and |
1978 // compatible version number as appropriate, then fall through to the next | 1997 // compatible version number as appropriate, then fall through to the next |
1979 // case. | 1998 // case. |
1980 | 1999 |
1981 case kCurrentVersionNumber: | 2000 case kCurrentVersionNumber: |
1982 // No migration needed. | 2001 // No migration needed. |
1983 return; | 2002 return; |
1984 } | 2003 } |
1985 } | 2004 } |
OLD | NEW |