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" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 bool WebIntentsTable::GetWebIntentServices( | 75 bool WebIntentsTable::GetWebIntentServices( |
76 const string16& action, | 76 const string16& action, |
77 std::vector<WebIntentServiceData>* services) { | 77 std::vector<WebIntentServiceData>* services) { |
78 DCHECK(services); | 78 DCHECK(services); |
79 sql::Statement s(db_->GetUniqueStatement( | 79 sql::Statement s(db_->GetUniqueStatement( |
80 "SELECT service_url, action, type, title, disposition FROM web_intents " | 80 "SELECT service_url, action, type, title, disposition FROM web_intents " |
81 "WHERE action=?")); | 81 "WHERE action=?")); |
| 82 s.BindString16(0, action); |
82 | 83 |
83 s.BindString16(0, action); | |
84 return ExtractIntents(&s, services); | 84 return ExtractIntents(&s, services); |
85 } | 85 } |
86 | 86 |
87 // TODO(gbillock): This currently does a full-table scan. Eventually we will | 87 // TODO(gbillock): This currently does a full-table scan. Eventually we will |
88 // store registrations by domain, and so have an indexed origin. At that time, | 88 // store registrations by domain, and so have an indexed origin. At that time, |
89 // this should just change to do lookup by origin instead of URL. | 89 // this should just change to do lookup by origin instead of URL. |
90 bool WebIntentsTable::GetWebIntentServicesForURL( | 90 bool WebIntentsTable::GetWebIntentServicesForURL( |
91 const string16& service_url, | 91 const string16& service_url, |
92 std::vector<WebIntentServiceData>* services) { | 92 std::vector<WebIntentServiceData>* services) { |
93 DCHECK(services); | 93 DCHECK(services); |
94 sql::Statement s(db_->GetUniqueStatement( | 94 sql::Statement s(db_->GetUniqueStatement( |
95 "SELECT service_url, action, type, title, disposition FROM web_intents " | 95 "SELECT service_url, action, type, title, disposition FROM web_intents " |
96 "WHERE service_url=?")); | 96 "WHERE service_url=?")); |
| 97 s.BindString16(0, service_url); |
97 | 98 |
98 s.BindString16(0, service_url); | |
99 return ExtractIntents(&s, services); | 99 return ExtractIntents(&s, services); |
100 } | 100 } |
101 | 101 |
102 bool WebIntentsTable::GetAllWebIntentServices( | 102 bool WebIntentsTable::GetAllWebIntentServices( |
103 std::vector<WebIntentServiceData>* services) { | 103 std::vector<WebIntentServiceData>* services) { |
104 DCHECK(services); | 104 DCHECK(services); |
105 sql::Statement s(db_->GetUniqueStatement( | 105 sql::Statement s(db_->GetUniqueStatement( |
106 "SELECT service_url, action, type, title, disposition FROM web_intents")); | 106 "SELECT service_url, action, type, title, disposition FROM web_intents")); |
107 | 107 |
108 return ExtractIntents(&s, services); | 108 return ExtractIntents(&s, services); |
109 } | 109 } |
110 | 110 |
111 bool WebIntentsTable::SetWebIntentService(const WebIntentServiceData& service) { | 111 bool WebIntentsTable::SetWebIntentService(const WebIntentServiceData& service) { |
112 sql::Statement s(db_->GetUniqueStatement( | 112 sql::Statement s(db_->GetUniqueStatement( |
113 "INSERT OR REPLACE INTO web_intents " | 113 "INSERT OR REPLACE INTO web_intents " |
114 "(service_url, type, action, title, disposition) " | 114 "(service_url, type, action, title, disposition) " |
115 "VALUES (?, ?, ?, ?, ?)")); | 115 "VALUES (?, ?, ?, ?, ?)")); |
116 | 116 |
117 // Default to window disposition. | 117 // Default to window disposition. |
118 string16 disposition = ASCIIToUTF16("window"); | 118 string16 disposition = ASCIIToUTF16("window"); |
119 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE) | 119 if (service.disposition == WebIntentServiceData::DISPOSITION_INLINE) |
120 disposition = ASCIIToUTF16("inline"); | 120 disposition = ASCIIToUTF16("inline"); |
121 s.BindString(0, service.service_url.spec()); | 121 s.BindString(0, service.service_url.spec()); |
122 s.BindString16(1, service.type); | 122 s.BindString16(1, service.type); |
123 s.BindString16(2, service.action); | 123 s.BindString16(2, service.action); |
124 s.BindString16(3, service.title); | 124 s.BindString16(3, service.title); |
125 s.BindString16(4, disposition); | 125 s.BindString16(4, disposition); |
| 126 |
126 return s.Run(); | 127 return s.Run(); |
127 } | 128 } |
128 | 129 |
129 // TODO(jhawkins): Investigate the need to remove rows matching only | 130 // TODO(jhawkins): Investigate the need to remove rows matching only |
130 // |service.service_url|. It's unlikely the user will be given the ability to | 131 // |service.service_url|. It's unlikely the user will be given the ability to |
131 // remove at the granularity of actions or types. | 132 // remove at the granularity of actions or types. |
132 bool WebIntentsTable::RemoveWebIntentService( | 133 bool WebIntentsTable::RemoveWebIntentService( |
133 const WebIntentServiceData& service) { | 134 const WebIntentServiceData& service) { |
134 sql::Statement s(db_->GetUniqueStatement( | 135 sql::Statement s(db_->GetUniqueStatement( |
135 "DELETE FROM web_intents " | 136 "DELETE FROM web_intents " |
136 "WHERE service_url = ? AND action = ? AND type = ?")); | 137 "WHERE service_url = ? AND action = ? AND type = ?")); |
137 | |
138 s.BindString(0, service.service_url.spec()); | 138 s.BindString(0, service.service_url.spec()); |
139 s.BindString16(1, service.action); | 139 s.BindString16(1, service.action); |
140 s.BindString16(2, service.type); | 140 s.BindString16(2, service.type); |
| 141 |
141 return s.Run(); | 142 return s.Run(); |
142 } | 143 } |
OLD | NEW |