OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/main/url_search_provider.h" | 5 #include "athena/main/url_search_provider.h" |
6 | 6 |
7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "components/metrics/proto/omnibox_event.pb.h" | 11 #include "components/metrics/proto/omnibox_event.pb.h" |
12 #include "components/metrics/proto/omnibox_input_type.pb.h" | 12 #include "components/metrics/proto/omnibox_input_type.pb.h" |
13 #include "components/omnibox/autocomplete_input.h" | 13 #include "components/omnibox/autocomplete_input.h" |
14 #include "components/omnibox/autocomplete_provider_client.h" | 14 #include "components/omnibox/autocomplete_provider_client.h" |
15 #include "components/omnibox/autocomplete_scheme_classifier.h" | 15 #include "components/omnibox/autocomplete_scheme_classifier.h" |
16 #include "components/omnibox/search_provider.h" | 16 #include "components/omnibox/search_provider.h" |
17 #include "components/search_engines/search_terms_data.h" | 17 #include "components/search_engines/search_terms_data.h" |
18 #include "components/search_engines/template_url_service.h" | 18 #include "components/search_engines/template_url_service.h" |
19 #include "components/search_engines/template_url_service_client.h" | 19 #include "components/search_engines/template_url_service_client.h" |
20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
21 #include "ui/app_list/search_result.h" | 21 #include "ui/app_list/search_result.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 namespace athena { | 25 namespace athena { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
| 29 // This constant was copied from HistoryURLProvider. |
| 30 // TODO(hashimoto): Componentize HistoryURLProvider and delete this. |
| 31 const int kScoreForWhatYouTypedResult = 1203; |
| 32 |
29 // The SearchTermsData implementation for Athena. | 33 // The SearchTermsData implementation for Athena. |
30 class AthenaSearchTermsData : public SearchTermsData { | 34 class AthenaSearchTermsData : public SearchTermsData { |
31 public: | 35 public: |
32 // SearchTermsData: | 36 // SearchTermsData: |
33 virtual std::string GetSuggestClient() const OVERRIDE { | 37 virtual std::string GetSuggestClient() const OVERRIDE { |
34 return "chrome"; | 38 return "chrome"; |
35 } | 39 } |
36 }; | 40 }; |
37 | 41 |
38 // The AutocompleteSchemeClassifier implementation for Athena. | 42 // The AutocompleteSchemeClassifier implementation for Athena. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 void UrlSearchProvider::Stop() { | 263 void UrlSearchProvider::Stop() { |
260 provider_->Stop(false); | 264 provider_->Stop(false); |
261 } | 265 } |
262 | 266 |
263 void UrlSearchProvider::OnProviderUpdate(bool updated_matches) { | 267 void UrlSearchProvider::OnProviderUpdate(bool updated_matches) { |
264 if (!updated_matches) | 268 if (!updated_matches) |
265 return; | 269 return; |
266 | 270 |
267 ClearResults(); | 271 ClearResults(); |
268 | 272 |
| 273 if (input_.type() == metrics::OmniboxInputType::URL) { |
| 274 // TODO(hashimoto): Componentize HistoryURLProvider and remove this code. |
| 275 AutocompleteMatch what_you_typed_match( |
| 276 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
| 277 what_you_typed_match.destination_url = input_.canonicalized_url(); |
| 278 what_you_typed_match.contents = input_.text(); |
| 279 what_you_typed_match.relevance = kScoreForWhatYouTypedResult; |
| 280 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult( |
| 281 browser_context_, what_you_typed_match))); |
| 282 } |
| 283 |
269 const ACMatches& matches = provider_->matches(); | 284 const ACMatches& matches = provider_->matches(); |
270 for (ACMatches::const_iterator it = matches.begin(); it != matches.end(); | 285 for (ACMatches::const_iterator it = matches.begin(); it != matches.end(); |
271 ++it) { | 286 ++it) { |
272 if (!it->destination_url.is_valid()) | 287 if (!it->destination_url.is_valid()) |
273 continue; | 288 continue; |
274 | 289 |
275 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult( | 290 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult( |
276 browser_context_, *it))); | 291 browser_context_, *it))); |
277 } | 292 } |
278 } | 293 } |
279 | 294 |
280 } // namespace athena | 295 } // namespace athena |
OLD | NEW |