Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: athena/main/url_search_provider.cc

Issue 584263002: Use ChromeAutocompleteSchemeClassifier for Athena on Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/content/shell/scheme_classifier_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "athena/content/public/scheme_classifier_factory.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "components/metrics/proto/omnibox_event.pb.h" 12 #include "components/metrics/proto/omnibox_event.pb.h"
12 #include "components/metrics/proto/omnibox_input_type.pb.h" 13 #include "components/metrics/proto/omnibox_input_type.pb.h"
13 #include "components/omnibox/autocomplete_input.h" 14 #include "components/omnibox/autocomplete_input.h"
14 #include "components/omnibox/autocomplete_provider_client.h" 15 #include "components/omnibox/autocomplete_provider_client.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. 29 // This constant was copied from HistoryURLProvider.
30 // TODO(hashimoto): Componentize HistoryURLProvider and delete this. 30 // TODO(hashimoto): Componentize HistoryURLProvider and delete this.
31 const int kScoreForWhatYouTypedResult = 1203; 31 const int kScoreForWhatYouTypedResult = 1203;
32 32
33 // The SearchTermsData implementation for Athena. 33 // The SearchTermsData implementation for Athena.
34 class AthenaSearchTermsData : public SearchTermsData { 34 class AthenaSearchTermsData : public SearchTermsData {
35 public: 35 public:
36 // SearchTermsData: 36 // SearchTermsData:
37 virtual std::string GetSuggestClient() const OVERRIDE { 37 virtual std::string GetSuggestClient() const OVERRIDE {
38 return "chrome"; 38 return "chrome";
39 } 39 }
40 }; 40 };
41 41
42 // The AutocompleteSchemeClassifier implementation for Athena.
43 // TODO(mukai): Introduce supports of normal schemes like about: or blob:
44 class AthenaSchemeClassifier : public AutocompleteSchemeClassifier {
45 public:
46 AthenaSchemeClassifier() {}
47
48 // AutocompleteSchemeClassifier:
49 virtual metrics::OmniboxInputType::Type GetInputTypeForScheme(
50 const std::string& scheme) const OVERRIDE {
51 if (net::URLRequest::IsHandledProtocol(scheme))
52 return metrics::OmniboxInputType::URL;
53 return metrics::OmniboxInputType::INVALID;
54 }
55 };
56
57 // The templateURLServiceClient for Athena. Mainly for the interaction with 42 // The templateURLServiceClient for Athena. Mainly for the interaction with
58 // history module (see chrome/browser/search_engines for Chrome implementation). 43 // history module (see chrome/browser/search_engines for Chrome implementation).
59 // TODO(mukai): Implement the contents of this class when it's necessary. 44 // TODO(mukai): Implement the contents of this class when it's necessary.
60 class AthenaTemplateURLServiceClient : public TemplateURLServiceClient { 45 class AthenaTemplateURLServiceClient : public TemplateURLServiceClient {
61 public: 46 public:
62 AthenaTemplateURLServiceClient() {} 47 AthenaTemplateURLServiceClient() {}
63 virtual ~AthenaTemplateURLServiceClient() {} 48 virtual ~AthenaTemplateURLServiceClient() {}
64 49
65 private: 50 private:
66 // TemplateURLServiceClient: 51 // TemplateURLServiceClient:
67 virtual void SetOwner(TemplateURLService* owner) OVERRIDE {} 52 virtual void SetOwner(TemplateURLService* owner) OVERRIDE {}
68 virtual void DeleteAllSearchTermsForKeyword(TemplateURLID id) OVERRIDE {} 53 virtual void DeleteAllSearchTermsForKeyword(TemplateURLID id) OVERRIDE {}
69 virtual void SetKeywordSearchTermsForURL( 54 virtual void SetKeywordSearchTermsForURL(
70 const GURL& url, 55 const GURL& url,
71 TemplateURLID id, 56 TemplateURLID id,
72 const base::string16& term) OVERRIDE {} 57 const base::string16& term) OVERRIDE {}
73 virtual void AddKeywordGeneratedVisit(const GURL& url) OVERRIDE {} 58 virtual void AddKeywordGeneratedVisit(const GURL& url) OVERRIDE {}
74 virtual void RestoreExtensionInfoIfNecessary( 59 virtual void RestoreExtensionInfoIfNecessary(
75 TemplateURL* template_url) OVERRIDE {} 60 TemplateURL* template_url) OVERRIDE {}
76 61
77 DISALLOW_COPY_AND_ASSIGN(AthenaTemplateURLServiceClient); 62 DISALLOW_COPY_AND_ASSIGN(AthenaTemplateURLServiceClient);
78 }; 63 };
79 64
80 // The AutocompleteProviderClient for Athena. 65 // The AutocompleteProviderClient for Athena.
81 class AthenaAutocompleteProviderClient : public AutocompleteProviderClient { 66 class AthenaAutocompleteProviderClient : public AutocompleteProviderClient {
82 public: 67 public:
83 explicit AthenaAutocompleteProviderClient( 68 explicit AthenaAutocompleteProviderClient(
84 content::BrowserContext* browser_context) 69 content::BrowserContext* browser_context)
85 : browser_context_(browser_context) {} 70 : browser_context_(browser_context),
71 scheme_classifier_(CreateSchemeClassifier(browser_context)) {}
86 virtual ~AthenaAutocompleteProviderClient() {} 72 virtual ~AthenaAutocompleteProviderClient() {}
87 73
88 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE { 74 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
89 return browser_context_->GetRequestContext(); 75 return browser_context_->GetRequestContext();
90 } 76 }
91 virtual bool IsOffTheRecord() OVERRIDE { 77 virtual bool IsOffTheRecord() OVERRIDE {
92 return browser_context_->IsOffTheRecord(); 78 return browser_context_->IsOffTheRecord();
93 } 79 }
94 virtual std::string AcceptLanguages() OVERRIDE { 80 virtual std::string AcceptLanguages() OVERRIDE {
95 // TODO(hashimoto): Return the value stored in the prefs. 81 // TODO(hashimoto): Return the value stored in the prefs.
96 return "en-US"; 82 return "en-US";
97 } 83 }
98 virtual bool SearchSuggestEnabled() OVERRIDE { return true; } 84 virtual bool SearchSuggestEnabled() OVERRIDE { return true; }
99 virtual bool ShowBookmarkBar() OVERRIDE { return false; } 85 virtual bool ShowBookmarkBar() OVERRIDE { return false; }
100 virtual const AutocompleteSchemeClassifier& SchemeClassifier() OVERRIDE { 86 virtual const AutocompleteSchemeClassifier& SchemeClassifier() OVERRIDE {
101 return scheme_classifier_; 87 return *scheme_classifier_;
102 } 88 }
103 virtual void Classify( 89 virtual void Classify(
104 const base::string16& text, 90 const base::string16& text,
105 bool prefer_keyword, 91 bool prefer_keyword,
106 bool allow_exact_keyword_match, 92 bool allow_exact_keyword_match,
107 metrics::OmniboxEventProto::PageClassification page_classification, 93 metrics::OmniboxEventProto::PageClassification page_classification,
108 AutocompleteMatch* match, 94 AutocompleteMatch* match,
109 GURL* alternate_nav_url) OVERRIDE {} 95 GURL* alternate_nav_url) OVERRIDE {}
110 virtual history::URLDatabase* InMemoryDatabase() OVERRIDE { return NULL; } 96 virtual history::URLDatabase* InMemoryDatabase() OVERRIDE { return NULL; }
111 virtual void DeleteMatchingURLsForKeywordFromHistory( 97 virtual void DeleteMatchingURLsForKeywordFromHistory(
112 history::KeywordID keyword_id, 98 history::KeywordID keyword_id,
113 const base::string16& term) OVERRIDE {} 99 const base::string16& term) OVERRIDE {}
114 virtual bool TabSyncEnabledAndUnencrypted() OVERRIDE { return false; } 100 virtual bool TabSyncEnabledAndUnencrypted() OVERRIDE { return false; }
115 virtual void PrefetchImage(const GURL& url) OVERRIDE {} 101 virtual void PrefetchImage(const GURL& url) OVERRIDE {}
116 102
117 private: 103 private:
118 content::BrowserContext* browser_context_; 104 content::BrowserContext* browser_context_;
119 AthenaSchemeClassifier scheme_classifier_; 105 scoped_ptr<AutocompleteSchemeClassifier> scheme_classifier_;
120 106
121 DISALLOW_COPY_AND_ASSIGN(AthenaAutocompleteProviderClient); 107 DISALLOW_COPY_AND_ASSIGN(AthenaAutocompleteProviderClient);
122 }; 108 };
123 109
124 int ACMatchStyleToTagStyle(int styles) { 110 int ACMatchStyleToTagStyle(int styles) {
125 int tag_styles = 0; 111 int tag_styles = 0;
126 if (styles & ACMatchClassification::URL) 112 if (styles & ACMatchClassification::URL)
127 tag_styles |= app_list::SearchResult::Tag::URL; 113 tag_styles |= app_list::SearchResult::Tag::URL;
128 if (styles & ACMatchClassification::MATCH) 114 if (styles & ACMatchClassification::MATCH)
129 tag_styles |= app_list::SearchResult::Tag::MATCH; 115 tag_styles |= app_list::SearchResult::Tag::MATCH;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 scoped_ptr<AutocompleteProviderClient>( 225 scoped_ptr<AutocompleteProviderClient>(
240 new AthenaAutocompleteProviderClient(browser_context_)))) { 226 new AthenaAutocompleteProviderClient(browser_context_)))) {
241 template_url_service_->Load(); 227 template_url_service_->Load();
242 } 228 }
243 229
244 UrlSearchProvider::~UrlSearchProvider() { 230 UrlSearchProvider::~UrlSearchProvider() {
245 } 231 }
246 232
247 void UrlSearchProvider::Start(const base::string16& query) { 233 void UrlSearchProvider::Start(const base::string16& query) {
248 const bool minimal_changes = query == input_.text(); 234 const bool minimal_changes = query == input_.text();
235 scoped_ptr<AutocompleteSchemeClassifier> scheme_classifier(
236 CreateSchemeClassifier(browser_context_));
249 input_ = AutocompleteInput(query, 237 input_ = AutocompleteInput(query,
250 base::string16::npos /* cursor_position */, 238 base::string16::npos /* cursor_position */,
251 base::string16() /* desired_tld */, 239 base::string16() /* desired_tld */,
252 GURL() /* current_url */, 240 GURL() /* current_url */,
253 metrics::OmniboxEventProto::INVALID_SPEC, 241 metrics::OmniboxEventProto::INVALID_SPEC,
254 false /* prevent_inline_autocomplete */, 242 false /* prevent_inline_autocomplete */,
255 false /* prefer_keyword */, 243 false /* prefer_keyword */,
256 true /* allow_extract_keyword_match */, 244 true /* allow_extract_keyword_match */,
257 true /* want_asynchronous_matches */, 245 true /* want_asynchronous_matches */,
258 AthenaSchemeClassifier()); 246 *scheme_classifier);
259 247
260 provider_->Start(input_, minimal_changes); 248 // Clearing results here may cause unexpected results.
261 } 249 // TODO(mukai): fix this by fixing crbug.com/415500
262 250 if (!minimal_changes)
263 void UrlSearchProvider::Stop() { 251 ClearResults();
264 provider_->Stop(false);
265 }
266
267 void UrlSearchProvider::OnProviderUpdate(bool updated_matches) {
268 if (!updated_matches)
269 return;
270
271 ClearResults();
272 252
273 if (input_.type() == metrics::OmniboxInputType::URL) { 253 if (input_.type() == metrics::OmniboxInputType::URL) {
274 // TODO(hashimoto): Componentize HistoryURLProvider and remove this code. 254 // TODO(hashimoto): Componentize HistoryURLProvider and remove this code.
275 AutocompleteMatch what_you_typed_match( 255 AutocompleteMatch what_you_typed_match(
276 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED); 256 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED);
277 what_you_typed_match.destination_url = input_.canonicalized_url(); 257 what_you_typed_match.destination_url = input_.canonicalized_url();
278 what_you_typed_match.contents = input_.text(); 258 what_you_typed_match.contents = input_.text();
279 what_you_typed_match.relevance = kScoreForWhatYouTypedResult; 259 what_you_typed_match.relevance = kScoreForWhatYouTypedResult;
280 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult( 260 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult(
281 browser_context_, what_you_typed_match))); 261 browser_context_, what_you_typed_match)));
282 } 262 }
283 263
264 provider_->Start(input_, minimal_changes);
265 }
266
267 void UrlSearchProvider::Stop() {
268 provider_->Stop(false);
269 }
270
271 void UrlSearchProvider::OnProviderUpdate(bool updated_matches) {
272 if (!updated_matches)
273 return;
274
284 const ACMatches& matches = provider_->matches(); 275 const ACMatches& matches = provider_->matches();
285 for (ACMatches::const_iterator it = matches.begin(); it != matches.end(); 276 for (ACMatches::const_iterator it = matches.begin(); it != matches.end();
286 ++it) { 277 ++it) {
287 if (!it->destination_url.is_valid()) 278 if (!it->destination_url.is_valid())
288 continue; 279 continue;
289 280
290 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult( 281 Add(scoped_ptr<app_list::SearchResult>(new UrlSearchResult(
291 browser_context_, *it))); 282 browser_context_, *it)));
292 } 283 }
293 } 284 }
294 285
295 } // namespace athena 286 } // namespace athena
OLDNEW
« no previous file with comments | « athena/content/shell/scheme_classifier_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698