Chromium Code Reviews| 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/history/shortcuts_backend.h" | 5 #include "chrome/browser/history/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 "base/strings/utf_string_conversions.h" | |
| 16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_result.h" | 18 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/history/history_notifications.h" | 20 #include "chrome/browser/history/history_notifications.h" |
| 20 #include "chrome/browser/history/history_service.h" | 21 #include "chrome/browser/history/history_service.h" |
| 21 #include "chrome/browser/history/shortcuts_database.h" | 22 #include "chrome/browser/history/shortcuts_database.h" |
| 22 #include "chrome/browser/omnibox/omnibox_log.h" | 23 #include "chrome/browser/omnibox/omnibox_log.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/autocomplete_match_type.h" | |
| 24 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 28 #include "extensions/common/extension.h" | 30 #include "extensions/common/extension.h" |
| 29 | 31 |
| 30 using content::BrowserThread; | 32 using content::BrowserThread; |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 36 bool IsSearchSuggestType(AutocompleteMatchType::Type type) { | |
| 37 switch (type) { | |
| 38 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE: | |
| 39 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY: | |
| 40 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED: | |
| 41 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE: | |
| 42 return true; | |
| 43 | |
| 44 default: | |
| 45 return false; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 const GURL GetDestinationURLForShortcut(const AutocompleteMatch& match) { | |
| 50 return IsSearchSuggestType(match.type) ? | |
| 51 match.stripped_destination_url : match.destination_url; | |
|
Peter Kasting
2014/02/14 05:35:25
If we needed to do this, I'd expect us to need thi
Anuj
2014/02/14 20:18:07
So the idea was to remove the additional query par
Peter Kasting
2014/02/14 21:40:21
I think the additional query parameters are defini
Anuj
2014/02/14 22:09:55
I think we should strip out these parameters at th
| |
| 52 } | |
| 53 | |
| 54 const base::string16 GetContentsForShortcut(const AutocompleteMatch& match) { | |
| 55 return IsSearchSuggestType(match.type) ? | |
| 56 match.fill_into_edit : match.contents; | |
| 57 } | |
| 58 | |
| 59 const base::string16 GetDescriptionForShortcut(const AutocompleteMatch& match) { | |
| 60 return IsSearchSuggestType(match.type) ? base::string16() : match.description; | |
|
Peter Kasting
2014/02/14 05:35:25
Hmm, should we be flattening the description here?
Anuj
2014/02/14 20:18:07
So the description is present for Entity and Profi
| |
| 61 } | |
| 62 | |
| 34 // Takes Match classification vector and removes all matched positions, | 63 // Takes Match classification vector and removes all matched positions, |
| 35 // compacting repetitions if necessary. | 64 // compacting repetitions if necessary. |
| 36 ACMatchClassifications StripMatchMarkers( | 65 ACMatchClassifications StripMatchMarkers( |
| 37 const ACMatchClassifications& matches) { | 66 const ACMatchClassifications& classifications) { |
| 38 ACMatchClassifications unmatched; | 67 ACMatchClassifications unmatched; |
| 39 for (ACMatchClassifications::const_iterator i(matches.begin()); | 68 for (ACMatchClassifications::const_iterator i(classifications.begin()); |
| 40 i != matches.end(); ++i) { | 69 i != classifications.end(); ++i) { |
| 41 AutocompleteMatch::AddLastClassificationIfNecessary( | 70 AutocompleteMatch::AddLastClassificationIfNecessary( |
| 42 &unmatched, i->offset, i->style & ~ACMatchClassification::MATCH); | 71 &unmatched, i->offset, i->style & ~ACMatchClassification::MATCH); |
| 43 } | 72 } |
| 44 return unmatched; | 73 return unmatched; |
| 45 } | 74 } |
| 46 | 75 |
| 76 ACMatchClassifications GetClassificationsForShortcut( | |
| 77 AutocompleteMatchType::Type type, | |
| 78 const ACMatchClassifications& classifications) { | |
| 79 return IsSearchSuggestType(type) ? ACMatchClassifications() : classifications; | |
| 80 } | |
| 81 | |
| 47 // Normally shortcuts have the same match type as the original match they were | 82 // 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 | 83 // 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. | 84 // type slightly to reflect that the origin of the shortcut is historical. |
| 50 AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) { | 85 AutocompleteMatch::Type GetTypeForShortcut(AutocompleteMatch::Type type) { |
| 51 switch (type) { | 86 switch (type) { |
| 52 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: | 87 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: |
| 53 case AutocompleteMatchType::NAVSUGGEST: | 88 case AutocompleteMatchType::NAVSUGGEST: |
| 54 return AutocompleteMatchType::HISTORY_URL; | 89 return AutocompleteMatchType::HISTORY_URL; |
| 55 | 90 |
| 56 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED: | 91 case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED: |
| 57 case AutocompleteMatchType::SEARCH_SUGGEST: | 92 case AutocompleteMatchType::SEARCH_SUGGEST: |
| 93 case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY: | |
| 94 case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE: | |
| 95 case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED: | |
| 96 case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE: | |
| 58 return AutocompleteMatchType::SEARCH_HISTORY; | 97 return AutocompleteMatchType::SEARCH_HISTORY; |
| 59 | 98 |
| 60 default: | 99 default: |
| 61 return type; | 100 return type; |
| 62 } | 101 } |
| 63 } | 102 } |
| 64 | 103 |
| 65 } // namespace | 104 } // namespace |
| 66 | 105 |
| 67 namespace history { | 106 namespace history { |
| 68 | 107 |
| 69 // ShortcutsBackend::Shortcut::MatchCore -------------------------------------- | 108 // ShortcutsBackend::Shortcut::MatchCore -------------------------------------- |
| 70 | 109 |
| 71 ShortcutsBackend::Shortcut::MatchCore::MatchCore( | 110 ShortcutsBackend::Shortcut::MatchCore::MatchCore( |
| 72 const AutocompleteMatch& match) | 111 const AutocompleteMatch& match) |
| 73 : fill_into_edit(match.fill_into_edit), | 112 : fill_into_edit(match.fill_into_edit), |
| 74 destination_url(match.destination_url), | 113 destination_url(GetDestinationURLForShortcut(match)), |
| 75 contents(match.contents), | 114 contents(GetContentsForShortcut(match)), |
| 76 contents_class(StripMatchMarkers(match.contents_class)), | 115 contents_class( |
| 77 description(match.description), | 116 GetClassificationsForShortcut(match.type, match.contents_class)), |
| 78 description_class(StripMatchMarkers(match.description_class)), | 117 description(GetDescriptionForShortcut(match)), |
| 118 description_class( | |
| 119 GetClassificationsForShortcut(match.type, match.description_class)), | |
| 79 transition(match.transition), | 120 transition(match.transition), |
| 80 type(GetTypeForShortcut(match.type)), | 121 type(GetTypeForShortcut(match.type)), |
| 81 keyword(match.keyword) { | 122 keyword(match.keyword) { |
| 82 } | 123 } |
| 83 | 124 |
| 84 ShortcutsBackend::Shortcut::MatchCore::MatchCore( | 125 ShortcutsBackend::Shortcut::MatchCore::MatchCore( |
| 85 const base::string16& fill_into_edit, | 126 const base::string16& fill_into_edit, |
| 86 const GURL& destination_url, | 127 const GURL& destination_url, |
| 87 const base::string16& contents, | 128 const base::string16& contents, |
| 88 const ACMatchClassifications& contents_class, | 129 const ACMatchClassifications& contents_class, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 shortcuts_map_.clear(); | 393 shortcuts_map_.clear(); |
| 353 guid_map_.clear(); | 394 guid_map_.clear(); |
| 354 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 395 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
| 355 OnShortcutsChanged()); | 396 OnShortcutsChanged()); |
| 356 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 397 return no_db_access_ || BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 357 base::Bind(base::IgnoreResult(&ShortcutsDatabase::DeleteAllShortcuts), | 398 base::Bind(base::IgnoreResult(&ShortcutsDatabase::DeleteAllShortcuts), |
| 358 db_.get())); | 399 db_.get())); |
| 359 } | 400 } |
| 360 | 401 |
| 361 } // namespace history | 402 } // namespace history |
| OLD | NEW |