OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "sql/statement.h" | 10 #include "sql/statement.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 bool ExtractIntents(sql::Statement* s, std::vector<WebIntentData>* intents) { | 13 bool ExtractIntents(sql::Statement* s, |
| 14 std::vector<WebIntentServiceData>* services) { |
14 DCHECK(s); | 15 DCHECK(s); |
15 while (s->Step()) { | 16 while (s->Step()) { |
16 WebIntentData intent; | 17 WebIntentServiceData service; |
17 string16 tmp = s->ColumnString16(0); | 18 string16 tmp = s->ColumnString16(0); |
18 intent.service_url = GURL(tmp); | 19 service.service_url = GURL(tmp); |
19 | 20 |
20 intent.action = s->ColumnString16(1); | 21 service.action = s->ColumnString16(1); |
21 intent.type = s->ColumnString16(2); | 22 service.type = s->ColumnString16(2); |
22 intent.title = s->ColumnString16(3); | 23 service.title = s->ColumnString16(3); |
23 tmp = s->ColumnString16(4); | 24 tmp = s->ColumnString16(4); |
24 // Default to window disposition. | 25 // Default to window disposition. |
25 intent.disposition = WebIntentData::DISPOSITION_WINDOW; | 26 service.disposition = WebIntentServiceData::DISPOSITION_WINDOW; |
26 if (tmp == ASCIIToUTF16("inline")) | 27 if (tmp == ASCIIToUTF16("inline")) |
27 intent.disposition = WebIntentData::DISPOSITION_INLINE; | 28 service.disposition = WebIntentServiceData::DISPOSITION_INLINE; |
28 intents->push_back(intent); | 29 services->push_back(service); |
29 } | 30 } |
30 return true; | 31 return true; |
31 } | 32 } |
32 } | 33 } |
33 | 34 |
34 WebIntentsTable::WebIntentsTable(sql::Connection* db, | 35 WebIntentsTable::WebIntentsTable(sql::Connection* db, |
35 sql::MetaTable* meta_table) | 36 sql::MetaTable* meta_table) |
36 : WebDatabaseTable(db, meta_table) { | 37 : WebDatabaseTable(db, meta_table) { |
37 } | 38 } |
38 | 39 |
(...skipping 22 matching lines...) Expand all Loading... |
61 } | 62 } |
62 | 63 |
63 return true; | 64 return true; |
64 } | 65 } |
65 | 66 |
66 // TODO(jhawkins): Figure out Sync story. | 67 // TODO(jhawkins): Figure out Sync story. |
67 bool WebIntentsTable::IsSyncable() { | 68 bool WebIntentsTable::IsSyncable() { |
68 return false; | 69 return false; |
69 } | 70 } |
70 | 71 |
71 bool WebIntentsTable::GetWebIntents(const string16& action, | 72 bool WebIntentsTable::GetWebIntents( |
72 std::vector<WebIntentData>* intents) { | 73 const string16& action, |
| 74 std::vector<WebIntentServiceData>* intents) { |
73 DCHECK(intents); | 75 DCHECK(intents); |
74 sql::Statement s(db_->GetUniqueStatement( | 76 sql::Statement s(db_->GetUniqueStatement( |
75 "SELECT service_url, action, type, title, disposition FROM web_intents " | 77 "SELECT service_url, action, type, title, disposition FROM web_intents " |
76 "WHERE action=?")); | 78 "WHERE action=?")); |
77 if (!s) { | 79 if (!s) { |
78 NOTREACHED() << "Statement prepare failed"; | 80 NOTREACHED() << "Statement prepare failed"; |
79 return false; | 81 return false; |
80 } | 82 } |
81 | 83 |
82 s.BindString16(0, action); | 84 s.BindString16(0, action); |
83 return ExtractIntents(&s, intents); | 85 return ExtractIntents(&s, intents); |
84 } | 86 } |
85 | 87 |
86 bool WebIntentsTable::GetAllWebIntents(std::vector<WebIntentData>* intents) { | 88 bool WebIntentsTable::GetAllWebIntents( |
| 89 std::vector<WebIntentServiceData>* intents) { |
87 DCHECK(intents); | 90 DCHECK(intents); |
88 sql::Statement s(db_->GetUniqueStatement( | 91 sql::Statement s(db_->GetUniqueStatement( |
89 "SELECT service_url, action, type, title, disposition FROM web_intents")); | 92 "SELECT service_url, action, type, title, disposition FROM web_intents")); |
90 if (!s) { | 93 if (!s) { |
91 NOTREACHED() << "Statement prepare failed"; | 94 NOTREACHED() << "Statement prepare failed"; |
92 return false; | 95 return false; |
93 } | 96 } |
94 | 97 |
95 return ExtractIntents(&s, intents); | 98 return ExtractIntents(&s, intents); |
96 } | 99 } |
97 | 100 |
98 bool WebIntentsTable::SetWebIntent(const WebIntentData& intent) { | 101 bool WebIntentsTable::SetWebIntent(const WebIntentServiceData& intent) { |
99 sql::Statement s(db_->GetUniqueStatement( | 102 sql::Statement s(db_->GetUniqueStatement( |
100 "INSERT OR REPLACE INTO web_intents " | 103 "INSERT OR REPLACE INTO web_intents " |
101 "(service_url, type, action, title, disposition) " | 104 "(service_url, type, action, title, disposition) " |
102 "VALUES (?, ?, ?, ?, ?)")); | 105 "VALUES (?, ?, ?, ?, ?)")); |
103 if (!s) { | 106 if (!s) { |
104 NOTREACHED() << "Statement prepare failed"; | 107 NOTREACHED() << "Statement prepare failed"; |
105 return false; | 108 return false; |
106 } | 109 } |
107 | 110 |
108 // Default to window disposition. | 111 // Default to window disposition. |
109 string16 disposition = ASCIIToUTF16("window"); | 112 string16 disposition = ASCIIToUTF16("window"); |
110 if (intent.disposition == WebIntentData::DISPOSITION_INLINE) | 113 if (intent.disposition == WebIntentServiceData::DISPOSITION_INLINE) |
111 disposition = ASCIIToUTF16("inline"); | 114 disposition = ASCIIToUTF16("inline"); |
112 s.BindString(0, intent.service_url.spec()); | 115 s.BindString(0, intent.service_url.spec()); |
113 s.BindString16(1, intent.type); | 116 s.BindString16(1, intent.type); |
114 s.BindString16(2, intent.action); | 117 s.BindString16(2, intent.action); |
115 s.BindString16(3, intent.title); | 118 s.BindString16(3, intent.title); |
116 s.BindString16(4, disposition); | 119 s.BindString16(4, disposition); |
117 return s.Run(); | 120 return s.Run(); |
118 } | 121 } |
119 | 122 |
120 // TODO(jhawkins): Investigate the need to remove rows matching only | 123 // TODO(jhawkins): Investigate the need to remove rows matching only |
121 // |intent.service_url|. It's unlikely the user will be given the ability to | 124 // |intent.service_url|. It's unlikely the user will be given the ability to |
122 // remove at the granularity of actions or types. | 125 // remove at the granularity of actions or types. |
123 bool WebIntentsTable::RemoveWebIntent(const WebIntentData& intent) { | 126 bool WebIntentsTable::RemoveWebIntent(const WebIntentServiceData& intent) { |
124 sql::Statement s(db_->GetUniqueStatement( | 127 sql::Statement s(db_->GetUniqueStatement( |
125 "DELETE FROM web_intents " | 128 "DELETE FROM web_intents " |
126 "WHERE service_url = ? AND action = ? AND type = ?")); | 129 "WHERE service_url = ? AND action = ? AND type = ?")); |
127 if (!s) { | 130 if (!s) { |
128 NOTREACHED() << "Statement prepare failed"; | 131 NOTREACHED() << "Statement prepare failed"; |
129 return false; | 132 return false; |
130 } | 133 } |
131 | 134 |
132 s.BindString(0, intent.service_url.spec()); | 135 s.BindString(0, intent.service_url.spec()); |
133 s.BindString16(1, intent.action); | 136 s.BindString16(1, intent.action); |
134 s.BindString16(2, intent.type); | 137 s.BindString16(2, intent.type); |
135 return s.Run(); | 138 return s.Run(); |
136 } | 139 } |
137 | |
OLD | NEW |