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