| OLD | NEW |
| 1 // Copyright (c) 2012 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 "components/omnibox/browser/shortcuts_backend.h" | 5 #include "components/omnibox/browser/shortcuts_backend.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 void ShortcutsBackend::InitCompleted() { | 223 void ShortcutsBackend::InitCompleted() { |
| 224 temp_guid_map_->swap(guid_map_); | 224 temp_guid_map_->swap(guid_map_); |
| 225 temp_shortcuts_map_->swap(shortcuts_map_); | 225 temp_shortcuts_map_->swap(shortcuts_map_); |
| 226 temp_shortcuts_map_.reset(NULL); | 226 temp_shortcuts_map_.reset(NULL); |
| 227 temp_guid_map_.reset(NULL); | 227 temp_guid_map_.reset(NULL); |
| 228 UMA_HISTOGRAM_COUNTS_10000("ShortcutsProvider.DatabaseSize", | 228 UMA_HISTOGRAM_COUNTS_10000("ShortcutsProvider.DatabaseSize", |
| 229 shortcuts_map_.size()); | 229 shortcuts_map_.size()); |
| 230 current_state_ = INITIALIZED; | 230 current_state_ = INITIALIZED; |
| 231 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 231 for (ShortcutsBackendObserver& observer : observer_list_) |
| 232 OnShortcutsLoaded()); | 232 observer.OnShortcutsLoaded(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool ShortcutsBackend::AddShortcut( | 235 bool ShortcutsBackend::AddShortcut( |
| 236 const ShortcutsDatabase::Shortcut& shortcut) { | 236 const ShortcutsDatabase::Shortcut& shortcut) { |
| 237 if (!initialized()) | 237 if (!initialized()) |
| 238 return false; | 238 return false; |
| 239 DCHECK(guid_map_.find(shortcut.id) == guid_map_.end()); | 239 DCHECK(guid_map_.find(shortcut.id) == guid_map_.end()); |
| 240 guid_map_[shortcut.id] = shortcuts_map_.insert( | 240 guid_map_[shortcut.id] = shortcuts_map_.insert( |
| 241 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); | 241 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); |
| 242 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 242 for (ShortcutsBackendObserver& observer : observer_list_) |
| 243 OnShortcutsChanged()); | 243 observer.OnShortcutsChanged(); |
| 244 return no_db_access_ || | 244 return no_db_access_ || |
| 245 db_runner_->PostTask( | 245 db_runner_->PostTask( |
| 246 FROM_HERE, | 246 FROM_HERE, |
| 247 base::Bind(base::IgnoreResult(&ShortcutsDatabase::AddShortcut), | 247 base::Bind(base::IgnoreResult(&ShortcutsDatabase::AddShortcut), |
| 248 db_.get(), shortcut)); | 248 db_.get(), shortcut)); |
| 249 } | 249 } |
| 250 | 250 |
| 251 bool ShortcutsBackend::UpdateShortcut( | 251 bool ShortcutsBackend::UpdateShortcut( |
| 252 const ShortcutsDatabase::Shortcut& shortcut) { | 252 const ShortcutsDatabase::Shortcut& shortcut) { |
| 253 if (!initialized()) | 253 if (!initialized()) |
| 254 return false; | 254 return false; |
| 255 GuidMap::iterator it(guid_map_.find(shortcut.id)); | 255 GuidMap::iterator it(guid_map_.find(shortcut.id)); |
| 256 if (it != guid_map_.end()) | 256 if (it != guid_map_.end()) |
| 257 shortcuts_map_.erase(it->second); | 257 shortcuts_map_.erase(it->second); |
| 258 guid_map_[shortcut.id] = shortcuts_map_.insert( | 258 guid_map_[shortcut.id] = shortcuts_map_.insert( |
| 259 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); | 259 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); |
| 260 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 260 for (ShortcutsBackendObserver& observer : observer_list_) |
| 261 OnShortcutsChanged()); | 261 observer.OnShortcutsChanged(); |
| 262 return no_db_access_ || | 262 return no_db_access_ || |
| 263 db_runner_->PostTask( | 263 db_runner_->PostTask( |
| 264 FROM_HERE, | 264 FROM_HERE, |
| 265 base::Bind(base::IgnoreResult(&ShortcutsDatabase::UpdateShortcut), | 265 base::Bind(base::IgnoreResult(&ShortcutsDatabase::UpdateShortcut), |
| 266 db_.get(), shortcut)); | 266 db_.get(), shortcut)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 bool ShortcutsBackend::DeleteShortcutsWithIDs( | 269 bool ShortcutsBackend::DeleteShortcutsWithIDs( |
| 270 const ShortcutsDatabase::ShortcutIDs& shortcut_ids) { | 270 const ShortcutsDatabase::ShortcutIDs& shortcut_ids) { |
| 271 if (!initialized()) | 271 if (!initialized()) |
| 272 return false; | 272 return false; |
| 273 for (size_t i = 0; i < shortcut_ids.size(); ++i) { | 273 for (size_t i = 0; i < shortcut_ids.size(); ++i) { |
| 274 GuidMap::iterator it(guid_map_.find(shortcut_ids[i])); | 274 GuidMap::iterator it(guid_map_.find(shortcut_ids[i])); |
| 275 if (it != guid_map_.end()) { | 275 if (it != guid_map_.end()) { |
| 276 shortcuts_map_.erase(it->second); | 276 shortcuts_map_.erase(it->second); |
| 277 guid_map_.erase(it); | 277 guid_map_.erase(it); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 280 for (ShortcutsBackendObserver& observer : observer_list_) |
| 281 OnShortcutsChanged()); | 281 observer.OnShortcutsChanged(); |
| 282 return no_db_access_ || | 282 return no_db_access_ || |
| 283 db_runner_->PostTask( | 283 db_runner_->PostTask( |
| 284 FROM_HERE, | 284 FROM_HERE, |
| 285 base::Bind( | 285 base::Bind( |
| 286 base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithIDs), | 286 base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithIDs), |
| 287 db_.get(), shortcut_ids)); | 287 db_.get(), shortcut_ids)); |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool ShortcutsBackend::DeleteShortcutsWithURL(const GURL& url, | 290 bool ShortcutsBackend::DeleteShortcutsWithURL(const GURL& url, |
| 291 bool exact_match) { | 291 bool exact_match) { |
| 292 const std::string& url_spec = url.spec(); | 292 const std::string& url_spec = url.spec(); |
| 293 ShortcutsDatabase::ShortcutIDs shortcut_ids; | 293 ShortcutsDatabase::ShortcutIDs shortcut_ids; |
| 294 for (GuidMap::iterator it(guid_map_.begin()); it != guid_map_.end(); ) { | 294 for (GuidMap::iterator it(guid_map_.begin()); it != guid_map_.end(); ) { |
| 295 if (exact_match ? (it->second->second.match_core.destination_url == url) | 295 if (exact_match ? (it->second->second.match_core.destination_url == url) |
| 296 : base::StartsWith( | 296 : base::StartsWith( |
| 297 it->second->second.match_core.destination_url.spec(), | 297 it->second->second.match_core.destination_url.spec(), |
| 298 url_spec, base::CompareCase::SENSITIVE)) { | 298 url_spec, base::CompareCase::SENSITIVE)) { |
| 299 shortcut_ids.push_back(it->first); | 299 shortcut_ids.push_back(it->first); |
| 300 shortcuts_map_.erase(it->second); | 300 shortcuts_map_.erase(it->second); |
| 301 guid_map_.erase(it++); | 301 guid_map_.erase(it++); |
| 302 } else { | 302 } else { |
| 303 ++it; | 303 ++it; |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 306 for (ShortcutsBackendObserver& observer : observer_list_) |
| 307 OnShortcutsChanged()); | 307 observer.OnShortcutsChanged(); |
| 308 return no_db_access_ || | 308 return no_db_access_ || |
| 309 db_runner_->PostTask( | 309 db_runner_->PostTask( |
| 310 FROM_HERE, | 310 FROM_HERE, |
| 311 base::Bind( | 311 base::Bind( |
| 312 base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithURL), | 312 base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithURL), |
| 313 db_.get(), url_spec)); | 313 db_.get(), url_spec)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool ShortcutsBackend::DeleteAllShortcuts() { | 316 bool ShortcutsBackend::DeleteAllShortcuts() { |
| 317 if (!initialized()) | 317 if (!initialized()) |
| 318 return false; | 318 return false; |
| 319 shortcuts_map_.clear(); | 319 shortcuts_map_.clear(); |
| 320 guid_map_.clear(); | 320 guid_map_.clear(); |
| 321 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 321 for (ShortcutsBackendObserver& observer : observer_list_) |
| 322 OnShortcutsChanged()); | 322 observer.OnShortcutsChanged(); |
| 323 return no_db_access_ || | 323 return no_db_access_ || |
| 324 db_runner_->PostTask( | 324 db_runner_->PostTask( |
| 325 FROM_HERE, base::Bind(base::IgnoreResult( | 325 FROM_HERE, base::Bind(base::IgnoreResult( |
| 326 &ShortcutsDatabase::DeleteAllShortcuts), | 326 &ShortcutsDatabase::DeleteAllShortcuts), |
| 327 db_.get())); | 327 db_.get())); |
| 328 } | 328 } |
| OLD | NEW |