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 |
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" |
16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 16 #include "chrome/browser/autocomplete/autocomplete_match.h" |
17 #include "chrome/browser/autocomplete/autocomplete_result.h" | 17 #include "chrome/browser/autocomplete/autocomplete_result.h" |
18 #include "chrome/browser/autocomplete/base_search_provider.h" | 18 #include "chrome/browser/autocomplete/base_search_provider.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/browser/history/history_notifications.h" | 20 #include "chrome/browser/history/history_notifications.h" |
21 #include "chrome/browser/history/history_service.h" | 21 #include "chrome/browser/history/history_service.h" |
22 #include "chrome/browser/history/shortcuts_database.h" | 22 #include "chrome/browser/history/shortcuts_database.h" |
23 #include "chrome/browser/omnibox/omnibox_log.h" | 23 #include "chrome/browser/omnibox/omnibox_log.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/search_engines/template_url_service_factory.h" |
25 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 26 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
26 #include "chrome/common/autocomplete_match_type.h" | 27 #include "chrome/common/autocomplete_match_type.h" |
27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
28 #include "components/autocomplete/autocomplete_input.h" | 29 #include "components/autocomplete/autocomplete_input.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
31 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
32 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
33 | 34 |
34 using content::BrowserThread; | 35 using content::BrowserThread; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 137 } |
137 | 138 |
138 ShortcutsBackend::~ShortcutsBackend() { | 139 ShortcutsBackend::~ShortcutsBackend() { |
139 } | 140 } |
140 | 141 |
141 // static | 142 // static |
142 history::ShortcutsDatabase::Shortcut::MatchCore | 143 history::ShortcutsDatabase::Shortcut::MatchCore |
143 ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match, | 144 ShortcutsBackend::MatchToMatchCore(const AutocompleteMatch& match, |
144 Profile* profile) { | 145 Profile* profile) { |
145 const AutocompleteMatch::Type match_type = GetTypeForShortcut(match.type); | 146 const AutocompleteMatch::Type match_type = GetTypeForShortcut(match.type); |
| 147 TemplateURLService* service = |
| 148 TemplateURLServiceFactory::GetForProfile(profile); |
146 const AutocompleteMatch& normalized_match = | 149 const AutocompleteMatch& normalized_match = |
147 AutocompleteMatch::IsSpecializedSearchType(match.type) ? | 150 AutocompleteMatch::IsSpecializedSearchType(match.type) ? |
148 BaseSearchProvider::CreateSearchSuggestion( | 151 BaseSearchProvider::CreateSearchSuggestion( |
149 match.search_terms_args->search_terms, match_type, | 152 match.search_terms_args->search_terms, match_type, |
150 (match.transition == content::PAGE_TRANSITION_KEYWORD), | 153 (match.transition == content::PAGE_TRANSITION_KEYWORD), |
151 match.GetTemplateURL(profile, false), | 154 match.GetTemplateURL(service, false), |
152 UIThreadSearchTermsData(profile)) : | 155 UIThreadSearchTermsData(profile)) : |
153 match; | 156 match; |
154 return history::ShortcutsDatabase::Shortcut::MatchCore( | 157 return history::ShortcutsDatabase::Shortcut::MatchCore( |
155 normalized_match.fill_into_edit, normalized_match.destination_url, | 158 normalized_match.fill_into_edit, normalized_match.destination_url, |
156 normalized_match.contents, | 159 normalized_match.contents, |
157 StripMatchMarkers(normalized_match.contents_class), | 160 StripMatchMarkers(normalized_match.contents_class), |
158 normalized_match.description, | 161 normalized_match.description, |
159 StripMatchMarkers(normalized_match.description_class), | 162 StripMatchMarkers(normalized_match.description_class), |
160 normalized_match.transition, match_type, normalized_match.keyword); | 163 normalized_match.transition, match_type, normalized_match.keyword); |
161 } | 164 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 guid_map_.clear(); | 319 guid_map_.clear(); |
317 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 320 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
318 OnShortcutsChanged()); | 321 OnShortcutsChanged()); |
319 return no_db_access_ || | 322 return no_db_access_ || |
320 BrowserThread::PostTask( | 323 BrowserThread::PostTask( |
321 BrowserThread::DB, FROM_HERE, | 324 BrowserThread::DB, FROM_HERE, |
322 base::Bind(base::IgnoreResult( | 325 base::Bind(base::IgnoreResult( |
323 &history::ShortcutsDatabase::DeleteAllShortcuts), | 326 &history::ShortcutsDatabase::DeleteAllShortcuts), |
324 db_.get())); | 327 db_.get())); |
325 } | 328 } |
OLD | NEW |