| 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" | |
| 14 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/sequenced_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 20 #include "components/bookmarks/browser/bookmark_utils.h" | 20 #include "components/bookmarks/browser/bookmark_utils.h" |
| 21 #include "components/history/core/browser/history_backend.h" | 21 #include "components/history/core/browser/history_backend.h" |
| 22 #include "components/history/core/browser/history_database.h" | 22 #include "components/history/core/browser/history_database.h" |
| 23 #include "components/history/core/browser/history_service.h" | 23 #include "components/history/core/browser/history_service.h" |
| 24 #include "components/history/core/browser/history_types.h" | 24 #include "components/history/core/browser/history_types.h" |
| 25 #include "components/metrics/proto/omnibox_input_type.pb.h" | 25 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 26 #include "components/omnibox/browser/autocomplete_match.h" | 26 #include "components/omnibox/browser/autocomplete_match.h" |
| 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 type_ = UNVISITED_INTRANET; | 419 type_ = UNVISITED_INTRANET; |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 HistoryURLProviderParams::HistoryURLProviderParams( | 423 HistoryURLProviderParams::HistoryURLProviderParams( |
| 424 const AutocompleteInput& input, | 424 const AutocompleteInput& input, |
| 425 bool trim_http, | 425 bool trim_http, |
| 426 const AutocompleteMatch& what_you_typed_match, | 426 const AutocompleteMatch& what_you_typed_match, |
| 427 TemplateURL* default_search_provider, | 427 TemplateURL* default_search_provider, |
| 428 const SearchTermsData& search_terms_data) | 428 const SearchTermsData& search_terms_data) |
| 429 : message_loop(base::MessageLoop::current()), | 429 : origin_task_runner(base::SequencedTaskRunnerHandle::Get()), |
| 430 input(input), | 430 input(input), |
| 431 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), | 431 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), |
| 432 trim_http(trim_http), | 432 trim_http(trim_http), |
| 433 what_you_typed_match(what_you_typed_match), | 433 what_you_typed_match(what_you_typed_match), |
| 434 failed(false), | 434 failed(false), |
| 435 exact_suggestion_is_in_history(false), | 435 exact_suggestion_is_in_history(false), |
| 436 promote_type(NEITHER), | 436 promote_type(NEITHER), |
| 437 default_search_provider(default_search_provider ? | 437 default_search_provider( |
| 438 new TemplateURL(default_search_provider->data()) : nullptr), | 438 default_search_provider |
| 439 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { | 439 ? new TemplateURL(default_search_provider->data()) |
| 440 } | 440 : nullptr), |
| 441 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) {} |
| 441 | 442 |
| 442 HistoryURLProviderParams::~HistoryURLProviderParams() { | 443 HistoryURLProviderParams::~HistoryURLProviderParams() { |
| 443 } | 444 } |
| 444 | 445 |
| 445 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, | 446 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, |
| 446 AutocompleteProviderListener* listener) | 447 AutocompleteProviderListener* listener) |
| 447 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), | 448 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_URL, client), |
| 448 listener_(listener), | 449 listener_(listener), |
| 449 params_(nullptr), | 450 params_(nullptr), |
| 450 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { | 451 search_url_database_(OmniboxFieldTrial::HUPSearchDatabase()) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 params->failed = true; | 634 params->failed = true; |
| 634 } else if (!params->cancel_flag.IsSet()) { | 635 } else if (!params->cancel_flag.IsSet()) { |
| 635 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 636 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 636 | 637 |
| 637 DoAutocomplete(backend, db, params); | 638 DoAutocomplete(backend, db, params); |
| 638 | 639 |
| 639 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime", | 640 UMA_HISTOGRAM_TIMES("Autocomplete.HistoryAsyncQueryTime", |
| 640 base::TimeTicks::Now() - beginning_time); | 641 base::TimeTicks::Now() - beginning_time); |
| 641 } | 642 } |
| 642 | 643 |
| 643 // Return the results (if any) to the main thread. | 644 // Return the results (if any) to the originating sequence. |
| 644 params->message_loop->task_runner()->PostTask( | 645 params->origin_task_runner->PostTask( |
| 645 FROM_HERE, base::Bind(&HistoryURLProvider::QueryComplete, this, params)); | 646 FROM_HERE, base::Bind(&HistoryURLProvider::QueryComplete, this, params)); |
| 646 } | 647 } |
| 647 | 648 |
| 648 HistoryURLProvider::~HistoryURLProvider() { | 649 HistoryURLProvider::~HistoryURLProvider() { |
| 649 // Note: This object can get leaked on shutdown if there are pending | 650 // Note: This object can get leaked on shutdown if there are pending |
| 650 // requests on the database (which hold a reference to us). Normally, these | 651 // requests on the database (which hold a reference to us). Normally, these |
| 651 // messages get flushed for each thread. We do a round trip from main, to | 652 // messages get flushed for each thread. We do a round trip from main, to |
| 652 // history, back to main while holding a reference. If the main thread | 653 // history, back to main while holding a reference. If the main thread |
| 653 // completes before the history thread, the message to delegate back to the | 654 // completes before the history thread, the message to delegate back to the |
| 654 // main thread will not run and the reference will leak. Therefore, don't do | 655 // main thread will not run and the reference will leak. Therefore, don't do |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1193 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
| 1193 match.contents.length(), ACMatchClassification::URL, | 1194 match.contents.length(), ACMatchClassification::URL, |
| 1194 &match.contents_class); | 1195 &match.contents_class); |
| 1195 } | 1196 } |
| 1196 match.description = info.title(); | 1197 match.description = info.title(); |
| 1197 match.description_class = | 1198 match.description_class = |
| 1198 ClassifyDescription(params.input.text(), match.description); | 1199 ClassifyDescription(params.input.text(), match.description); |
| 1199 RecordAdditionalInfoFromUrlRow(info, &match); | 1200 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1200 return match; | 1201 return match; |
| 1201 } | 1202 } |
| OLD | NEW |