| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/webdata/web_database.h" |
| 12 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/mime_util.h" | 14 #include "net/base/mime_util.h" |
| 14 #include "sql/statement.h" | 15 #include "sql/statement.h" |
| 15 #include "third_party/sqlite/sqlite3.h" | 16 #include "third_party/sqlite/sqlite3.h" |
| 16 | 17 |
| 17 WebIntentsTable::WebIntentsTable(sql::Connection* db, | 18 namespace { |
| 18 sql::MetaTable* meta_table) | 19 |
| 19 : WebDatabaseTable(db, meta_table) { | 20 int table_key = 0; |
| 21 |
| 22 WebDatabaseTable::TypeKey GetKey() { |
| 23 return reinterpret_cast<void*>(&table_key); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 WebIntentsTable::WebIntentsTable() { |
| 20 } | 29 } |
| 21 | 30 |
| 22 WebIntentsTable::~WebIntentsTable() { | 31 WebIntentsTable::~WebIntentsTable() { |
| 23 } | 32 } |
| 24 | 33 |
| 25 bool WebIntentsTable::Init() { | 34 WebIntentsTable* WebIntentsTable::FromWebDatabase(WebDatabase* db) { |
| 35 return static_cast<WebIntentsTable*>(db->GetTable(GetKey())); |
| 36 } |
| 37 |
| 38 WebDatabaseTable::TypeKey WebIntentsTable::GetTypeKey() const { |
| 39 return GetKey(); |
| 40 } |
| 41 |
| 42 bool WebIntentsTable::Init(sql::Connection* db, sql::MetaTable* meta_table) { |
| 43 WebDatabaseTable::Init(db, meta_table); |
| 44 |
| 26 if (!db_->DoesTableExist("web_intents")) { | 45 if (!db_->DoesTableExist("web_intents")) { |
| 27 if (!db_->Execute("CREATE TABLE web_intents (" | 46 if (!db_->Execute("CREATE TABLE web_intents (" |
| 28 " service_url LONGVARCHAR," | 47 " service_url LONGVARCHAR," |
| 29 " action VARCHAR," | 48 " action VARCHAR," |
| 30 " type VARCHAR," | 49 " type VARCHAR," |
| 31 " title LONGVARCHAR," | 50 " title LONGVARCHAR," |
| 32 " disposition VARCHAR," | 51 " disposition VARCHAR," |
| 33 " scheme VARCHAR," | 52 " scheme VARCHAR," |
| 34 " UNIQUE (service_url, action, scheme, type))")) { | 53 " UNIQUE (service_url, action, scheme, type))")) { |
| 35 return false; | 54 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 DLOG(WARNING) << "Could not backup web_intents table."; | 109 DLOG(WARNING) << "Could not backup web_intents table."; |
| 91 return false; | 110 return false; |
| 92 } | 111 } |
| 93 | 112 |
| 94 if (!db_->Execute("ALTER TABLE web_intents_defaults" | 113 if (!db_->Execute("ALTER TABLE web_intents_defaults" |
| 95 " RENAME TO old_web_intents_defaults")) { | 114 " RENAME TO old_web_intents_defaults")) { |
| 96 DLOG(WARNING) << "Could not backup web_intents_defaults table."; | 115 DLOG(WARNING) << "Could not backup web_intents_defaults table."; |
| 97 return false; | 116 return false; |
| 98 } | 117 } |
| 99 | 118 |
| 100 if (!Init()) return false; | 119 if (!Init(db_, meta_table_)) return false; |
| 101 | 120 |
| 102 int error = db_->ExecuteAndReturnErrorCode( | 121 int error = db_->ExecuteAndReturnErrorCode( |
| 103 "INSERT INTO web_intents" | 122 "INSERT INTO web_intents" |
| 104 " (service_url, action, type, title, disposition)" | 123 " (service_url, action, type, title, disposition)" |
| 105 " SELECT " | 124 " SELECT " |
| 106 " service_url, action, type, title, disposition" | 125 " service_url, action, type, title, disposition" |
| 107 " FROM old_web_intents"); | 126 " FROM old_web_intents"); |
| 108 | 127 |
| 109 if (error != SQLITE_OK) { | 128 if (error != SQLITE_OK) { |
| 110 DLOG(WARNING) << "Could not copy old intent data to upgraded table." | 129 DLOG(WARNING) << "Could not copy old intent data to upgraded table." |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 return false; | 148 return false; |
| 130 } | 149 } |
| 131 | 150 |
| 132 if (!db_->Execute("DROP table old_web_intents_defaults")) { | 151 if (!db_->Execute("DROP table old_web_intents_defaults")) { |
| 133 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; | 152 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; |
| 134 return false; | 153 return false; |
| 135 } | 154 } |
| 136 | 155 |
| 137 return true; | 156 return true; |
| 138 } | 157 } |
| OLD | NEW |