Chromium Code Reviews| Index: chrome/browser/webdata/web_intents_table.cc |
| diff --git a/chrome/browser/webdata/web_intents_table.cc b/chrome/browser/webdata/web_intents_table.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6f98e8f0f6e7e374cc835b717efe1ce08af430a5 |
| --- /dev/null |
| +++ b/chrome/browser/webdata/web_intents_table.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/webdata/web_intents_table.h" |
| + |
| +#include "base/logging.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "sql/statement.h" |
| + |
| +bool WebIntentsTable::Init() { |
| + return InitWebIntentsTable(); |
| +} |
| + |
| +bool WebIntentsTable::IsSyncable() { |
| + return false; |
| +} |
| + |
| +bool WebIntentsTable::InitWebIntentsTable() { |
|
James Hawkins
2011/07/26 20:21:53
I'd prefer to remove this level of indirection and
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
| + if (!db_->DoesTableExist("web_intents")) { |
|
James Hawkins
2011/07/26 20:21:53
Save indentation by reversing the logic and return
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
| + if (!db_->Execute("CREATE TABLE web_intents (" |
| + "service_url LONGVARCHAR," |
| + "action VARCHAR," |
| + "type VARCHAR," |
| + "UNIQUE (service_url, action, type))")) { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + if (!db_->Execute("CREATE INDEX web_intents_index " |
| + "ON web_intents (action,type)")) { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +bool WebIntentsTable::GetWebIntents(const string16& action, |
| + std::vector<WebIntent>& intents) { |
| + sql::Statement s(db_->GetUniqueStatement( |
| + "SELECT service_url, action, type FROM web_intents " |
| + "WHERE action=?")); |
| + if (!s) { |
| + NOTREACHED() << "Statement prepare failed"; |
| + return false; |
| + } |
| + |
| + s.BindString16(0, action); |
| + while (s.Step()) { |
| + WebIntent intent; |
| + string16 tmp = s.ColumnString16(0); |
| + intent.service_url = GURL(tmp); |
| + |
| + intent.action = s.ColumnString16(1); |
| + intent.type = s.ColumnString16(2); |
| + |
| + intents.push_back(intent); |
| + } |
| + return true; |
| +} |
| + |
| +bool WebIntentsTable::SetWebIntent(const string16& action, |
| + const string16& type, |
| + const GURL& service_url) { |
| + sql::Statement s(db_->GetUniqueStatement( |
| + "INSERT OR REPLACE INTO web_intents (service_url, type, action) " |
| + "VALUES (?, ?, ?)")); |
| + if (!s) { |
| + NOTREACHED() << "Statement prepare failed"; |
| + return false; |
| + } |
| + s.BindString(0, service_url.spec()); |
|
James Hawkins
2011/07/26 20:21:53
Blank line for consistency and readability.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
| + s.BindString16(1, type); |
| + s.BindString16(2, action); |
| + return s.Run(); |
| +} |
| + |
| +bool WebIntentsTable::RemoveWebIntent(const string16& action, |
| + const string16& type, |
| + const GURL& service_url) { |
| + sql::Statement delete_s(db_->GetUniqueStatement( |
| + "DELETE FROM web_intents " |
| + "WHERE service_url = ? AND action = ? AND type = ?")); |
| + if (!delete_s) { |
| + NOTREACHED() << "Statement prepare failed"; |
| + return false; |
| + } |
|
James Hawkins
2011/07/26 20:21:53
Blank line, as above.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
|
| + delete_s.BindString(0, service_url.spec()); |
| + delete_s.BindString16(1, action); |
| + delete_s.BindString16(2, type); |
| + return delete_s.Run(); |
| +} |
| + |