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

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

Issue 12225076: Delete most web intents code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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
« no previous file with comments | « chrome/browser/webdata/web_intents_table.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/intents/default_web_intent_service.h"
13 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
14 #include "net/base/mime_util.h" 13 #include "net/base/mime_util.h"
15 #include "sql/statement.h" 14 #include "sql/statement.h"
16 #include "third_party/sqlite/sqlite3.h" 15 #include "third_party/sqlite/sqlite3.h"
17 16
18 using webkit_glue::WebIntentServiceData;
19
20 namespace {
21
22 #if defined(ENABLE_WEB_INTENTS)
23 bool ExtractIntents(sql::Statement* s,
24 std::vector<WebIntentServiceData>* services) {
25 DCHECK(s);
26 if (!s->is_valid())
27 return false;
28
29 while (s->Step()) {
30 WebIntentServiceData service;
31 service.action = s->ColumnString16(0);
32 service.type = s->ColumnString16(1);
33 service.scheme = s->ColumnString16(2);
34 service.service_url = GURL(s->ColumnString16(3));
35 service.title = s->ColumnString16(4);
36 // Default to window disposition.
37 service.disposition = WebIntentServiceData::DISPOSITION_WINDOW;
38 if (s->ColumnString16(5) == ASCIIToUTF16("inline"))
39 service.disposition = WebIntentServiceData::DISPOSITION_INLINE;
40 services->push_back(service);
41 }
42 return s->Succeeded();
43 }
44 #endif // defined(ENABLE_WEB_INTENTS)
45
46 } // namespace
47
48 WebIntentsTable::WebIntentsTable(sql::Connection* db, 17 WebIntentsTable::WebIntentsTable(sql::Connection* db,
49 sql::MetaTable* meta_table) 18 sql::MetaTable* meta_table)
50 : WebDatabaseTable(db, meta_table) { 19 : WebDatabaseTable(db, meta_table) {
51 } 20 }
52 21
53 WebIntentsTable::~WebIntentsTable() { 22 WebIntentsTable::~WebIntentsTable() {
54 } 23 }
55 24
56 bool WebIntentsTable::Init() { 25 bool WebIntentsTable::Init() {
57 if (!db_->DoesTableExist("web_intents")) { 26 if (!db_->DoesTableExist("web_intents")) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return false; 118 return false;
150 } 119 }
151 120
152 if (!db_->Execute("DROP table old_web_intents_defaults")) { 121 if (!db_->Execute("DROP table old_web_intents_defaults")) {
153 DLOG(WARNING) << "Could not drop backup web_intents_defaults table."; 122 DLOG(WARNING) << "Could not drop backup web_intents_defaults table.";
154 return false; 123 return false;
155 } 124 }
156 125
157 return true; 126 return true;
158 } 127 }
159
160 #if defined(ENABLE_WEB_INTENTS)
161 bool WebIntentsTable::GetWebIntentServicesForAction(
162 const string16& action,
163 std::vector<WebIntentServiceData>* services) {
164 DCHECK(services);
165 sql::Statement s(db_->GetUniqueStatement(
166 "SELECT action, type, scheme, service_url, title, disposition"
167 " FROM web_intents"
168 " WHERE action=?"));
169 s.BindString16(0, action);
170
171 return ExtractIntents(&s, services);
172 }
173
174 bool WebIntentsTable::GetWebIntentServicesForScheme(
175 const string16& scheme,
176 std::vector<WebIntentServiceData>* services) {
177 DCHECK(services);
178 sql::Statement s(db_->GetUniqueStatement(
179 "SELECT action, type, scheme, service_url, title, disposition"
180 " FROM web_intents"
181 " WHERE scheme=?"));
182 s.BindString16(0, scheme);
183
184 return ExtractIntents(&s, services);
185 }
186
187 // TODO(gbillock): This currently does a full-table scan. Eventually we will
188 // store registrations by domain, and so have an indexed origin. At that time,
189 // this should just change to do lookup by origin instead of URL.
190 bool WebIntentsTable::GetWebIntentServicesForURL(
191 const string16& service_url,
192 std::vector<WebIntentServiceData>* services) {
193 DCHECK(services);
194 sql::Statement s(db_->GetUniqueStatement(
195 "SELECT action, type, scheme, service_url, title, disposition"
196 " FROM web_intents"
197 " WHERE service_url=?"));
198 s.BindString16(0, service_url);
199
200 return ExtractIntents(&s, services);
201 }
202
203 bool WebIntentsTable::GetAllWebIntentServices(
204 std::vector<WebIntentServiceData>* services) {
205 DCHECK(services);
206 sql::Statement s(db_->GetUniqueStatement(
207 "SELECT action, type, scheme, service_url, title, disposition"
208 " FROM web_intents"));
209
210 return ExtractIntents(&s, services);
211 }
212
213 bool WebIntentsTable::SetWebIntentService(const WebIntentServiceData& service) {
214 sql::Statement s(db_->GetUniqueStatement(
215 "INSERT OR REPLACE INTO web_intents "
216 "(action, type, scheme, service_url, title, disposition) "
217 "VALUES (?, ?, ?, ?, ?, ?)"));
218
219 // Default to window disposition.
220 string16 disposition = ASCIIToUTF16("window");
221 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE)
222 disposition = ASCIIToUTF16("inline");
223 s.BindString16(0, service.action);
224 s.BindString16(1, service.type);
225 s.BindString16(2, service.scheme);
226 s.BindString(3, service.service_url.spec());
227 s.BindString16(4, service.title);
228 s.BindString16(5, disposition);
229
230 return s.Run();
231 }
232
233 // TODO(jhawkins): Investigate the need to remove rows matching only
234 // |service.service_url|. It's unlikely the user will be given the ability to
235 // remove at the granularity of actions or types.
236 bool WebIntentsTable::RemoveWebIntentService(
237 const WebIntentServiceData& service) {
238 sql::Statement s(db_->GetUniqueStatement(
239 "DELETE FROM web_intents "
240 "WHERE action = ? AND type = ? AND scheme = ? AND service_url = ?"));
241
242 s.BindString16(0, service.action);
243 s.BindString16(1, service.type);
244 s.BindString16(2, service.scheme);
245 s.BindString(3, service.service_url.spec());
246
247 return s.Run();
248 }
249
250 bool WebIntentsTable::GetDefaultServices(
251 const string16& action,
252 std::vector<DefaultWebIntentService>* default_services) {
253 sql::Statement s(db_->GetUniqueStatement(
254 "SELECT action, type, url_pattern, user_date, suppression, "
255 "service_url FROM web_intents_defaults "
256 "WHERE action=?"));
257 s.BindString16(0, action);
258
259 while (s.Step()) {
260 DefaultWebIntentService entry;
261 entry.action = s.ColumnString16(0);
262 entry.type = s.ColumnString16(1);
263 if (entry.url_pattern.Parse(s.ColumnString(2)) !=
264 URLPattern::PARSE_SUCCESS) {
265 return false;
266 }
267 entry.user_date = s.ColumnInt(3);
268 entry.suppression = s.ColumnInt64(4);
269 entry.service_url = s.ColumnString(5);
270
271 default_services->push_back(entry);
272 }
273
274 return s.Succeeded();
275 }
276
277 bool WebIntentsTable::GetAllDefaultServices(
278 std::vector<DefaultWebIntentService>* default_services) {
279 sql::Statement s(db_->GetUniqueStatement(
280 "SELECT action, type, url_pattern, user_date, suppression, "
281 "service_url FROM web_intents_defaults"));
282
283 while (s.Step()) {
284 DefaultWebIntentService entry;
285 entry.action = s.ColumnString16(0);
286 entry.type = s.ColumnString16(1);
287 if (entry.url_pattern.Parse(s.ColumnString(2)) !=
288 URLPattern::PARSE_SUCCESS) {
289 return false;
290 }
291 entry.user_date = s.ColumnInt(3);
292 entry.suppression = s.ColumnInt64(4);
293 entry.service_url = s.ColumnString(5);
294
295 default_services->push_back(entry);
296 }
297
298 return s.Succeeded();
299
300 }
301
302 bool WebIntentsTable::SetDefaultService(
303 const DefaultWebIntentService& default_service) {
304 sql::Statement s(db_->GetUniqueStatement(
305 "INSERT OR REPLACE INTO web_intents_defaults "
306 "(action, type, url_pattern, user_date, suppression,"
307 " service_url, scheme) "
308 "VALUES (?, ?, ?, ?, ?, ?, ?)"));
309 s.BindString16(0, default_service.action);
310 s.BindString16(1, default_service.type);
311 s.BindString(2, default_service.url_pattern.GetAsString());
312 s.BindInt(3, default_service.user_date);
313 s.BindInt64(4, default_service.suppression);
314 s.BindString(5, default_service.service_url);
315 s.BindString16(6, default_service.scheme);
316
317 return s.Run();
318 }
319
320 bool WebIntentsTable::RemoveDefaultService(
321 const DefaultWebIntentService& default_service) {
322 sql::Statement s(db_->GetUniqueStatement(
323 "DELETE FROM web_intents_defaults "
324 "WHERE action = ? AND type = ? AND url_pattern = ?"));
325 s.BindString16(0, default_service.action);
326 s.BindString16(1, default_service.type);
327 s.BindString(2, default_service.url_pattern.GetAsString());
328
329 return s.Run();
330 }
331
332 bool WebIntentsTable::RemoveServiceDefaults(const GURL& service_url) {
333 sql::Statement s(db_->GetUniqueStatement(
334 "DELETE FROM web_intents_defaults WHERE service_url = ?"));
335 s.BindString(0, service_url.spec());
336
337 return s.Run();
338 }
339
340 #endif // defined(ENABLE_WEB_INTENTS)
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_intents_table.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698