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

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

Issue 7461089: First implementation of web intents table. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed review issues. Created 9 years, 4 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
(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 bool WebIntentsTable::Init() {
17 if (db_->DoesTableExist("web_intents"))
18 return true;
19
20 if (!db_->Execute("CREATE TABLE web_intents ("
21 "service_url LONGVARCHAR,"
22 "action VARCHAR,"
23 "type VARCHAR,"
24 "UNIQUE (service_url, action, type))")) {
25 NOTREACHED();
26 return false;
27 }
28
29 if (!db_->Execute("CREATE INDEX web_intents_index "
30 "ON web_intents (action,type)")) {
31 NOTREACHED();
32 return false;
33 }
34
35 return true;
36 }
37
38 bool WebIntentsTable::IsSyncable() {
James Hawkins 2011/07/26 21:48:41 Add a TODO(jhawkins) to figure out the Sync story
groby-ooo-7-16 2011/07/26 23:12:34 Done.
39 return false;
40 }
41
42 bool WebIntentsTable::GetWebIntents(const string16& action,
43 std::vector<WebIntentData>* intents) {
44 DCHECK(intents);
45 sql::Statement s(db_->GetUniqueStatement(
46 "SELECT service_url, action, type FROM web_intents "
47 "WHERE action=?"));
48 if (!s) {
49 NOTREACHED() << "Statement prepare failed";
50 return false;
51 }
52
53 s.BindString16(0, action);
54 while (s.Step()) {
55 WebIntentData intent;
56 string16 tmp = s.ColumnString16(0);
57 intent.service_url = GURL(tmp);
58
59 intent.action = s.ColumnString16(1);
60 intent.type = s.ColumnString16(2);
61
62 intents->push_back(intent);
63 }
64 return true;
65 }
66
67 bool WebIntentsTable::SetWebIntent(const string16& action,
68 const string16& type,
69 const GURL& service_url) {
70 sql::Statement s(db_->GetUniqueStatement(
71 "INSERT OR REPLACE INTO web_intents (service_url, type, action) "
72 "VALUES (?, ?, ?)"));
73 if (!s) {
74 NOTREACHED() << "Statement prepare failed";
75 return false;
76 }
77
78 s.BindString(0, service_url.spec());
79 s.BindString16(1, type);
80 s.BindString16(2, action);
81 return s.Run();
82 }
83
84 bool WebIntentsTable::RemoveWebIntent(const string16& action,
85 const string16& type,
86 const GURL& service_url) {
87 sql::Statement delete_s(db_->GetUniqueStatement(
88 "DELETE FROM web_intents "
89 "WHERE service_url = ? AND action = ? AND type = ?"));
90 if (!delete_s) {
91 NOTREACHED() << "Statement prepare failed";
92 return false;
93 }
94
95 delete_s.BindString(0, service_url.spec());
96 delete_s.BindString16(1, action);
97 delete_s.BindString16(2, type);
98 return delete_s.Run();
99 }
100
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698