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

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

Issue 9355004: Merge 121330 - Modify schema to include defaulting information. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1025/src/
Patch Set: Created 8 years, 10 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <string>
6 7
8 #include "base/i18n/case_conversion.h"
7 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/intents/default_web_intent_service.h"
9 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "net/base/mime_util.h"
10 #include "sql/statement.h" 15 #include "sql/statement.h"
11 16
12 using webkit_glue::WebIntentServiceData; 17 using webkit_glue::WebIntentServiceData;
13 18
14 namespace { 19 namespace {
15 20
16 bool ExtractIntents(sql::Statement* s, 21 bool ExtractIntents(sql::Statement* s,
17 std::vector<WebIntentServiceData>* services) { 22 std::vector<WebIntentServiceData>* services) {
18 DCHECK(s); 23 DCHECK(s);
19 if (!s->is_valid()) 24 if (!s->is_valid())
(...skipping 21 matching lines...) Expand all
41 46
42 WebIntentsTable::WebIntentsTable(sql::Connection* db, 47 WebIntentsTable::WebIntentsTable(sql::Connection* db,
43 sql::MetaTable* meta_table) 48 sql::MetaTable* meta_table)
44 : WebDatabaseTable(db, meta_table) { 49 : WebDatabaseTable(db, meta_table) {
45 } 50 }
46 51
47 WebIntentsTable::~WebIntentsTable() { 52 WebIntentsTable::~WebIntentsTable() {
48 } 53 }
49 54
50 bool WebIntentsTable::Init() { 55 bool WebIntentsTable::Init() {
51 if (db_->DoesTableExist("web_intents")) 56 if (!db_->DoesTableExist("web_intents")) {
52 return true; 57 if (!db_->Execute("CREATE TABLE web_intents ("
58 "service_url LONGVARCHAR,"
59 "action VARCHAR,"
60 "type VARCHAR,"
61 "title LONGVARCHAR,"
62 "disposition VARCHAR,"
63 "UNIQUE (service_url, action, type))")) {
64 return false;
65 }
66 }
53 67
54 if (!db_->Execute("CREATE TABLE web_intents (" 68 if (!db_->DoesTableExist("web_intents_defaults")) {
55 "service_url LONGVARCHAR," 69 if (!db_->Execute("CREATE TABLE web_intents_defaults ("
56 "action VARCHAR," 70 "action VARCHAR,"
57 "type VARCHAR," 71 "type VARCHAR,"
58 "title VARCHAR," 72 "url_pattern LONGVARCHAR,"
59 "disposition VARCHAR," 73 "user_date INTEGER,"
60 "UNIQUE (service_url, action, type))")) { 74 "suppression INTEGER,"
75 "service_url LONGVARCHAR,"
76 "UNIQUE (action, type, url_pattern))")) {
77 return false;
78 }
79 }
80
81 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_index "
82 "ON web_intents (action)"))
83 return false;
84
85 if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index "
86 "ON web_intents_defaults (action)")) {
61 return false; 87 return false;
62 } 88 }
63 89
64 if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)"))
65 return false;
66
67 return true; 90 return true;
68 } 91 }
69 92
70 // TODO(jhawkins): Figure out Sync story. 93 // TODO(jhawkins): Figure out Sync story.
71 bool WebIntentsTable::IsSyncable() { 94 bool WebIntentsTable::IsSyncable() {
72 return false; 95 return false;
73 } 96 }
74 97
75 bool WebIntentsTable::GetWebIntentServices( 98 bool WebIntentsTable::GetWebIntentServices(
76 const string16& action, 99 const string16& action,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const WebIntentServiceData& service) { 157 const WebIntentServiceData& service) {
135 sql::Statement s(db_->GetUniqueStatement( 158 sql::Statement s(db_->GetUniqueStatement(
136 "DELETE FROM web_intents " 159 "DELETE FROM web_intents "
137 "WHERE service_url = ? AND action = ? AND type = ?")); 160 "WHERE service_url = ? AND action = ? AND type = ?"));
138 s.BindString(0, service.service_url.spec()); 161 s.BindString(0, service.service_url.spec());
139 s.BindString16(1, service.action); 162 s.BindString16(1, service.action);
140 s.BindString16(2, service.type); 163 s.BindString16(2, service.type);
141 164
142 return s.Run(); 165 return s.Run();
143 } 166 }
167
168 bool WebIntentsTable::GetDefaultServices(
169 const string16& action,
170 std::vector<DefaultWebIntentService>* default_services) {
171 sql::Statement s(db_->GetUniqueStatement(
172 "SELECT action, type, url_pattern, user_date, suppression, "
173 "service_url FROM web_intents_defaults "
174 "WHERE action=?"));
175 s.BindString16(0, action);
176
177 while (s.Step()) {
178 DefaultWebIntentService entry;
179 entry.action = s.ColumnString16(0);
180 entry.type = s.ColumnString16(1);
181 if (entry.url_pattern.Parse(s.ColumnString(2)) !=
182 URLPattern::PARSE_SUCCESS) {
183 return false;
184 }
185 entry.user_date = s.ColumnInt(3);
186 entry.suppression = s.ColumnInt(4);
187 entry.service_url = s.ColumnString(5);
188
189 default_services->push_back(entry);
190 }
191
192 return s.Succeeded();
193 }
194
195 bool WebIntentsTable::GetAllDefaultServices(
196 std::vector<DefaultWebIntentService>* default_services) {
197 sql::Statement s(db_->GetUniqueStatement(
198 "SELECT action, type, url_pattern, user_date, suppression, "
199 "service_url FROM web_intents_defaults"));
200
201 while (s.Step()) {
202 DefaultWebIntentService entry;
203 entry.action = s.ColumnString16(0);
204 entry.type = s.ColumnString16(1);
205 if (entry.url_pattern.Parse(s.ColumnString(2)) !=
206 URLPattern::PARSE_SUCCESS) {
207 return false;
208 }
209 entry.user_date = s.ColumnInt(3);
210 entry.suppression = s.ColumnInt(4);
211 entry.service_url = s.ColumnString(5);
212
213 default_services->push_back(entry);
214 }
215
216 return s.Succeeded();
217
218 }
219
220 bool WebIntentsTable::SetDefaultService(
221 const DefaultWebIntentService& default_service) {
222 sql::Statement s(db_->GetUniqueStatement(
223 "INSERT OR REPLACE INTO web_intents_defaults "
224 "(action, type, url_pattern, user_date, suppression, service_url) "
225 "VALUES (?, ?, ?, ?, ?, ?)"));
226 s.BindString16(0, default_service.action);
227 s.BindString16(1, default_service.type);
228 s.BindString(2, default_service.url_pattern.GetAsString());
229 s.BindInt(3, default_service.user_date);
230 s.BindInt(4, default_service.suppression);
231 s.BindString(5, default_service.service_url);
232
233 return s.Run();
234 }
235
236 bool WebIntentsTable::RemoveDefaultService(
237 const DefaultWebIntentService& default_service) {
238 sql::Statement s(db_->GetUniqueStatement(
239 "DELETE FROM web_intents_defaults "
240 "WHERE action = ? AND type = ? AND url_pattern = ?"));
241 s.BindString16(0, default_service.action);
242 s.BindString16(1, default_service.type);
243 s.BindString(2, default_service.url_pattern.GetAsString());
244
245 return s.Run();
246 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_intents_table.h ('k') | chrome/browser/webdata/web_intents_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698