OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/search_versus_navigate_classifier.h" |
| 6 |
| 7 #include "chrome/browser/autocomplete/autocomplete.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 |
| 10 SearchVersusNavigateClassifier::SearchVersusNavigateClassifier(Profile* profile) |
| 11 : controller_(new AutocompleteController(profile)) { |
| 12 } |
| 13 |
| 14 SearchVersusNavigateClassifier::~SearchVersusNavigateClassifier() { |
| 15 } |
| 16 |
| 17 void SearchVersusNavigateClassifier::Classify(const std::wstring& text, |
| 18 const std::wstring& desired_tld, |
| 19 bool* is_search, |
| 20 GURL* destination_url, |
| 21 PageTransition::Type* transition, |
| 22 bool* is_history_what_you_typed_match, |
| 23 GURL* alternate_nav_url) { |
| 24 controller_->Start(text, desired_tld, true, false, true); |
| 25 DCHECK(controller_->done()); |
| 26 const AutocompleteResult& result = controller_->result(); |
| 27 if (result.empty()) { |
| 28 if (is_search) |
| 29 *is_search = false; |
| 30 if (destination_url) |
| 31 *destination_url = GURL(); |
| 32 if (transition) |
| 33 *transition = PageTransition::TYPED; |
| 34 if (is_history_what_you_typed_match) |
| 35 *is_history_what_you_typed_match = false; |
| 36 if (alternate_nav_url) |
| 37 *alternate_nav_url = GURL(); |
| 38 return; |
| 39 } |
| 40 |
| 41 const AutocompleteResult::const_iterator match(result.default_match()); |
| 42 DCHECK(match != result.end()); |
| 43 |
| 44 // If this is a search, the page transition will be GENERATED rather than |
| 45 // TYPED. |
| 46 if (is_search) |
| 47 *is_search = (match->transition != PageTransition::TYPED); |
| 48 if (destination_url) |
| 49 *destination_url = match->destination_url; |
| 50 if (transition) |
| 51 *transition = match->transition; |
| 52 if (is_history_what_you_typed_match) |
| 53 *is_history_what_you_typed_match = match->is_history_what_you_typed_match; |
| 54 if (alternate_nav_url) |
| 55 *alternate_nav_url = result.alternate_nav_url(); |
| 56 } |
OLD | NEW |