| 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/keyword_table.h" | 5 #include "chrome/browser/webdata/keyword_table.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 DCHECK(url.id()); | 141 DCHECK(url.id()); |
| 142 // Be sure to change kUrlIdPosition if you add columns | 142 // Be sure to change kUrlIdPosition if you add columns |
| 143 sql::Statement s(db_->GetUniqueStatement( | 143 sql::Statement s(db_->GetUniqueStatement( |
| 144 "INSERT INTO keywords " | 144 "INSERT INTO keywords " |
| 145 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " | 145 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " |
| 146 "originating_url, date_created, usage_count, input_encodings, " | 146 "originating_url, date_created, usage_count, input_encodings, " |
| 147 "show_in_default_list, suggest_url, prepopulate_id, " | 147 "show_in_default_list, suggest_url, prepopulate_id, " |
| 148 "autogenerate_keyword, logo_id, created_by_policy, instant_url, " | 148 "autogenerate_keyword, logo_id, created_by_policy, instant_url, " |
| 149 "last_modified, sync_guid, id) VALUES " | 149 "last_modified, sync_guid, id) VALUES " |
| 150 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); | 150 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); |
| 151 if (!s) { | |
| 152 NOTREACHED() << "Statement prepare failed"; | |
| 153 return false; | |
| 154 } | |
| 155 BindURLToStatement(url, &s); | 151 BindURLToStatement(url, &s); |
| 156 s.BindInt64(kUrlIdPosition, url.id()); | 152 s.BindInt64(kUrlIdPosition, url.id()); |
| 153 |
| 157 if (!s.Run()) { | 154 if (!s.Run()) { |
| 158 NOTREACHED(); | |
| 159 return false; | 155 return false; |
| 160 } | 156 } |
| 161 return UpdateBackupSignature(); | 157 return UpdateBackupSignature(); |
| 162 } | 158 } |
| 163 | 159 |
| 164 bool KeywordTable::RemoveKeyword(TemplateURLID id) { | 160 bool KeywordTable::RemoveKeyword(TemplateURLID id) { |
| 165 DCHECK(id); | 161 DCHECK(id); |
| 166 sql::Statement s(db_->GetUniqueStatement("DELETE FROM keywords WHERE id=?")); | 162 sql::Statement s( |
| 167 if (!s) { | 163 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); |
| 168 NOTREACHED() << "Statement prepare failed"; | |
| 169 return false; | |
| 170 } | |
| 171 s.BindInt64(0, id); | 164 s.BindInt64(0, id); |
| 165 |
| 172 return s.Run() && UpdateBackupSignature(); | 166 return s.Run() && UpdateBackupSignature(); |
| 173 } | 167 } |
| 174 | 168 |
| 175 bool KeywordTable::GetKeywords(std::vector<TemplateURL*>* urls) { | 169 bool KeywordTable::GetKeywords(std::vector<TemplateURL*>* urls) { |
| 176 sql::Statement s(db_->GetUniqueStatement( | 170 sql::Statement s(db_->GetUniqueStatement( |
| 177 "SELECT id, short_name, keyword, favicon_url, url, " | 171 "SELECT id, short_name, keyword, favicon_url, url, " |
| 178 "safe_for_autoreplace, originating_url, date_created, " | 172 "safe_for_autoreplace, originating_url, date_created, " |
| 179 "usage_count, input_encodings, show_in_default_list, " | 173 "usage_count, input_encodings, show_in_default_list, " |
| 180 "suggest_url, prepopulate_id, autogenerate_keyword, logo_id, " | 174 "suggest_url, prepopulate_id, autogenerate_keyword, logo_id, " |
| 181 "created_by_policy, instant_url, last_modified, sync_guid " | 175 "created_by_policy, instant_url, last_modified, sync_guid " |
| 182 "FROM keywords ORDER BY id ASC")); | 176 "FROM keywords ORDER BY id ASC")); |
| 183 if (!s) { | 177 |
| 184 NOTREACHED() << "Statement prepare failed"; | |
| 185 return false; | |
| 186 } | |
| 187 while (s.Step()) { | 178 while (s.Step()) { |
| 188 TemplateURL* template_url = new TemplateURL(); | 179 TemplateURL* template_url = new TemplateURL(); |
| 189 GetURLFromStatement(s, template_url); | 180 GetURLFromStatement(s, template_url); |
| 190 urls->push_back(template_url); | 181 urls->push_back(template_url); |
| 191 } | 182 } |
| 192 return s.Succeeded(); | 183 return s.Succeeded(); |
| 193 } | 184 } |
| 194 | 185 |
| 195 bool KeywordTable::UpdateKeyword(const TemplateURL& url) { | 186 bool KeywordTable::UpdateKeyword(const TemplateURL& url) { |
| 196 DCHECK(url.id()); | 187 DCHECK(url.id()); |
| 197 // Be sure to change kUrlIdPosition if you add columns | 188 // Be sure to change kUrlIdPosition if you add columns |
| 198 sql::Statement s(db_->GetUniqueStatement( | 189 sql::Statement s(db_->GetUniqueStatement( |
| 199 "UPDATE keywords " | 190 "UPDATE keywords " |
| 200 "SET short_name=?, keyword=?, favicon_url=?, url=?, " | 191 "SET short_name=?, keyword=?, favicon_url=?, url=?, " |
| 201 "safe_for_autoreplace=?, originating_url=?, date_created=?, " | 192 "safe_for_autoreplace=?, originating_url=?, date_created=?, " |
| 202 "usage_count=?, input_encodings=?, show_in_default_list=?, " | 193 "usage_count=?, input_encodings=?, show_in_default_list=?, " |
| 203 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, " | 194 "suggest_url=?, prepopulate_id=?, autogenerate_keyword=?, " |
| 204 "logo_id=?, created_by_policy=?, instant_url=?, last_modified=?, " | 195 "logo_id=?, created_by_policy=?, instant_url=?, last_modified=?, " |
| 205 "sync_guid=? WHERE id=?")); | 196 "sync_guid=? WHERE id=?")); |
| 206 if (!s) { | |
| 207 NOTREACHED() << "Statement prepare failed"; | |
| 208 return false; | |
| 209 } | |
| 210 BindURLToStatement(url, &s); | 197 BindURLToStatement(url, &s); |
| 211 s.BindInt64(kUrlIdPosition, url.id()); | 198 s.BindInt64(kUrlIdPosition, url.id()); |
| 199 |
| 212 return s.Run() && UpdateBackupSignature(); | 200 return s.Run() && UpdateBackupSignature(); |
| 213 } | 201 } |
| 214 | 202 |
| 215 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { | 203 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { |
| 216 return meta_table_->SetValue(kDefaultSearchProviderKey, id) && | 204 return meta_table_->SetValue(kDefaultSearchProviderKey, id) && |
| 217 UpdateBackupSignature(); | 205 UpdateBackupSignature(); |
| 218 } | 206 } |
| 219 | 207 |
| 220 int64 KeywordTable::GetDefaultSearchProviderID() { | 208 int64 KeywordTable::GetDefaultSearchProviderID() { |
| 221 int64 value = 0; | 209 int64 value = 0; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 return false; | 636 return false; |
| 649 } | 637 } |
| 650 if (!meta_table_->SetValue(kDefaultSearchBackupKey, backup_url)) { | 638 if (!meta_table_->SetValue(kDefaultSearchBackupKey, backup_url)) { |
| 651 LOG(WARNING) << "Failed to update the keyword backup"; | 639 LOG(WARNING) << "Failed to update the keyword backup"; |
| 652 return false; | 640 return false; |
| 653 } | 641 } |
| 654 | 642 |
| 655 *backup = backup_url; | 643 *backup = backup_url; |
| 656 return true; | 644 return true; |
| 657 } | 645 } |
| OLD | NEW |