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 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 WebIntentsTable* WebIntentsTable::FromWebDatabase(WebDatabase* db) { | 36 WebIntentsTable* WebIntentsTable::FromWebDatabase(WebDatabase* db) { |
37 return static_cast<WebIntentsTable*>(db->GetTable(GetKey())); | 37 return static_cast<WebIntentsTable*>(db->GetTable(GetKey())); |
38 } | 38 } |
39 | 39 |
40 WebDatabaseTable::TypeKey WebIntentsTable::GetTypeKey() const { | 40 WebDatabaseTable::TypeKey WebIntentsTable::GetTypeKey() const { |
41 return GetKey(); | 41 return GetKey(); |
42 } | 42 } |
43 | 43 |
44 bool WebIntentsTable::Init(sql::Connection* db, sql::MetaTable* meta_table) { | 44 bool WebIntentsTable::CreateTablesIfNecessary() { |
45 WebDatabaseTable::Init(db, meta_table); | |
46 | |
47 if (!db_->DoesTableExist("web_intents")) { | 45 if (!db_->DoesTableExist("web_intents")) { |
48 if (!db_->Execute("CREATE TABLE web_intents (" | 46 if (!db_->Execute("CREATE TABLE web_intents (" |
49 " service_url LONGVARCHAR," | 47 " service_url LONGVARCHAR," |
50 " action VARCHAR," | 48 " action VARCHAR," |
51 " type VARCHAR," | 49 " type VARCHAR," |
52 " title LONGVARCHAR," | 50 " title LONGVARCHAR," |
53 " disposition VARCHAR," | 51 " disposition VARCHAR," |
54 " scheme VARCHAR," | 52 " scheme VARCHAR," |
55 " UNIQUE (service_url, action, scheme, type))")) { | 53 " UNIQUE (service_url, action, scheme, type))")) { |
56 return false; | 54 return false; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 *update_compatible_version = true; | 96 *update_compatible_version = true; |
99 return MigrateToVersion46AddSchemeColumn(); | 97 return MigrateToVersion46AddSchemeColumn(); |
100 } | 98 } |
101 | 99 |
102 return true; | 100 return true; |
103 } | 101 } |
104 | 102 |
105 // Updates the table by way of renaming the old tables, rerunning | 103 // Updates the table by way of renaming the old tables, rerunning |
106 // the Init method, then selecting old values into the new tables. | 104 // the Init method, then selecting old values into the new tables. |
107 bool WebIntentsTable::MigrateToVersion46AddSchemeColumn() { | 105 bool WebIntentsTable::MigrateToVersion46AddSchemeColumn() { |
| 106 // If the old table doesn't exist, there's nothing to migrate. |
| 107 if (!db_->DoesTableExist("web_intents")) |
| 108 return true; |
108 | 109 |
109 if (!db_->Execute("ALTER TABLE web_intents RENAME TO old_web_intents")) { | 110 if (!db_->Execute("ALTER TABLE web_intents RENAME TO old_web_intents")) |
110 DLOG(WARNING) << "Could not backup web_intents table."; | |
111 return false; | 111 return false; |
112 } | |
113 | 112 |
114 if (!db_->Execute("ALTER TABLE web_intents_defaults" | 113 if (!db_->Execute("ALTER TABLE web_intents_defaults" |
115 " RENAME TO old_web_intents_defaults")) { | 114 " RENAME TO old_web_intents_defaults")) |
116 DLOG(WARNING) << "Could not backup web_intents_defaults table."; | |
117 return false; | 115 return false; |
118 } | |
119 | 116 |
120 if (!Init(db_, meta_table_)) return false; | 117 if (!CreateTablesIfNecessary()) |
| 118 return false; |
121 | 119 |
122 int error = db_->ExecuteAndReturnErrorCode( | 120 int error = db_->ExecuteAndReturnErrorCode( |
123 "INSERT INTO web_intents" | 121 "INSERT INTO web_intents" |
124 " (service_url, action, type, title, disposition)" | 122 " (service_url, action, type, title, disposition)" |
125 " SELECT " | 123 " SELECT " |
126 " service_url, action, type, title, disposition" | 124 " service_url, action, type, title, disposition" |
127 " FROM old_web_intents"); | 125 " FROM old_web_intents"); |
128 | 126 |
129 if (error != SQLITE_OK) { | 127 if (error != SQLITE_OK) { |
130 DLOG(WARNING) << "Could not copy old intent data to upgraded table." | 128 DLOG(WARNING) << "Could not copy old intent data to upgraded table." |
(...skipping 18 matching lines...) Expand all Loading... |
149 return false; | 147 return false; |
150 } | 148 } |
151 | 149 |
152 if (!db_->Execute("DROP table old_web_intents_defaults")) { | 150 if (!db_->Execute("DROP table old_web_intents_defaults")) { |
153 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; | 151 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; |
154 return false; | 152 return false; |
155 } | 153 } |
156 | 154 |
157 return true; | 155 return true; |
158 } | 156 } |
OLD | NEW |