OLD | NEW |
---|---|
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/history/shortcuts_database.h" | 5 #include "chrome/browser/history/shortcuts_database.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) && | 189 static_cast<int>(content::PAGE_TRANSITION_TYPED)).c_str()) && |
190 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") && | 190 db_.Execute("ALTER TABLE omni_box_shortcuts ADD COLUMN type INTEGER") && |
191 db_.Execute(base::StringPrintf( | 191 db_.Execute(base::StringPrintf( |
192 "UPDATE omni_box_shortcuts SET type = %d", | 192 "UPDATE omni_box_shortcuts SET type = %d", |
193 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && | 193 static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) && |
194 db_.Execute("ALTER TABLE omni_box_shortcuts " | 194 db_.Execute("ALTER TABLE omni_box_shortcuts " |
195 "ADD COLUMN keyword VARCHAR") && | 195 "ADD COLUMN keyword VARCHAR") && |
196 transaction.Commit(); | 196 transaction.Commit(); |
197 } | 197 } |
198 | 198 |
199 // With new suggestion types being added, following values have changed: | |
Peter Kasting
2014/02/05 21:59:39
We really should do migration passes based on vers
Anuj
2014/02/10 22:17:30
There is no meta-table in Shortcuts DB. So just co
| |
200 // SEARCH_OTHER_ENGINE -> SEARCH_SUGGEST_ENTITY | |
201 // EXTENSION_APP -> SEARCH_SUGGEST_INFINITE | |
202 // CONTACT -> SEARCH_SUGGEST_PERSONALIZED | |
203 // BOOKMARK_TITLE -> SEARCH_SUGGEST_PROFILE | |
204 sql::Transaction transaction(&db_); | |
205 transaction.Begin(); | |
206 // Migrate old SEARCH_OTHER_ENGINE values to the new type value. | |
207 // The ENTITY suggestion values always have a description and always have a | |
208 // https google search url with gs_ssp parameter. The old SEARCH_OTHER_ENGINE | |
209 // entries will definitely fail the url check, but empty description test is | |
210 // also sufficient and faster. | |
Peter Kasting
2014/02/05 21:59:39
Is it actually necessary to do such sophisticated
Anuj
2014/02/10 22:17:30
I am not sure. I feel if we are bothering to make
Peter Kasting
2014/02/10 22:29:46
I'd probably write the "dumbest" possible code tha
Anuj
2014/02/11 07:20:04
Done.
| |
211 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
212 "SET type = %d " | |
213 "where type = %d AND " | |
214 "(description = '' OR " | |
215 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*&?gs_ssp=.*')", | |
216 static_cast<int>(AutocompleteMatchType::SEARCH_OTHER_ENGINE), | |
Peter Kasting
2014/02/05 21:59:39
For both old and new type values, hardcode the num
Anuj
2014/02/10 22:17:30
Done.
| |
217 static_cast<int>(AutocompleteMatchType::SEARCH_SUGGEST_ENTITY)) | |
218 .c_str()) && | |
Peter Kasting
2014/02/05 21:59:39
Nit: If you're going to chain statements with &&,
Anuj
2014/02/10 22:17:30
They are not indented in the block above - lines
Peter Kasting
2014/02/10 22:29:46
They are, in fact, indented. They're part of the
Anuj
2014/02/11 07:20:04
Done.
| |
219 // Migrate old EXTENSION_APP values to the new type value. | |
220 // The INFINITE suggestions are not launched. So it is safe to update all of | |
221 // them to EXTENSION_APP type wherever the url is not a google search. | |
222 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
223 "SET type = %d " | |
224 "where type = %d AND " | |
225 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*')", | |
226 static_cast<int>(AutocompleteMatchType::EXTENSION_APP), | |
227 static_cast<int>(AutocompleteMatchType::SEARCH_SUGGEST_INFINITE)) | |
228 .c_str()) && | |
229 // Migrate old CONTACT values to the new type value. | |
230 // The PERSONALIZED suggestions are not launched. So it is safe to update all | |
231 // of them to CONTACT type wherever the url is not a google search. | |
232 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
233 "SET type = %d " | |
234 "where type = %d AND " | |
235 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*')", | |
236 static_cast<int>(AutocompleteMatchType::CONTACT), | |
237 static_cast<int>(AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED)) | |
238 .c_str()) && | |
239 // Migrate old BOOKMARK_TITLE values to the new type value. | |
240 // The PROFILE suggestion values always have a description and always have a | |
241 // https google search url with tbs parameter. The old BOOKMARK_TITLE entries | |
242 // will definitely fail the url check, but empty description test is also | |
243 // sufficient and faster. | |
244 db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts " | |
245 "SET type = %d " | |
246 "where type = %d AND " | |
247 "(description = '' OR " | |
248 "url NOT REGEXP '^https://www\\.google\\..*/search\\?.*&?tbs=.*')", | |
249 static_cast<int>(AutocompleteMatchType::BOOKMARK_TITLE), | |
250 static_cast<int>(AutocompleteMatchType::SEARCH_SUGGEST_PROFILE)) | |
251 .c_str()) && | |
252 transaction.Commit(); | |
199 return true; | 253 return true; |
Peter Kasting
2014/02/05 21:59:39
Seems like here we should be returning the result
Anuj
2014/02/10 22:17:30
But we are okay about failing to do this modificat
Peter Kasting
2014/02/10 22:29:46
If you fail to execute one of these statements, so
Anuj
2014/02/11 07:20:04
Done.
| |
200 } | 254 } |
201 | 255 |
202 } // namespace history | 256 } // namespace history |
OLD | NEW |