Chromium Code Reviews| 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/webdata/web_intents_table.h" | 5 #include "chrome/browser/webdata/web_intents_table.h" |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 " UNIQUE (action, scheme, type, url_pattern))")) { | 83 " UNIQUE (action, scheme, type, url_pattern))")) { |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index" | 86 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index" |
| 87 " ON web_intents_defaults (action)")) | 87 " ON web_intents_defaults (action)")) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index" | 90 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index" |
| 91 " ON web_intents_defaults (scheme)")) | 91 " ON web_intents_defaults (scheme)")) |
| 92 return false; | 92 return false; |
| 93 } else { | |
| 94 // For a while, 'scheme' was set to null when setting a web_intents_defaults | |
| 95 // row. Due to a longstanding SQLite bug, a NULL entry in a unique key field | |
| 96 // is always considered distinct from any other NULL entry in that field, | |
| 97 // rendering the uniqueness obsolete. Get rid of any such entries. | |
| 98 if (!db_->Execute("DELETE FROM web_intents_defaults WHERE scheme IS NULL")) | |
|
Steve McKay
2012/09/14 18:57:00
This'll ding startup time. We can do this one and
Greg Billock
2012/09/14 19:12:28
Scott, should we roll DB versions for this?
Scott Hess - ex-Googler
2012/09/14 19:37:47
The UNIQUE constraint will be enforced by a tree k
| |
| 99 return false; | |
| 93 } | 100 } |
| 94 | 101 |
| 102 | |
| 95 return true; | 103 return true; |
| 96 } | 104 } |
| 97 | 105 |
| 98 // TODO(jhawkins): Figure out Sync story. | 106 // TODO(jhawkins): Figure out Sync story. |
| 99 bool WebIntentsTable::IsSyncable() { | 107 bool WebIntentsTable::IsSyncable() { |
| 100 return false; | 108 return false; |
| 101 } | 109 } |
| 102 | 110 |
| 103 // Updates the table by way of renaming the old tables, rerunning | 111 // Updates the table by way of renaming the old tables, rerunning |
| 104 // the Init method, then selecting old values into the new tables. | 112 // the Init method, then selecting old values into the new tables. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 } | 301 } |
| 294 | 302 |
| 295 return s.Succeeded(); | 303 return s.Succeeded(); |
| 296 | 304 |
| 297 } | 305 } |
| 298 | 306 |
| 299 bool WebIntentsTable::SetDefaultService( | 307 bool WebIntentsTable::SetDefaultService( |
| 300 const DefaultWebIntentService& default_service) { | 308 const DefaultWebIntentService& default_service) { |
| 301 sql::Statement s(db_->GetUniqueStatement( | 309 sql::Statement s(db_->GetUniqueStatement( |
| 302 "INSERT OR REPLACE INTO web_intents_defaults " | 310 "INSERT OR REPLACE INTO web_intents_defaults " |
| 303 "(action, type, url_pattern, user_date, suppression, service_url) " | 311 "(action, type, url_pattern, user_date, suppression," |
| 304 "VALUES (?, ?, ?, ?, ?, ?)")); | 312 " service_url, scheme) " |
| 313 "VALUES (?, ?, ?, ?, ?, ?, ?)")); | |
| 305 s.BindString16(0, default_service.action); | 314 s.BindString16(0, default_service.action); |
| 306 s.BindString16(1, default_service.type); | 315 s.BindString16(1, default_service.type); |
| 307 s.BindString(2, default_service.url_pattern.GetAsString()); | 316 s.BindString(2, default_service.url_pattern.GetAsString()); |
| 308 s.BindInt(3, default_service.user_date); | 317 s.BindInt(3, default_service.user_date); |
| 309 s.BindInt64(4, default_service.suppression); | 318 s.BindInt64(4, default_service.suppression); |
| 310 s.BindString(5, default_service.service_url); | 319 s.BindString(5, default_service.service_url); |
| 320 s.BindString16(6, default_service.scheme); | |
| 311 | 321 |
| 312 return s.Run(); | 322 return s.Run(); |
| 313 } | 323 } |
| 314 | 324 |
| 315 bool WebIntentsTable::RemoveDefaultService( | 325 bool WebIntentsTable::RemoveDefaultService( |
| 316 const DefaultWebIntentService& default_service) { | 326 const DefaultWebIntentService& default_service) { |
| 317 sql::Statement s(db_->GetUniqueStatement( | 327 sql::Statement s(db_->GetUniqueStatement( |
| 318 "DELETE FROM web_intents_defaults " | 328 "DELETE FROM web_intents_defaults " |
| 319 "WHERE action = ? AND type = ? AND url_pattern = ?")); | 329 "WHERE action = ? AND type = ? AND url_pattern = ?")); |
| 320 s.BindString16(0, default_service.action); | 330 s.BindString16(0, default_service.action); |
| 321 s.BindString16(1, default_service.type); | 331 s.BindString16(1, default_service.type); |
| 322 s.BindString(2, default_service.url_pattern.GetAsString()); | 332 s.BindString(2, default_service.url_pattern.GetAsString()); |
| 323 | 333 |
| 324 return s.Run(); | 334 return s.Run(); |
| 325 } | 335 } |
| 326 | 336 |
| 327 bool WebIntentsTable::RemoveServiceDefaults(const GURL& service_url) { | 337 bool WebIntentsTable::RemoveServiceDefaults(const GURL& service_url) { |
| 328 sql::Statement s(db_->GetUniqueStatement( | 338 sql::Statement s(db_->GetUniqueStatement( |
| 329 "DELETE FROM web_intents_defaults WHERE service_url = ?")); | 339 "DELETE FROM web_intents_defaults WHERE service_url = ?")); |
| 330 s.BindString(0, service_url.spec()); | 340 s.BindString(0, service_url.spec()); |
| 331 | 341 |
| 332 return s.Run(); | 342 return s.Run(); |
| 333 } | 343 } |
| OLD | NEW |