OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/webdata/web_intents_table.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 #include "sql/statement.h" |
| 10 |
| 11 WebIntentsTable::WebIntentsTable(sql::Connection* db, |
| 12 sql::MetaTable* meta_table) |
| 13 : WebDatabaseTable(db, meta_table) { |
| 14 } |
| 15 |
| 16 WebIntentsTable::~WebIntentsTable() { |
| 17 } |
| 18 |
| 19 bool WebIntentsTable::Init() { |
| 20 if (db_->DoesTableExist("web_intents")) |
| 21 return true; |
| 22 |
| 23 if (!db_->Execute("CREATE TABLE web_intents (" |
| 24 "service_url LONGVARCHAR," |
| 25 "action VARCHAR," |
| 26 "type VARCHAR," |
| 27 "UNIQUE (service_url, action, type))")) { |
| 28 NOTREACHED(); |
| 29 return false; |
| 30 } |
| 31 |
| 32 if (!db_->Execute("CREATE INDEX web_intents_index " |
| 33 "ON web_intents (action)")) { |
| 34 NOTREACHED(); |
| 35 return false; |
| 36 } |
| 37 |
| 38 return true; |
| 39 } |
| 40 |
| 41 // TODO(jhawkins): Figure out Sync story. |
| 42 bool WebIntentsTable::IsSyncable() { |
| 43 return false; |
| 44 } |
| 45 |
| 46 bool WebIntentsTable::GetWebIntents(const string16& action, |
| 47 std::vector<WebIntentData>* intents) { |
| 48 DCHECK(intents); |
| 49 sql::Statement s(db_->GetUniqueStatement( |
| 50 "SELECT service_url, action, type FROM web_intents " |
| 51 "WHERE action=?")); |
| 52 if (!s) { |
| 53 NOTREACHED() << "Statement prepare failed"; |
| 54 return false; |
| 55 } |
| 56 |
| 57 s.BindString16(0, action); |
| 58 while (s.Step()) { |
| 59 WebIntentData intent; |
| 60 string16 tmp = s.ColumnString16(0); |
| 61 intent.service_url = GURL(tmp); |
| 62 |
| 63 intent.action = s.ColumnString16(1); |
| 64 intent.type = s.ColumnString16(2); |
| 65 |
| 66 intents->push_back(intent); |
| 67 } |
| 68 return true; |
| 69 } |
| 70 |
| 71 bool WebIntentsTable::SetWebIntent(const string16& action, |
| 72 const string16& type, |
| 73 const GURL& service_url) { |
| 74 sql::Statement s(db_->GetUniqueStatement( |
| 75 "INSERT OR REPLACE INTO web_intents (service_url, type, action) " |
| 76 "VALUES (?, ?, ?)")); |
| 77 if (!s) { |
| 78 NOTREACHED() << "Statement prepare failed"; |
| 79 return false; |
| 80 } |
| 81 |
| 82 s.BindString(0, service_url.spec()); |
| 83 s.BindString16(1, type); |
| 84 s.BindString16(2, action); |
| 85 return s.Run(); |
| 86 } |
| 87 |
| 88 bool WebIntentsTable::RemoveWebIntent(const string16& action, |
| 89 const string16& type, |
| 90 const GURL& service_url) { |
| 91 sql::Statement delete_s(db_->GetUniqueStatement( |
| 92 "DELETE FROM web_intents " |
| 93 "WHERE service_url = ? AND action = ? AND type = ?")); |
| 94 if (!delete_s) { |
| 95 NOTREACHED() << "Statement prepare failed"; |
| 96 return false; |
| 97 } |
| 98 |
| 99 delete_s.BindString(0, service_url.spec()); |
| 100 delete_s.BindString16(1, action); |
| 101 delete_s.BindString16(2, type); |
| 102 return delete_s.Run(); |
| 103 } |
| 104 |
OLD | NEW |