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 bool WebIntentsTable::Init() { | |
12 return InitWebIntentsTable(); | |
13 } | |
14 | |
15 bool WebIntentsTable::IsSyncable() { | |
16 return false; | |
17 } | |
18 | |
19 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.
| |
20 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.
| |
21 if (!db_->Execute("CREATE TABLE web_intents (" | |
22 "service_url LONGVARCHAR," | |
23 "action VARCHAR," | |
24 "type VARCHAR," | |
25 "UNIQUE (service_url, action, type))")) { | |
26 NOTREACHED(); | |
27 return false; | |
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::GetWebIntents(const string16& action, | |
39 std::vector<WebIntent>& intents) { | |
40 sql::Statement s(db_->GetUniqueStatement( | |
41 "SELECT service_url, action, type FROM web_intents " | |
42 "WHERE action=?")); | |
43 if (!s) { | |
44 NOTREACHED() << "Statement prepare failed"; | |
45 return false; | |
46 } | |
47 | |
48 s.BindString16(0, action); | |
49 while (s.Step()) { | |
50 WebIntent intent; | |
51 string16 tmp = s.ColumnString16(0); | |
52 intent.service_url = GURL(tmp); | |
53 | |
54 intent.action = s.ColumnString16(1); | |
55 intent.type = s.ColumnString16(2); | |
56 | |
57 intents.push_back(intent); | |
58 } | |
59 return true; | |
60 } | |
61 | |
62 bool WebIntentsTable::SetWebIntent(const string16& action, | |
63 const string16& type, | |
64 const GURL& service_url) { | |
65 sql::Statement s(db_->GetUniqueStatement( | |
66 "INSERT OR REPLACE INTO web_intents (service_url, type, action) " | |
67 "VALUES (?, ?, ?)")); | |
68 if (!s) { | |
69 NOTREACHED() << "Statement prepare failed"; | |
70 return false; | |
71 } | |
72 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.
| |
73 s.BindString16(1, type); | |
74 s.BindString16(2, action); | |
75 return s.Run(); | |
76 } | |
77 | |
78 bool WebIntentsTable::RemoveWebIntent(const string16& action, | |
79 const string16& type, | |
80 const GURL& service_url) { | |
81 sql::Statement delete_s(db_->GetUniqueStatement( | |
82 "DELETE FROM web_intents " | |
83 "WHERE service_url = ? AND action = ? AND type = ?")); | |
84 if (!delete_s) { | |
85 NOTREACHED() << "Statement prepare failed"; | |
86 return false; | |
87 } | |
James Hawkins
2011/07/26 20:21:53
Blank line, as above.
groby-ooo-7-16
2011/07/26 21:38:37
Done.
| |
88 delete_s.BindString(0, service_url.spec()); | |
89 delete_s.BindString16(1, action); | |
90 delete_s.BindString16(2, type); | |
91 return delete_s.Run(); | |
92 } | |
93 | |
OLD | NEW |