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

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

Issue 201099: Convert the sqlite cookie database and web database to use the new sqlite... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
« no previous file with comments | « chrome/browser/webdata/web_data_service.cc ('k') | chrome/browser/webdata/web_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_H__ 5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H__ 6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "app/sql/connection.h"
12 #include "app/sql/meta_table.h"
11 #include "base/basictypes.h" 13 #include "base/basictypes.h"
12 #include "chrome/browser/meta_table_helper.h" 14 #include "chrome/browser/meta_table_helper.h"
13 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/common/sqlite_utils.h" 16 #include "chrome/common/sqlite_utils.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "testing/gtest/include/gtest/gtest_prod.h" 18 #include "testing/gtest/include/gtest/gtest_prod.h"
17 #include "webkit/glue/autofill_form.h" 19 #include "webkit/glue/autofill_form.h"
18 20
21 class FilePath;
22
19 namespace base { 23 namespace base {
20 class Time; 24 class Time;
21 } 25 }
22 26
23 namespace webkit_glue { 27 namespace webkit_glue {
24 struct PasswordForm; 28 struct PasswordForm;
25 } 29 }
26 30
27 #if defined(OS_WIN) 31 #if defined(OS_WIN)
28 struct IE7PasswordInfo; 32 struct IE7PasswordInfo;
29 #endif 33 #endif
30 34
31 //////////////////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////////////////
32 // 36 //
33 // A Sqlite database instance to store all the meta data we have about web pages 37 // A Sqlite database instance to store all the meta data we have about web pages
34 // 38 //
35 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
36 class WebDatabase { 40 class WebDatabase {
37 public: 41 public:
38 WebDatabase(); 42 WebDatabase();
39 ~WebDatabase(); 43 ~WebDatabase();
40 44
41 // Initialize the database given a name. The name defines where the sqlite 45 // Initialize the database given a name. The name defines where the sqlite
42 // file is. If false is returned, no other method should be called. 46 // file is. If false is returned, no other method should be called.
43 bool Init(const std::wstring& db_name); 47 bool Init(const FilePath& db_name);
44 48
45 // Transactions management 49 // Transactions management
46 void BeginTransaction(); 50 void BeginTransaction();
47 void CommitTransaction(); 51 void CommitTransaction();
48 52
49 ////////////////////////////////////////////////////////////////////////////// 53 //////////////////////////////////////////////////////////////////////////////
50 // 54 //
51 // Keywords 55 // Keywords
52 // 56 //
53 ////////////////////////////////////////////////////////////////////////////// 57 //////////////////////////////////////////////////////////////////////////////
54 58
55 // Adds a new keyword, updating the id field on success. 59 // Adds a new keyword, updating the id field on success.
56 // Returns true if successful. 60 // Returns true if successful.
57 bool AddKeyword(const TemplateURL& url); 61 bool AddKeyword(const TemplateURL& url);
58 62
59 // Removes the specified keyword. 63 // Removes the specified keyword.
60 // Returns true if successful. 64 // Returns true if successful.
61 bool RemoveKeyword(TemplateURL::IDType id); 65 bool RemoveKeyword(TemplateURL::IDType id);
62 66
63 // Loads the keywords into the specified vector. It's up to the caller to 67 // Loads the keywords into the specified vector. It's up to the caller to
64 // delete the returned objects. 68 // delete the returned objects.
65 // Returns true on success. 69 // Returns true on success.
66 bool GetKeywords(std::vector<TemplateURL*>* urls) const; 70 bool GetKeywords(std::vector<TemplateURL*>* urls);
67 71
68 // Updates the database values for the specified url. 72 // Updates the database values for the specified url.
69 // Returns true on success. 73 // Returns true on success.
70 bool UpdateKeyword(const TemplateURL& url); 74 bool UpdateKeyword(const TemplateURL& url);
71 75
72 // ID (TemplateURL->id) of the default search provider. 76 // ID (TemplateURL->id) of the default search provider.
73 bool SetDefaultSearchProviderID(int64 id); 77 bool SetDefaultSearchProviderID(int64 id);
74 int64 GetDefaulSearchProviderID(); 78 int64 GetDefaulSearchProviderID();
75 79
76 // Version of the builtin keywords. 80 // Version of the builtin keywords.
(...skipping 22 matching lines...) Expand all
99 103
100 // Updates remembered password form. 104 // Updates remembered password form.
101 bool UpdateLogin(const webkit_glue::PasswordForm& form); 105 bool UpdateLogin(const webkit_glue::PasswordForm& form);
102 106
103 // Removes |form| from the list of remembered password forms. 107 // Removes |form| from the list of remembered password forms.
104 bool RemoveLogin(const webkit_glue::PasswordForm& form); 108 bool RemoveLogin(const webkit_glue::PasswordForm& form);
105 109
106 // Removes all logins created from |delete_begin| onwards (inclusive) and 110 // Removes all logins created from |delete_begin| onwards (inclusive) and
107 // before |delete_end|. You may use a null Time value to do an unbounded 111 // before |delete_end|. You may use a null Time value to do an unbounded
108 // delete in either direction. 112 // delete in either direction.
109 bool RemoveLoginsCreatedBetween(const base::Time delete_begin, 113 bool RemoveLoginsCreatedBetween(base::Time delete_begin,
110 const base::Time delete_end); 114 base::Time delete_end);
111 115
112 // Loads a list of matching password forms into the specified vector |forms|. 116 // Loads a list of matching password forms into the specified vector |forms|.
113 // The list will contain all possibly relevant entries to the observed |form|, 117 // The list will contain all possibly relevant entries to the observed |form|,
114 // including blacklisted matches. 118 // including blacklisted matches.
115 bool GetLogins(const webkit_glue::PasswordForm& form, 119 bool GetLogins(const webkit_glue::PasswordForm& form,
116 std::vector<webkit_glue::PasswordForm*>* forms) const; 120 std::vector<webkit_glue::PasswordForm*>* forms);
117 121
118 // Loads the complete list of password forms into the specified vector |forms| 122 // Loads the complete list of password forms into the specified vector |forms|
119 // if include_blacklisted is true, otherwise only loads those which are 123 // if include_blacklisted is true, otherwise only loads those which are
120 // actually autofillable; i.e haven't been blacklisted by the user selecting 124 // actually autofillable; i.e haven't been blacklisted by the user selecting
121 // the 'Never for this site' button. 125 // the 'Never for this site' button.
122 bool GetAllLogins(std::vector<webkit_glue::PasswordForm*>* forms, 126 bool GetAllLogins(std::vector<webkit_glue::PasswordForm*>* forms,
123 bool include_blacklisted) const; 127 bool include_blacklisted);
124 128
125 ////////////////////////////////////////////////////////////////////////////// 129 //////////////////////////////////////////////////////////////////////////////
126 // 130 //
127 // Autofill 131 // Autofill
128 // 132 //
129 ////////////////////////////////////////////////////////////////////////////// 133 //////////////////////////////////////////////////////////////////////////////
130 134
131 // Records the form elements in |elements| in the database in the autofill 135 // Records the form elements in |elements| in the database in the autofill
132 // table. 136 // table.
133 bool AddAutofillFormElements( 137 bool AddAutofillFormElements(
134 const std::vector<webkit_glue::AutofillForm::Element>& elements); 138 const std::vector<webkit_glue::AutofillForm::Element>& elements);
135 139
136 // Records a single form element in in the database in the autofill table. 140 // Records a single form element in in the database in the autofill table.
137 bool AddAutofillFormElement( 141 bool AddAutofillFormElement(
138 const webkit_glue::AutofillForm::Element& element); 142 const webkit_glue::AutofillForm::Element& element);
139 143
140 // Retrieves a vector of all values which have been recorded in the autofill 144 // Retrieves a vector of all values which have been recorded in the autofill
141 // table as the value in a form element with name |name| and which start with 145 // table as the value in a form element with name |name| and which start with
142 // |prefix|. The comparison of the prefix is case insensitive. 146 // |prefix|. The comparison of the prefix is case insensitive.
143 bool GetFormValuesForElementName(const std::wstring& name, 147 bool GetFormValuesForElementName(const std::wstring& name,
144 const std::wstring& prefix, 148 const std::wstring& prefix,
145 std::vector<std::wstring>* values, 149 std::vector<std::wstring>* values,
146 int limit) const; 150 int limit);
147 151
148 // Removes rows from autofill_dates if they were created on or after 152 // Removes rows from autofill_dates if they were created on or after
149 // |delete_begin| and strictly before |delete_end|. Decrements the count of 153 // |delete_begin| and strictly before |delete_end|. Decrements the count of
150 // the corresponding rows in the autofill table, and removes those rows if the 154 // the corresponding rows in the autofill table, and removes those rows if the
151 // count goes to 0. 155 // count goes to 0.
152 bool RemoveFormElementsAddedBetween(const base::Time delete_begin, 156 bool RemoveFormElementsAddedBetween(base::Time delete_begin,
153 const base::Time delete_end); 157 base::Time delete_end);
154 158
155 // Removes from autofill_dates rows with given pair_id where date_created lies 159 // Removes from autofill_dates rows with given pair_id where date_created lies
156 // between delte_begin and delte_end. 160 // between delte_begin and delte_end.
157 bool RemoveFormElementForTimeRange(int64 pair_id, 161 bool RemoveFormElementForTimeRange(int64 pair_id,
158 const base::Time delete_begin, 162 base::Time delete_begin,
159 const base::Time delete_end, 163 base::Time delete_end,
160 int* how_many); 164 int* how_many);
161 165
162 // Increments the count in the row corresponding to |pair_id| by |delta|. 166 // Increments the count in the row corresponding to |pair_id| by |delta|.
163 // Removes the row from the table if the count becomes 0. 167 // Removes the row from the table if the count becomes 0.
164 bool AddToCountOfFormElement(int64 pair_id, int delta); 168 bool AddToCountOfFormElement(int64 pair_id, int delta);
165 169
166 // Gets the pair_id and count entries from name and value specified in 170 // Gets the pair_id and count entries from name and value specified in
167 // |element|. Sets *count to 0 if there is no such row in the table. 171 // |element|. Sets *count to 0 if there is no such row in the table.
168 bool GetIDAndCountOfFormElement( 172 bool GetIDAndCountOfFormElement(
169 const webkit_glue::AutofillForm::Element& element, 173 const webkit_glue::AutofillForm::Element& element,
170 int64* pair_id, 174 int64* pair_id,
171 int* count) const; 175 int* count);
172 176
173 // Gets the count only given the pair_id. 177 // Gets the count only given the pair_id.
174 bool GetCountOfFormElement(int64 pair_id, 178 bool GetCountOfFormElement(int64 pair_id, int* count);
175 int* count) const;
176 179
177 // Updates the count entry in the row corresponding to |pair_id| to |count|. 180 // Updates the count entry in the row corresponding to |pair_id| to |count|.
178 bool SetCountOfFormElement(int64 pair_id, int count); 181 bool SetCountOfFormElement(int64 pair_id, int count);
179 182
180 // Adds a new row to the autofill table with name and value given in 183 // Adds a new row to the autofill table with name and value given in
181 // |element|. Sets *pair_id to the pair_id of the new row. 184 // |element|. Sets *pair_id to the pair_id of the new row.
182 bool InsertFormElement( 185 bool InsertFormElement(
183 const webkit_glue::AutofillForm::Element& element, 186 const webkit_glue::AutofillForm::Element& element,
184 int64* pair_id); 187 int64* pair_id);
185 188
186 // Adds a new row to the autofill_dates table. 189 // Adds a new row to the autofill_dates table.
187 bool InsertPairIDAndDate(int64 pair_id, const base::Time date_created); 190 bool InsertPairIDAndDate(int64 pair_id, base::Time date_created);
188 191
189 // Removes row from the autofill tables given |pair_id|. 192 // Removes row from the autofill tables given |pair_id|.
190 bool RemoveFormElementForID(int64 pair_id); 193 bool RemoveFormElementForID(int64 pair_id);
191 194
192 // Removes row from the autofill tables for the given |name| |value| pair. 195 // Removes row from the autofill tables for the given |name| |value| pair.
193 bool RemoveFormElement(const std::wstring& name, const std::wstring& value); 196 bool RemoveFormElement(const std::wstring& name, const std::wstring& value);
194 197
195 ////////////////////////////////////////////////////////////////////////////// 198 //////////////////////////////////////////////////////////////////////////////
196 // 199 //
197 // Web Apps 200 // Web Apps
198 // 201 //
199 ////////////////////////////////////////////////////////////////////////////// 202 //////////////////////////////////////////////////////////////////////////////
200 203
201 bool SetWebAppImage(const GURL& url, const SkBitmap& image); 204 bool SetWebAppImage(const GURL& url, const SkBitmap& image);
202 bool GetWebAppImages(const GURL& url, std::vector<SkBitmap>* images) const; 205 bool GetWebAppImages(const GURL& url, std::vector<SkBitmap>* images);
203 206
204 bool SetWebAppHasAllImages(const GURL& url, bool has_all_images); 207 bool SetWebAppHasAllImages(const GURL& url, bool has_all_images);
205 bool GetWebAppHasAllImages(const GURL& url) const; 208 bool GetWebAppHasAllImages(const GURL& url);
206 209
207 bool RemoveWebApp(const GURL& url); 210 bool RemoveWebApp(const GURL& url);
208 211
209 private: 212 private:
210 FRIEND_TEST(WebDatabaseTest, Autofill); 213 FRIEND_TEST(WebDatabaseTest, Autofill);
211 214
212 // Removes empty values for autofill that were incorrectly stored in the DB 215 // Removes empty values for autofill that were incorrectly stored in the DB
213 // (see bug http://crbug.com/6111). 216 // (see bug http://crbug.com/6111).
214 // TODO(jcampan): http://crbug.com/7564 remove when we think all users have 217 // TODO(jcampan): http://crbug.com/7564 remove when we think all users have
215 // run this code. 218 // run this code.
216 bool ClearAutofillEmptyValueElements(); 219 bool ClearAutofillEmptyValueElements();
217 220
218 bool InitKeywordsTable(); 221 bool InitKeywordsTable();
219 bool InitLoginsTable(); 222 bool InitLoginsTable();
220 bool InitAutofillTable(); 223 bool InitAutofillTable();
221 bool InitAutofillDatesTable(); 224 bool InitAutofillDatesTable();
222 bool InitWebAppIconsTable(); 225 bool InitWebAppIconsTable();
223 bool InitWebAppsTable(); 226 bool InitWebAppsTable();
224 227
225 void MigrateOldVersionsAsNeeded(); 228 void MigrateOldVersionsAsNeeded();
226 229
227 sqlite3* db_; 230 sql::Connection db_;
228 int transaction_nesting_; 231 sql::MetaTable meta_table_;
229 MetaTableHelper meta_table_;
230 232
231 DISALLOW_COPY_AND_ASSIGN(WebDatabase); 233 DISALLOW_COPY_AND_ASSIGN(WebDatabase);
232 }; 234 };
233 235
234 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H__ 236 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.cc ('k') | chrome/browser/webdata/web_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698