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 "chrome/browser/autocomplete/shortcuts_backend.h" | 5 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 it->second.id, text, MatchToMatchCore(match, profile_), now, | 139 it->second.id, text, MatchToMatchCore(match, profile_), now, |
140 it->second.number_of_hits + 1)); | 140 it->second.number_of_hits + 1)); |
141 return; | 141 return; |
142 } | 142 } |
143 } | 143 } |
144 AddShortcut(ShortcutsDatabase::Shortcut( | 144 AddShortcut(ShortcutsDatabase::Shortcut( |
145 base::GenerateGUID(), text, MatchToMatchCore(match, profile_), now, 1)); | 145 base::GenerateGUID(), text, MatchToMatchCore(match, profile_), now, 1)); |
146 } | 146 } |
147 | 147 |
148 ShortcutsBackend::~ShortcutsBackend() { | 148 ShortcutsBackend::~ShortcutsBackend() { |
| 149 if (db_) { |
| 150 auto* db = db_.get(); |
| 151 db->AddRef(); |
| 152 db_ = nullptr; |
| 153 if (!BrowserThread::ReleaseSoon(BrowserThread::DB, FROM_HERE, db)) |
| 154 db->Release(); |
| 155 } |
149 } | 156 } |
150 | 157 |
151 // static | 158 // static |
152 ShortcutsDatabase::Shortcut::MatchCore ShortcutsBackend::MatchToMatchCore( | 159 ShortcutsDatabase::Shortcut::MatchCore ShortcutsBackend::MatchToMatchCore( |
153 const AutocompleteMatch& match, | 160 const AutocompleteMatch& match, |
154 Profile* profile) { | 161 Profile* profile) { |
155 const AutocompleteMatch::Type match_type = GetTypeForShortcut(match.type); | 162 const AutocompleteMatch::Type match_type = GetTypeForShortcut(match.type); |
156 TemplateURLService* service = | 163 TemplateURLService* service = |
157 TemplateURLServiceFactory::GetForProfile(profile); | 164 TemplateURLServiceFactory::GetForProfile(profile); |
158 const AutocompleteMatch& normalized_match = | 165 const AutocompleteMatch& normalized_match = |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 guid_map_.clear(); | 343 guid_map_.clear(); |
337 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 344 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
338 OnShortcutsChanged()); | 345 OnShortcutsChanged()); |
339 return no_db_access_ || | 346 return no_db_access_ || |
340 BrowserThread::PostTask( | 347 BrowserThread::PostTask( |
341 BrowserThread::DB, FROM_HERE, | 348 BrowserThread::DB, FROM_HERE, |
342 base::Bind( | 349 base::Bind( |
343 base::IgnoreResult(&ShortcutsDatabase::DeleteAllShortcuts), | 350 base::IgnoreResult(&ShortcutsDatabase::DeleteAllShortcuts), |
344 db_.get())); | 351 db_.get())); |
345 } | 352 } |
OLD | NEW |