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

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

Issue 9104018: Modify schema to include defaulting information. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix forward decl. Created 8 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 7
8 #include "base/i18n/case_conversion.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/intents/default_web_intent_service.h"
9 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/mime_util.h"
10 #include "sql/statement.h" 15 #include "sql/statement.h"
11 16
12 using webkit_glue::WebIntentServiceData; 17 using webkit_glue::WebIntentServiceData;
13 18
14 namespace { 19 namespace {
15 20
16 bool ExtractIntents(sql::Statement* s, 21 bool ExtractIntents(sql::Statement* s,
17 std::vector<WebIntentServiceData>* services) { 22 std::vector<WebIntentServiceData>* services) {
18 DCHECK(s); 23 DCHECK(s);
19 if (!s->is_valid()) 24 if (!s->is_valid())
(...skipping 21 matching lines...) Expand all
41 46
42 WebIntentsTable::WebIntentsTable(sql::Connection* db, 47 WebIntentsTable::WebIntentsTable(sql::Connection* db,
43 sql::MetaTable* meta_table) 48 sql::MetaTable* meta_table)
44 : WebDatabaseTable(db, meta_table) { 49 : WebDatabaseTable(db, meta_table) {
45 } 50 }
46 51
47 WebIntentsTable::~WebIntentsTable() { 52 WebIntentsTable::~WebIntentsTable() {
48 } 53 }
49 54
50 bool WebIntentsTable::Init() { 55 bool WebIntentsTable::Init() {
51 if (db_->DoesTableExist("web_intents")) 56 if (!db_->DoesTableExist("web_intents")) {
52 return true; 57 if (!db_->Execute("CREATE TABLE web_intents ("
58 "service_url LONGVARCHAR,"
59 "action VARCHAR,"
60 "type VARCHAR,"
61 "title LONGVARCHAR,"
62 "disposition VARCHAR,"
63 "UNIQUE (service_url, action, type))")) {
64 return false;
65 }
66 }
53 67
54 if (!db_->Execute("CREATE TABLE web_intents (" 68 if (!db_->DoesTableExist("web_intents_defaults")) {
55 "service_url LONGVARCHAR," 69 if (!db_->Execute("CREATE TABLE web_intents_defaults ("
56 "action VARCHAR," 70 "action VARCHAR,"
57 "type VARCHAR," 71 "type VARCHAR,"
58 "title VARCHAR," 72 "url_prefix LONGVARCHAR,"
59 "disposition VARCHAR," 73 "user_date INTEGER,"
60 "UNIQUE (service_url, action, type))")) { 74 "suppression INTEGER,"
75 "service_url LONGVARCHAR,"
76 "extension_url LONGVARCHAR,"
77 "UNIQUE (action, type, url_prefix))")) {
78 return false;
79 }
80 }
81
82 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_index "
83 "ON web_intents (action)"))
84 return false;
85
86 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index "
87 "ON web_intents_defaults (action)")) {
61 return false; 88 return false;
62 } 89 }
63 90
64 if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)"))
65 return false;
66
67 return true; 91 return true;
68 } 92 }
69 93
70 // TODO(jhawkins): Figure out Sync story. 94 // TODO(jhawkins): Figure out Sync story.
71 bool WebIntentsTable::IsSyncable() { 95 bool WebIntentsTable::IsSyncable() {
72 return false; 96 return false;
73 } 97 }
74 98
75 bool WebIntentsTable::GetWebIntentServices( 99 bool WebIntentsTable::GetWebIntentServices(
76 const string16& action, 100 const string16& action,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const WebIntentServiceData& service) { 158 const WebIntentServiceData& service) {
135 sql::Statement s(db_->GetUniqueStatement( 159 sql::Statement s(db_->GetUniqueStatement(
136 "DELETE FROM web_intents " 160 "DELETE FROM web_intents "
137 "WHERE service_url = ? AND action = ? AND type = ?")); 161 "WHERE service_url = ? AND action = ? AND type = ?"));
138 s.BindString(0, service.service_url.spec()); 162 s.BindString(0, service.service_url.spec());
139 s.BindString16(1, service.action); 163 s.BindString16(1, service.action);
140 s.BindString16(2, service.type); 164 s.BindString16(2, service.type);
141 165
142 return s.Run(); 166 return s.Run();
143 } 167 }
168
169 bool WebIntentsTable::GetDefaultServices(
170 const string16& action,
171 std::vector<DefaultWebIntentService>* default_services) {
172 sql::Statement s(db_->GetUniqueStatement(
173 "SELECT action, type, url_prefix, user_date, suppression, "
174 "service_url, extension_url FROM web_intents_defaults "
175 "WHERE action=?"));
176 s.BindString16(0, action);
177
178 while (s.Step()) {
179 DefaultWebIntentService entry;
180 entry.action = s.ColumnString16(0);
181 entry.type = s.ColumnString16(1);
182 entry.url_prefix = s.ColumnString(2);
183 entry.user_date = s.ColumnInt(3);
184 entry.suppression = s.ColumnInt(4);
185 entry.service_url = s.ColumnString(5);
186 entry.extension_url = s.ColumnString(6);
187 default_services->push_back(entry);
188 }
189
190 return s.Succeeded();
191 }
192
193 bool WebIntentsTable::SetDefaultService(
194 const DefaultWebIntentService& default_service) {
195 sql::Statement s(db_->GetUniqueStatement(
196 "INSERT OR REPLACE INTO web_intents_defaults "
197 "(action, type, url_prefix, user_date, suppression,"
198 " service_url, extension_url) "
199 "VALUES (?, ?, ?, ?, ?, ?, ?)"));
200 s.BindString16(0, default_service.action);
201 s.BindString16(1, default_service.type);
202 s.BindString(2, default_service.url_prefix);
203 s.BindInt(3, default_service.user_date);
204 s.BindInt(4, default_service.suppression);
205 s.BindString(5, default_service.service_url);
206 s.BindString(6, default_service.extension_url);
207
208 return s.Run();
209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698