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

Side by Side Diff: chrome/browser/webdata/web_intents_table.cc

Issue 12543034: Move creation of the various WebDatabaseTable types out of WebDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review. Created 7 years, 9 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
OLDNEW
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 WebDatabaseTable::TypeKey GetKey() {
21 return reinterpret_cast<void*>(&WebIntentsTable::FromWebDatabase);
22 }
23
24 } // namespace
25
26 WebIntentsTable::WebIntentsTable() {
20 } 27 }
21 28
22 WebIntentsTable::~WebIntentsTable() { 29 WebIntentsTable::~WebIntentsTable() {
23 } 30 }
24 31
25 bool WebIntentsTable::Init() { 32 WebIntentsTable* WebIntentsTable::FromWebDatabase(WebDatabase* db) {
33 return static_cast<WebIntentsTable*>(db->GetTable(GetKey()));
34 }
35
36 WebDatabaseTable::TypeKey WebIntentsTable::GetTypeKey() const {
37 return GetKey();
38 }
39
40 bool WebIntentsTable::Init(sql::Connection* db, sql::MetaTable* meta_table) {
41 WebDatabaseTable::Init(db, meta_table);
42
26 if (!db_->DoesTableExist("web_intents")) { 43 if (!db_->DoesTableExist("web_intents")) {
27 if (!db_->Execute("CREATE TABLE web_intents (" 44 if (!db_->Execute("CREATE TABLE web_intents ("
28 " service_url LONGVARCHAR," 45 " service_url LONGVARCHAR,"
29 " action VARCHAR," 46 " action VARCHAR,"
30 " type VARCHAR," 47 " type VARCHAR,"
31 " title LONGVARCHAR," 48 " title LONGVARCHAR,"
32 " disposition VARCHAR," 49 " disposition VARCHAR,"
33 " scheme VARCHAR," 50 " scheme VARCHAR,"
34 " UNIQUE (service_url, action, scheme, type))")) { 51 " UNIQUE (service_url, action, scheme, type))")) {
35 return false; 52 return false;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 DLOG(WARNING) << "Could not backup web_intents table."; 107 DLOG(WARNING) << "Could not backup web_intents table.";
91 return false; 108 return false;
92 } 109 }
93 110
94 if (!db_->Execute("ALTER TABLE web_intents_defaults" 111 if (!db_->Execute("ALTER TABLE web_intents_defaults"
95 " RENAME TO old_web_intents_defaults")) { 112 " RENAME TO old_web_intents_defaults")) {
96 DLOG(WARNING) << "Could not backup web_intents_defaults table."; 113 DLOG(WARNING) << "Could not backup web_intents_defaults table.";
97 return false; 114 return false;
98 } 115 }
99 116
100 if (!Init()) return false; 117 if (!Init(db_, meta_table_)) return false;
101 118
102 int error = db_->ExecuteAndReturnErrorCode( 119 int error = db_->ExecuteAndReturnErrorCode(
103 "INSERT INTO web_intents" 120 "INSERT INTO web_intents"
104 " (service_url, action, type, title, disposition)" 121 " (service_url, action, type, title, disposition)"
105 " SELECT " 122 " SELECT "
106 " service_url, action, type, title, disposition" 123 " service_url, action, type, title, disposition"
107 " FROM old_web_intents"); 124 " FROM old_web_intents");
108 125
109 if (error != SQLITE_OK) { 126 if (error != SQLITE_OK) {
110 DLOG(WARNING) << "Could not copy old intent data to upgraded table." 127 DLOG(WARNING) << "Could not copy old intent data to upgraded table."
(...skipping 18 matching lines...) Expand all
129 return false; 146 return false;
130 } 147 }
131 148
132 if (!db_->Execute("DROP table old_web_intents_defaults")) { 149 if (!db_->Execute("DROP table old_web_intents_defaults")) {
133 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; 150 DLOG(WARNING) << "Could not drop backup web_intents_defaults table.";
134 return false; 151 return false;
135 } 152 }
136 153
137 return true; 154 return true;
138 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698