| 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 "components/omnibox/browser/history_url_provider.h" | 5 #include "components/omnibox/browser/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/trace_event/trace_event.h" |
| 19 #include "components/bookmarks/browser/bookmark_utils.h" | 20 #include "components/bookmarks/browser/bookmark_utils.h" |
| 20 #include "components/history/core/browser/history_backend.h" | 21 #include "components/history/core/browser/history_backend.h" |
| 21 #include "components/history/core/browser/history_database.h" | 22 #include "components/history/core/browser/history_database.h" |
| 22 #include "components/history/core/browser/history_service.h" | 23 #include "components/history/core/browser/history_service.h" |
| 23 #include "components/history/core/browser/history_types.h" | 24 #include "components/history/core/browser/history_types.h" |
| 24 #include "components/metrics/proto/omnibox_input_type.pb.h" | 25 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 25 #include "components/omnibox/browser/autocomplete_match.h" | 26 #include "components/omnibox/browser/autocomplete_match.h" |
| 26 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 27 #include "components/omnibox/browser/autocomplete_result.h" | 28 #include "components/omnibox/browser/autocomplete_result.h" |
| 28 #include "components/omnibox/browser/in_memory_url_index_types.h" | 29 #include "components/omnibox/browser/in_memory_url_index_types.h" |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 params_(NULL), | 450 params_(NULL), |
| 450 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { | 451 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { |
| 451 // Initialize the default HUP scoring params. | 452 // Initialize the default HUP scoring params. |
| 452 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_); | 453 OmniboxFieldTrial::GetDefaultHUPScoringParams(&scoring_params_); |
| 453 // Initialize HUP scoring params based on the current experiment. | 454 // Initialize HUP scoring params based on the current experiment. |
| 454 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); | 455 OmniboxFieldTrial::GetExperimentalHUPScoringParams(&scoring_params_); |
| 455 } | 456 } |
| 456 | 457 |
| 457 void HistoryURLProvider::Start(const AutocompleteInput& input, | 458 void HistoryURLProvider::Start(const AutocompleteInput& input, |
| 458 bool minimal_changes) { | 459 bool minimal_changes) { |
| 460 TRACE_EVENT0("omnibox", "HistoryURLProvider::Start"); |
| 459 // NOTE: We could try hard to do less work in the |minimal_changes| case | 461 // NOTE: We could try hard to do less work in the |minimal_changes| case |
| 460 // here; some clever caching would let us reuse the raw matches from the | 462 // here; some clever caching would let us reuse the raw matches from the |
| 461 // history DB without re-querying. However, we'd still have to go back to | 463 // history DB without re-querying. However, we'd still have to go back to |
| 462 // the history thread to mark these up properly, and if pass 2 is currently | 464 // the history thread to mark these up properly, and if pass 2 is currently |
| 463 // running, we'd need to wait for it to return to the main thread before | 465 // running, we'd need to wait for it to return to the main thread before |
| 464 // doing this (we can't just write new data for it to read due to thread | 466 // doing this (we can't just write new data for it to read due to thread |
| 465 // safety issues). At that point it's just as fast, and easier, to simply | 467 // safety issues). At that point it's just as fast, and easier, to simply |
| 466 // re-run the query from scratch and ignore |minimal_changes|. | 468 // re-run the query from scratch and ignore |minimal_changes|. |
| 467 | 469 |
| 468 // Cancel any in-progress query. | 470 // Cancel any in-progress query. |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 // take care of adding this defaultable match.) | 836 // take care of adding this defaultable match.) |
| 835 if ((params.promote_type == HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) || | 837 if ((params.promote_type == HistoryURLProviderParams::WHAT_YOU_TYPED_MATCH) || |
| 836 (params.prevent_inline_autocomplete && | 838 (params.prevent_inline_autocomplete && |
| 837 params.have_what_you_typed_match)) { | 839 params.have_what_you_typed_match)) { |
| 838 matches_.push_back(params.what_you_typed_match); | 840 matches_.push_back(params.what_you_typed_match); |
| 839 } | 841 } |
| 840 } | 842 } |
| 841 | 843 |
| 842 void HistoryURLProvider::QueryComplete( | 844 void HistoryURLProvider::QueryComplete( |
| 843 HistoryURLProviderParams* params_gets_deleted) { | 845 HistoryURLProviderParams* params_gets_deleted) { |
| 846 TRACE_EVENT0("omnibox", "HistoryURLProvider::QueryComplete"); |
| 844 // Ensure |params_gets_deleted| gets deleted on exit. | 847 // Ensure |params_gets_deleted| gets deleted on exit. |
| 845 scoped_ptr<HistoryURLProviderParams> params(params_gets_deleted); | 848 scoped_ptr<HistoryURLProviderParams> params(params_gets_deleted); |
| 846 | 849 |
| 847 // If the user hasn't already started another query, clear our member pointer | 850 // If the user hasn't already started another query, clear our member pointer |
| 848 // so we can't write into deleted memory. | 851 // so we can't write into deleted memory. |
| 849 if (params_ == params_gets_deleted) | 852 if (params_ == params_gets_deleted) |
| 850 params_ = NULL; | 853 params_ = NULL; |
| 851 | 854 |
| 852 // Don't send responses for queries that have been canceled. | 855 // Don't send responses for queries that have been canceled. |
| 853 if (params->cancel_flag.IsSet()) | 856 if (params->cancel_flag.IsSet()) |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1198 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1196 match.contents.length(), ACMatchClassification::URL, | 1199 match.contents.length(), ACMatchClassification::URL, |
| 1197 &match.contents_class); | 1200 &match.contents_class); |
| 1198 } | 1201 } |
| 1199 match.description = info.title(); | 1202 match.description = info.title(); |
| 1200 match.description_class = | 1203 match.description_class = |
| 1201 ClassifyDescription(params.input.text(), match.description); | 1204 ClassifyDescription(params.input.text(), match.description); |
| 1202 RecordAdditionalInfoFromUrlRow(info, &match); | 1205 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1203 return match; | 1206 return match; |
| 1204 } | 1207 } |
| OLD | NEW |