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

Side by Side Diff: chrome/browser/autocomplete/shortcuts_backend.cc

Issue 200493006: Move the ShortcutsBackend from history to autocomplete so that it can fully (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 9 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) 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/history/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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/i18n/case_conversion.h" 14 #include "base/i18n/case_conversion.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
(...skipping 10 matching lines...) Expand all
26 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 namespace { 32 namespace {
33 33
34 // Takes Match classification vector and removes all matched positions, 34 // Takes Match classification vector and removes all matched positions,
35 // compacting repetitions if necessary. 35 // compacting repetitions if necessary.
36 ACMatchClassifications StripMatchMarkers( 36 std::string StripMatchMarkers(const ACMatchClassifications& matches) {
37 const ACMatchClassifications& matches) {
38 ACMatchClassifications unmatched; 37 ACMatchClassifications unmatched;
39 for (ACMatchClassifications::const_iterator i(matches.begin()); 38 for (ACMatchClassifications::const_iterator i(matches.begin());
40 i != matches.end(); ++i) { 39 i != matches.end(); ++i) {
41 AutocompleteMatch::AddLastClassificationIfNecessary( 40 AutocompleteMatch::AddLastClassificationIfNecessary(
42 &unmatched, i->offset, i->style & ~ACMatchClassification::MATCH); 41 &unmatched, i->offset, i->style & ~ACMatchClassification::MATCH);
43 } 42 }
44 return unmatched; 43 return AutocompleteMatch::ClassificationsToString(unmatched);
45 } 44 }
46 45
47 // Normally shortcuts have the same match type as the original match they were 46 // Normally shortcuts have the same match type as the original match they were
48 // created from, but for certain match types, we should modify the shortcut's 47 // created from, but for certain match types, we should modify the shortcut's
49 // type slightly to reflect that the origin of the shortcut is historical. 48 // type slightly to reflect that the origin of the shortcut is historical.
50 AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) { 49 AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) {
51 switch (type) { 50 switch (type) {
52 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: 51 case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
53 case AutocompleteMatchType::NAVSUGGEST: 52 case AutocompleteMatchType::NAVSUGGEST:
54 return AutocompleteMatchType::HISTORY_URL; 53 return AutocompleteMatchType::HISTORY_URL;
55 54
56 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED: 55 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
57 case AutocompleteMatchType::SEARCH_SUGGEST: 56 case AutocompleteMatchType::SEARCH_SUGGEST:
58 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY: 57 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
59 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE: 58 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
60 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED: 59 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
61 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE: 60 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
62 return AutocompleteMatchType::SEARCH_HISTORY; 61 return AutocompleteMatchType::SEARCH_HISTORY;
63 62
64 default: 63 default:
65 return type; 64 return type;
66 } 65 }
67 } 66 }
68 67
69 } // namespace 68 } // namespace
70 69
71 namespace history {
72
73 // ShortcutsBackend::Shortcut::MatchCore --------------------------------------
74
75 ShortcutsBackend::Shortcut::MatchCore::MatchCore(
76 const AutocompleteMatch& match)
77 : fill_into_edit(match.fill_into_edit),
78 destination_url(match.destination_url),
79 contents(match.contents),
80 contents_class(StripMatchMarkers(match.contents_class)),
81 description(match.description),
82 description_class(StripMatchMarkers(match.description_class)),
83 transition(match.transition),
84 type(GetTypeForShortcut(match.type)),
85 keyword(match.keyword) {
86 }
87
88 ShortcutsBackend::Shortcut::MatchCore::MatchCore(
89 const base::string16& fill_into_edit,
90 const GURL& destination_url,
91 const base::string16& contents,
92 const ACMatchClassifications& contents_class,
93 const base::string16& description,
94 const ACMatchClassifications& description_class,
95 content::PageTransition transition,
96 AutocompleteMatch::Type type,
97 const base::string16& keyword)
98 : fill_into_edit(fill_into_edit),
99 destination_url(destination_url),
100 contents(contents),
101 contents_class(StripMatchMarkers(contents_class)),
102 description(description),
103 description_class(StripMatchMarkers(description_class)),
104 transition(transition),
105 type(GetTypeForShortcut(type)),
106 keyword(keyword) {
107 }
108
109 ShortcutsBackend::Shortcut::MatchCore::~MatchCore() {
110 }
111
112 AutocompleteMatch ShortcutsBackend::Shortcut::MatchCore::ToMatch() const {
113 AutocompleteMatch match;
114 match.fill_into_edit = fill_into_edit;
115 match.destination_url = destination_url;
116 match.contents = contents;
117 match.contents_class = contents_class;
118 match.description = description;
119 match.description_class = description_class;
120 match.transition = transition;
121 match.type = type;
122 match.keyword = keyword;
123 return match;
124 }
125
126
127 // ShortcutsBackend::Shortcut -------------------------------------------------
128
129 ShortcutsBackend::Shortcut::Shortcut(
130 const std::string& id,
131 const base::string16& text,
132 const MatchCore& match_core,
133 const base::Time& last_access_time,
134 int number_of_hits)
135 : id(id),
136 text(text),
137 match_core(match_core),
138 last_access_time(last_access_time),
139 number_of_hits(number_of_hits) {
140 }
141
142 ShortcutsBackend::Shortcut::Shortcut()
143 : match_core(AutocompleteMatch()),
144 last_access_time(base::Time::Now()),
145 number_of_hits(0) {
146 }
147
148 ShortcutsBackend::Shortcut::~Shortcut() {
149 }
150
151 70
152 // ShortcutsBackend ----------------------------------------------------------- 71 // ShortcutsBackend -----------------------------------------------------------
153 72
154 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) 73 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db)
155 : current_state_(NOT_INITIALIZED), 74 : current_state_(NOT_INITIALIZED),
156 no_db_access_(suppress_db) { 75 no_db_access_(suppress_db) {
157 if (!suppress_db) { 76 if (!suppress_db) {
158 db_ = new ShortcutsDatabase( 77 db_ = new history::ShortcutsDatabase(
159 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); 78 profile->GetPath().Append(chrome::kShortcutsDatabaseName));
160 } 79 }
161 // |profile| can be NULL in tests. 80 // |profile| can be NULL in tests.
162 if (profile) { 81 if (profile) {
163 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 82 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
164 content::Source<Profile>(profile)); 83 content::Source<Profile>(profile));
165 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, 84 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED,
166 content::Source<Profile>(profile)); 85 content::Source<Profile>(profile));
167 } 86 }
168 } 87 }
169 88
170 bool ShortcutsBackend::Init() { 89 bool ShortcutsBackend::Init() {
171 if (current_state_ != NOT_INITIALIZED) 90 if (current_state_ != NOT_INITIALIZED)
172 return false; 91 return false;
173 92
174 if (no_db_access_) { 93 if (no_db_access_) {
175 current_state_ = INITIALIZED; 94 current_state_ = INITIALIZED;
176 return true; 95 return true;
177 } 96 }
178 97
179 current_state_ = INITIALIZING; 98 current_state_ = INITIALIZING;
180 return BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 99 return BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
181 base::Bind(&ShortcutsBackend::InitInternal, this)); 100 base::Bind(&ShortcutsBackend::InitInternal, this));
182 } 101 }
183 102
184 bool ShortcutsBackend::DeleteShortcutsWithUrl(const GURL& shortcut_url) { 103 bool ShortcutsBackend::DeleteShortcutsWithURL(const GURL& shortcut_url) {
185 return initialized() && DeleteShortcutsWithUrl(shortcut_url, true); 104 return initialized() && DeleteShortcutsWithURL(shortcut_url, true);
186 } 105 }
187 106
188 void ShortcutsBackend::AddObserver(ShortcutsBackendObserver* obs) { 107 void ShortcutsBackend::AddObserver(ShortcutsBackendObserver* obs) {
189 observer_list_.AddObserver(obs); 108 observer_list_.AddObserver(obs);
190 } 109 }
191 110
192 void ShortcutsBackend::RemoveObserver(ShortcutsBackendObserver* obs) { 111 void ShortcutsBackend::RemoveObserver(ShortcutsBackendObserver* obs) {
193 observer_list_.RemoveObserver(obs); 112 observer_list_.RemoveObserver(obs);
194 } 113 }
195 114
196 void ShortcutsBackend::AddOrUpdateShortcut(const base::string16& text, 115 void ShortcutsBackend::AddOrUpdateShortcut(const base::string16& text,
197 const AutocompleteMatch& match) { 116 const AutocompleteMatch& match) {
198 const base::string16 text_lowercase(base::i18n::ToLower(text)); 117 const base::string16 text_lowercase(base::i18n::ToLower(text));
199 const base::Time now(base::Time::Now()); 118 const base::Time now(base::Time::Now());
200 for (ShortcutMap::const_iterator it( 119 for (ShortcutMap::const_iterator it(
201 shortcuts_map_.lower_bound(text_lowercase)); 120 shortcuts_map_.lower_bound(text_lowercase));
202 it != shortcuts_map_.end() && 121 it != shortcuts_map_.end() &&
203 StartsWith(it->first, text_lowercase, true); ++it) { 122 StartsWith(it->first, text_lowercase, true); ++it) {
204 if (match.destination_url == it->second.match_core.destination_url) { 123 if (match.destination_url == it->second.match_core.destination_url) {
205 UpdateShortcut(Shortcut(it->second.id, text, Shortcut::MatchCore(match), 124 UpdateShortcut(history::ShortcutsDatabase::Shortcut(
206 now, it->second.number_of_hits + 1)); 125 it->second.id, text, MatchToMatchCore(match), now,
126 it->second.number_of_hits + 1));
207 return; 127 return;
208 } 128 }
209 } 129 }
210 AddShortcut(Shortcut(base::GenerateGUID(), text, Shortcut::MatchCore(match), 130 AddShortcut(history::ShortcutsDatabase::Shortcut(
211 now, 1)); 131 base::GenerateGUID(), text, MatchToMatchCore(match), now, 1));
212 } 132 }
213 133
214 ShortcutsBackend::~ShortcutsBackend() { 134 ShortcutsBackend::~ShortcutsBackend() {
215 } 135 }
216 136
137 // static
138 history::ShortcutsDatabase::Shortcut::MatchCore
139 ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match) {
140 return history::ShortcutsDatabase::Shortcut::MatchCore(
141 match.fill_into_edit, match.destination_url, match.contents,
142 StripMatchMarkers(match.contents_class), match.description,
143 StripMatchMarkers(match.description_class), match.transition,
144 GetTypeForShortcut(match.type), match.keyword);
145 }
146
217 void ShortcutsBackend::ShutdownOnUIThread() { 147 void ShortcutsBackend::ShutdownOnUIThread() {
218 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) || 148 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
219 BrowserThread::CurrentlyOn(BrowserThread::UI)); 149 BrowserThread::CurrentlyOn(BrowserThread::UI));
220 notification_registrar_.RemoveAll(); 150 notification_registrar_.RemoveAll();
221 } 151 }
222 152
223 void ShortcutsBackend::Observe(int type, 153 void ShortcutsBackend::Observe(int type,
224 const content::NotificationSource& source, 154 const content::NotificationSource& source,
225 const content::NotificationDetails& details) { 155 const content::NotificationDetails& details) {
226 if (!initialized()) 156 if (!initialized())
227 return; 157 return;
228 158
229 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 159 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
230 // When an extension is unloaded, we want to remove any Shortcuts associated 160 // When an extension is unloaded, we want to remove any Shortcuts associated
231 // with it. 161 // with it.
232 DeleteShortcutsWithUrl(content::Details<extensions::UnloadedExtensionInfo>( 162 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>(
233 details)->extension->url(), false); 163 details)->extension->url(), false);
234 return; 164 return;
235 } 165 }
236 166
237 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); 167 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type);
238 const history::URLsDeletedDetails* deleted_details = 168 const history::URLsDeletedDetails* deleted_details =
239 content::Details<const history::URLsDeletedDetails>(details).ptr(); 169 content::Details<const history::URLsDeletedDetails>(details).ptr();
240 if (deleted_details->all_history) 170 if (deleted_details->all_history)
241 DeleteAllShortcuts(); 171 DeleteAllShortcuts();
242 const URLRows& rows(deleted_details->rows); 172 const history::URLRows& rows(deleted_details->rows);
243 std::vector<std::string> shortcut_ids; 173 history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
244 174
245 for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end(); 175 for (GuidMap::const_iterator it(guid_map_.begin()); it != guid_map_.end();
246 ++it) { 176 ++it) {
247 if (std::find_if( 177 if (std::find_if(
248 rows.begin(), rows.end(), URLRow::URLRowHasURL( 178 rows.begin(), rows.end(), history::URLRow::URLRowHasURL(
249 it->second->second.match_core.destination_url)) != rows.end()) 179 it->second->second.match_core.destination_url)) != rows.end())
250 shortcut_ids.push_back(it->first); 180 shortcut_ids.push_back(it->first);
251 } 181 }
252 DeleteShortcutsWithIds(shortcut_ids); 182 DeleteShortcutsWithIDs(shortcut_ids);
253 } 183 }
254 184
255 void ShortcutsBackend::InitInternal() { 185 void ShortcutsBackend::InitInternal() {
256 DCHECK(current_state_ == INITIALIZING); 186 DCHECK(current_state_ == INITIALIZING);
257 db_->Init(); 187 db_->Init();
258 ShortcutsDatabase::GuidToShortcutMap shortcuts; 188 history::ShortcutsDatabase::GuidToShortcutMap shortcuts;
259 db_->LoadShortcuts(&shortcuts); 189 db_->LoadShortcuts(&shortcuts);
260 temp_shortcuts_map_.reset(new ShortcutMap); 190 temp_shortcuts_map_.reset(new ShortcutMap);
261 temp_guid_map_.reset(new GuidMap); 191 temp_guid_map_.reset(new GuidMap);
262 for (ShortcutsDatabase::GuidToShortcutMap::const_iterator it( 192 for (history::ShortcutsDatabase::GuidToShortcutMap::const_iterator it(
263 shortcuts.begin()); it != shortcuts.end(); ++it) { 193 shortcuts.begin()); it != shortcuts.end(); ++it) {
264 (*temp_guid_map_)[it->first] = temp_shortcuts_map_->insert( 194 (*temp_guid_map_)[it->first] = temp_shortcuts_map_->insert(
265 std::make_pair(base::i18n::ToLower(it->second.text), it->second)); 195 std::make_pair(base::i18n::ToLower(it->second.text), it->second));
266 } 196 }
267 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 197 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
268 base::Bind(&ShortcutsBackend::InitCompleted, this)); 198 base::Bind(&ShortcutsBackend::InitCompleted, this));
269 } 199 }
270 200
271 void ShortcutsBackend::InitCompleted() { 201 void ShortcutsBackend::InitCompleted() {
272 temp_guid_map_->swap(guid_map_); 202 temp_guid_map_->swap(guid_map_);
273 temp_shortcuts_map_->swap(shortcuts_map_); 203 temp_shortcuts_map_->swap(shortcuts_map_);
274 temp_shortcuts_map_.reset(NULL); 204 temp_shortcuts_map_.reset(NULL);
275 temp_guid_map_.reset(NULL); 205 temp_guid_map_.reset(NULL);
276 current_state_ = INITIALIZED; 206 current_state_ = INITIALIZED;
277 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 207 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
278 OnShortcutsLoaded()); 208 OnShortcutsLoaded());
279 } 209 }
280 210
281 bool ShortcutsBackend::AddShortcut(const Shortcut& shortcut) { 211 bool ShortcutsBackend::AddShortcut(
212 const history::ShortcutsDatabase::Shortcut& shortcut) {
282 if (!initialized()) 213 if (!initialized())
283 return false; 214 return false;
284 DCHECK(guid_map_.find(shortcut.id) == guid_map_.end()); 215 DCHECK(guid_map_.find(shortcut.id) == guid_map_.end());
285 guid_map_[shortcut.id] = shortcuts_map_.insert( 216 guid_map_[shortcut.id] = shortcuts_map_.insert(
286 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); 217 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut));
287 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 218 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
288 OnShortcutsChanged()); 219 OnShortcutsChanged());
289 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 220 return no_db_access_ ||
290 base::Bind(base::IgnoreResult(&ShortcutsDatabase::AddShortcut), 221 BrowserThread::PostTask(
291 db_.get(), shortcut)); 222 BrowserThread::DB, FROM_HERE,
223 base::Bind(base::IgnoreResult(
224 &history::ShortcutsDatabase::AddShortcut),
225 db_.get(), shortcut));
292 } 226 }
293 227
294 bool ShortcutsBackend::UpdateShortcut(const Shortcut& shortcut) { 228 bool ShortcutsBackend::UpdateShortcut(
229 const history::ShortcutsDatabase::Shortcut& shortcut) {
295 if (!initialized()) 230 if (!initialized())
296 return false; 231 return false;
297 GuidMap::iterator it(guid_map_.find(shortcut.id)); 232 GuidMap::iterator it(guid_map_.find(shortcut.id));
298 if (it != guid_map_.end()) 233 if (it != guid_map_.end())
299 shortcuts_map_.erase(it->second); 234 shortcuts_map_.erase(it->second);
300 guid_map_[shortcut.id] = shortcuts_map_.insert( 235 guid_map_[shortcut.id] = shortcuts_map_.insert(
301 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut)); 236 std::make_pair(base::i18n::ToLower(shortcut.text), shortcut));
302 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 237 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
303 OnShortcutsChanged()); 238 OnShortcutsChanged());
304 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 239 return no_db_access_ ||
305 base::Bind(base::IgnoreResult(&ShortcutsDatabase::UpdateShortcut), 240 BrowserThread::PostTask(
306 db_.get(), shortcut)); 241 BrowserThread::DB, FROM_HERE,
242 base::Bind(base::IgnoreResult(
243 &history::ShortcutsDatabase::UpdateShortcut),
244 db_.get(), shortcut));
307 } 245 }
308 246
309 bool ShortcutsBackend::DeleteShortcutsWithIds( 247 bool ShortcutsBackend::DeleteShortcutsWithIDs(
310 const std::vector<std::string>& shortcut_ids) { 248 const history::ShortcutsDatabase::ShortcutIDs& shortcut_ids) {
311 if (!initialized()) 249 if (!initialized())
312 return false; 250 return false;
313 for (size_t i = 0; i < shortcut_ids.size(); ++i) { 251 for (size_t i = 0; i < shortcut_ids.size(); ++i) {
314 GuidMap::iterator it(guid_map_.find(shortcut_ids[i])); 252 GuidMap::iterator it(guid_map_.find(shortcut_ids[i]));
315 if (it != guid_map_.end()) { 253 if (it != guid_map_.end()) {
316 shortcuts_map_.erase(it->second); 254 shortcuts_map_.erase(it->second);
317 guid_map_.erase(it); 255 guid_map_.erase(it);
318 } 256 }
319 } 257 }
320 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 258 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
321 OnShortcutsChanged()); 259 OnShortcutsChanged());
322 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 260 return no_db_access_ ||
323 base::Bind(base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithIds), 261 BrowserThread::PostTask(
324 db_.get(), shortcut_ids)); 262 BrowserThread::DB, FROM_HERE,
263 base::Bind(base::IgnoreResult(
264 &history::ShortcutsDatabase::DeleteShortcutsWithIDs),
265 db_.get(), shortcut_ids));
325 } 266 }
326 267
327 bool ShortcutsBackend::DeleteShortcutsWithUrl(const GURL& url, 268 bool ShortcutsBackend::DeleteShortcutsWithURL(const GURL& url,
328 bool exact_match) { 269 bool exact_match) {
329 const std::string& url_spec = url.spec(); 270 const std::string& url_spec = url.spec();
330 std::vector<std::string> shortcut_ids; 271 history::ShortcutsDatabase::ShortcutIDs shortcut_ids;
331 for (GuidMap::iterator it(guid_map_.begin()); it != guid_map_.end(); ) { 272 for (GuidMap::iterator it(guid_map_.begin()); it != guid_map_.end(); ) {
332 if (exact_match ? 273 if (exact_match ?
333 (it->second->second.match_core.destination_url == url) : 274 (it->second->second.match_core.destination_url == url) :
334 StartsWithASCII(it->second->second.match_core.destination_url.spec(), 275 StartsWithASCII(it->second->second.match_core.destination_url.spec(),
335 url_spec, true)) { 276 url_spec, true)) {
336 shortcut_ids.push_back(it->first); 277 shortcut_ids.push_back(it->first);
337 shortcuts_map_.erase(it->second); 278 shortcuts_map_.erase(it->second);
338 guid_map_.erase(it++); 279 guid_map_.erase(it++);
339 } else { 280 } else {
340 ++it; 281 ++it;
341 } 282 }
342 } 283 }
343 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 284 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
344 OnShortcutsChanged()); 285 OnShortcutsChanged());
345 return no_db_access_ || 286 return no_db_access_ ||
346 BrowserThread::PostTask( 287 BrowserThread::PostTask(
347 BrowserThread::DB, FROM_HERE, 288 BrowserThread::DB, FROM_HERE,
348 base::Bind( 289 base::Bind(base::IgnoreResult(
349 base::IgnoreResult(&ShortcutsDatabase::DeleteShortcutsWithUrl), 290 &history::ShortcutsDatabase::DeleteShortcutsWithURL),
350 db_.get(), url_spec)); 291 db_.get(), url_spec));
351 } 292 }
352 293
353 bool ShortcutsBackend::DeleteAllShortcuts() { 294 bool ShortcutsBackend::DeleteAllShortcuts() {
354 if (!initialized()) 295 if (!initialized())
355 return false; 296 return false;
356 shortcuts_map_.clear(); 297 shortcuts_map_.clear();
357 guid_map_.clear(); 298 guid_map_.clear();
358 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, 299 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_,
359 OnShortcutsChanged()); 300 OnShortcutsChanged());
360 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 301 return no_db_access_ ||
361 base::Bind(base::IgnoreResult(&ShortcutsDatabase::DeleteAllShortcuts), 302 BrowserThread::PostTask(
362 db_.get())); 303 BrowserThread::DB, FROM_HERE,
304 base::Bind(base::IgnoreResult(
305 &history::ShortcutsDatabase::DeleteAllShortcuts),
306 db_.get()));
363 } 307 }
364
365 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/shortcuts_backend.h ('k') | chrome/browser/autocomplete/shortcuts_backend_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698