| 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/bookmark_provider.h" | 5 #include "chrome/browser/autocomplete/bookmark_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_result.h" | 13 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 14 #include "chrome/browser/autocomplete/history_provider.h" | 14 #include "chrome/browser/autocomplete/history_provider.h" |
| 15 #include "chrome/browser/autocomplete/url_prefix.h" | 15 #include "chrome/browser/autocomplete/url_prefix.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 17 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 17 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "components/bookmarks/browser/bookmark_match.h" | 20 #include "components/bookmarks/browser/bookmark_match.h" |
| 21 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 22 #include "components/metrics/proto/omnibox_input_type.pb.h" | |
| 23 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 24 | 23 |
| 25 typedef std::vector<BookmarkMatch> BookmarkMatches; | 24 typedef std::vector<BookmarkMatch> BookmarkMatches; |
| 26 | 25 |
| 27 // BookmarkProvider ------------------------------------------------------------ | 26 // BookmarkProvider ------------------------------------------------------------ |
| 28 | 27 |
| 29 BookmarkProvider::BookmarkProvider( | 28 BookmarkProvider::BookmarkProvider( |
| 30 AutocompleteProviderListener* listener, | 29 AutocompleteProviderListener* listener, |
| 31 Profile* profile) | 30 Profile* profile) |
| 32 : AutocompleteProvider(listener, profile, | 31 : AutocompleteProvider(listener, profile, |
| 33 AutocompleteProvider::TYPE_BOOKMARK), | 32 AutocompleteProvider::TYPE_BOOKMARK), |
| 34 bookmark_model_(NULL), | 33 bookmark_model_(NULL), |
| 35 score_using_url_matches_(OmniboxFieldTrial::BookmarksIndexURLsValue()) { | 34 score_using_url_matches_(OmniboxFieldTrial::BookmarksIndexURLsValue()) { |
| 36 if (profile) { | 35 if (profile) { |
| 37 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); | 36 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); |
| 38 languages_ = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); | 37 languages_ = profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 | 40 |
| 42 void BookmarkProvider::Start(const AutocompleteInput& input, | 41 void BookmarkProvider::Start(const AutocompleteInput& input, |
| 43 bool minimal_changes) { | 42 bool minimal_changes) { |
| 44 if (minimal_changes) | 43 if (minimal_changes) |
| 45 return; | 44 return; |
| 46 matches_.clear(); | 45 matches_.clear(); |
| 47 | 46 |
| 48 if (input.text().empty() || | 47 if (input.text().empty() || |
| 49 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) | 48 (input.type() == AutocompleteInput::FORCED_QUERY)) |
| 50 return; | 49 return; |
| 51 | 50 |
| 52 DoAutocomplete(input); | 51 DoAutocomplete(input); |
| 53 } | 52 } |
| 54 | 53 |
| 55 BookmarkProvider::~BookmarkProvider() {} | 54 BookmarkProvider::~BookmarkProvider() {} |
| 56 | 55 |
| 57 void BookmarkProvider::DoAutocomplete(const AutocompleteInput& input) { | 56 void BookmarkProvider::DoAutocomplete(const AutocompleteInput& input) { |
| 58 // We may not have a bookmark model for some unit tests. | 57 // We may not have a bookmark model for some unit tests. |
| 59 if (!bookmark_model_) | 58 if (!bookmark_model_) |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 i != positions.end(); | 309 i != positions.end(); |
| 311 ++i) { | 310 ++i) { |
| 312 AutocompleteMatch::ACMatchClassifications new_class; | 311 AutocompleteMatch::ACMatchClassifications new_class; |
| 313 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, | 312 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, |
| 314 text_length, url_style, &new_class); | 313 text_length, url_style, &new_class); |
| 315 classifications = AutocompleteMatch::MergeClassifications( | 314 classifications = AutocompleteMatch::MergeClassifications( |
| 316 classifications, new_class); | 315 classifications, new_class); |
| 317 } | 316 } |
| 318 return classifications; | 317 return classifications; |
| 319 } | 318 } |
| OLD | NEW |