15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This class contains common functionality for search-based autocomplete 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// providers. Search provider and zero suggest provider both use it for common 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// functionality. 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef COMPONENTS_OMNIBOX_BASE_SEARCH_PROVIDER_H_ 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define COMPONENTS_OMNIBOX_BASE_SEARCH_PROVIDER_H_ 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <map> 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string> 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <utility> 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <vector> 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/memory/scoped_vector.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/string16.h" 196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/metrics/proto/omnibox_event.pb.h" 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_input.h" 215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_match.h" 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_provider.h" 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/search_suggestion_parser.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass AutocompleteProviderClient; 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class GURL; 275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class SearchTermsData; 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SuggestionDeletionHandler; 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TemplateURL; 305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class TemplateURLService; 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace base { 336d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)class DictionaryValue; 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ListValue; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Value; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Base functionality for receiving suggestions from a search engine. 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This class is abstract and should only be used as a base for other 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// autocomplete providers utilizing its functionality. 416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class BaseSearchProvider : public AutocompleteProvider { 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // ID used in creating URLFetcher for default provider's suggest results. 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static const int kDefaultProviderURLFetcherID; 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // ID used in creating URLFetcher for keyword provider's suggest results. 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static const int kKeywordProviderURLFetcherID; 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // ID used in creating URLFetcher for deleting suggestion results. 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static const int kDeletionURLFetcherID; 51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 526e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) BaseSearchProvider(TemplateURLService* template_url_service, 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<AutocompleteProviderClient> client, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutocompleteProvider::Type type); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns whether |match| is flagged as a query that should be prefetched. 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static bool ShouldPrefetch(const AutocompleteMatch& match); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Returns a simpler AutocompleteMatch suitable for persistence like in 606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // ShortcutsDatabase. This wrapper function uses a number of default values 616e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // that may or may not be appropriate for your needs. 62effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // NOTE: Use with care. Most likely you want the other CreateSearchSuggestion 63effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // with protected access. 64effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch static AutocompleteMatch CreateSearchSuggestion( 65effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const base::string16& suggestion, 66effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch AutocompleteMatchType::Type type, 67effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool from_keyword_provider, 68f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const TemplateURL* template_url, 69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const SearchTermsData& search_terms_data); 70effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // AutocompleteProvider: 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool field_trial_triggered_in_session() const { 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return field_trial_triggered_in_session_; 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected: 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The following keys are used to record additional information on matches. 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We annotate our AutocompleteMatches with whether their relevance scores 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // were server-provided using this key in the |additional_info| field. 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kRelevanceFromServerKey[]; 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Indicates whether the server said a match should be prefetched. 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kShouldPrefetchKey[]; 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used to store metadata from the server response, which is needed for 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // prefetching. 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kSuggestMetadataKey[]; 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used to store a deletion request url for server-provided suggestions. 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kDeletionUrlKey[]; 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // These are the values for the above keys. 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kTrue[]; 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static const char kFalse[]; 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~BaseSearchProvider(); 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef std::pair<base::string16, std::string> MatchKey; 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) typedef std::map<MatchKey, AutocompleteMatch> MatchMap; 104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) typedef ScopedVector<SuggestionDeletionHandler> SuggestionDeletionHandlers; 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns an AutocompleteMatch with the given |autocomplete_provider| 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // for the search |suggestion|, which represents a search via |template_url|. 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If |template_url| is NULL, returns a match with an invalid destination URL. 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |input| is the original user input. Text in the input is used to highlight 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // portions of the match contents to distinguish locally-typed text from 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // suggested text. 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |input| is also necessary for various other details, like whether we should 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // allow inline autocompletion and what the transition type should be. 1166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |in_keyword_mode| helps guarantee a non-keyword suggestion does not 1176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // appear as the default match when the user is in keyword mode. 1185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // |accepted_suggestion| is used to generate Assisted Query Stats. 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |append_extra_query_params| should be set if |template_url| is the default 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // search engine, so the destination URL will contain any 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // command-line-specified query params. 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static AutocompleteMatch CreateSearchSuggestion( 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutocompleteProvider* autocomplete_provider, 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const AutocompleteInput& input, 1256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const bool in_keyword_mode, 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const SearchSuggestionParser::SuggestResult& suggestion, 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TemplateURL* template_url, 128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const SearchTermsData& search_terms_data, 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int accepted_suggestion, 1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool append_extra_query_params); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 13223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Returns whether the requirements for requesting zero suggest results 13323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // are met. The requirements are 13423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // * The user is enrolled in a zero suggest experiment. 13523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // * The user is not on the NTP. 13623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // * The suggest request is sent over HTTPS. This avoids leaking the current 13723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // page URL or personal data in unencrypted network traffic. 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // * The user has suggest enabled in their settings and is not in incognito 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // mode. (Incognito disables suggest entirely.) 14023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // * The user's suggest provider is Google. We might want to allow other 14123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // providers to see this data someday, but for now this has only been 14223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // implemented for Google. 14323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) static bool ZeroSuggestEnabled( 14423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const GURL& suggest_url, 14523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const TemplateURL* template_url, 1466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) metrics::OmniboxEventProto::PageClassification page_classification, 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const SearchTermsData& search_terms_data, 1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci AutocompleteProviderClient* client); 14923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 15023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Returns whether we can send the URL of the current page in any suggest 15123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // requests. Doing this requires that all the following hold: 15223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // * ZeroSuggestEnabled() is true, so we meet the requirements above. 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // * The current URL is HTTP, or HTTPS with the same domain as the suggest 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // server. Non-HTTP[S] URLs (e.g. FTP/file URLs) may contain sensitive 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // information. HTTPS URLs may also contain sensitive information, but if 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // they're on the same domain as the suggest server, then the relevant 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // entity could have already seen/logged this data. 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // * The user is OK in principle with sending URLs of current pages to their 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // provider. Today, there is no explicit setting that controls this, but if 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the user has tab sync enabled and tab sync is unencrypted, then they're 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // already sending this data to Google for sync purposes. Thus we use this 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // setting as a proxy for "it's OK to send such data". In the future, 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // especially if we want to support suggest providers other than Google, we 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // may change this to be a standalone setting or part of some explicit 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // general opt-in. 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) static bool CanSendURL( 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& current_page_url, 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& suggest_url, 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TemplateURL* template_url, 1706d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) metrics::OmniboxEventProto::PageClassification page_classification, 1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const SearchTermsData& search_terms_data, 1721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci AutocompleteProviderClient* client); 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 174010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // If the |deletion_url| is valid, then set |match.deletable| to true and 175010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // save the |deletion_url| into the |match|'s additional info under 176010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // the key |kDeletionUrlKey|. 177010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) void SetDeletionURL(const std::string& deletion_url, 178010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) AutocompleteMatch* match); 179010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Creates an AutocompleteMatch from |result| to search for the query in 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |result|. Adds the created match to |map|; if such a match 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // already exists, whichever one has lower relevance is eliminated. 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |metadata| and |accepted_suggestion| are used for generating an 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // AutocompleteMatch. 185a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |mark_as_deletable| indicates whether the match should be marked deletable. 1866e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |in_keyword_mode| helps guarantee a non-keyword suggestion does not 1876e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // appear as the default match when the user is in keyword mode. 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // NOTE: Any result containing a deletion URL is always marked deletable. 1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void AddMatchToMap(const SearchSuggestionParser::SuggestResult& result, 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& metadata, 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int accepted_suggestion, 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool mark_as_deletable, 1936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool in_keyword_mode, 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MatchMap* map); 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 196a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Parses results from the suggest server and updates the appropriate suggest 1976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // and navigation result lists in |results|. |default_result_relevance| is 1986e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // the relevance to use if it was not explicitly set by the server. 1996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // |is_keyword_result| indicates whether the response was received from the 2006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // keyword provider. 201a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns whether the appropriate result list members were updated. 202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool ParseSuggestResults(const base::Value& root_val, 2036e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) int default_result_relevance, 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool is_keyword_result, 2055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SearchSuggestionParser::Results* results); 2066d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 20723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Returns the TemplateURL corresponding to the keyword or default 20823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // provider based on the value of |is_keyword|. 20923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual const TemplateURL* GetTemplateURL(bool is_keyword) const = 0; 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns the AutocompleteInput for keyword provider or default provider 212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // based on the value of |is_keyword|. 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual const AutocompleteInput GetInput(bool is_keyword) const = 0; 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns whether the destination URL corresponding to the given |result| 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // should contain command-line-specified query params. 2175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual bool ShouldAppendExtraParams( 2185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const SearchSuggestionParser::SuggestResult& result) const = 0; 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Records in UMA whether the deletion request resulted in success. 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RecordDeletionResult(bool success) = 0; 222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TemplateURLService* template_url_service_; 2241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci scoped_ptr<AutocompleteProviderClient> client_; 225116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Whether a field trial, if any, has triggered in the most recent 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // autocomplete query. This field is set to true only if the suggestion 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // provider has completed and the response contained 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // '"google:fieldtrialtriggered":true'. 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool field_trial_triggered_; 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Same as above except that it is maintained across the current Omnibox 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // session. 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool field_trial_triggered_in_session_; 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 237a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) friend class SearchProviderTest; 238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); 239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Removes the deleted |match| from the list of |matches_|. 241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void DeleteMatchFromMatches(const AutocompleteMatch& match); 242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This gets called when we have requested a suggestion deletion from the 244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // server to handle the results of the deletion. It will be called after the 245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // deletion request completes. 246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void OnDeletionComplete(bool success, 247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SuggestionDeletionHandler* handler); 248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Each deletion handler in this vector corresponds to an outstanding request 250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // that a server delete a personalized suggestion. Making this a ScopedVector 251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // causes us to auto-cancel all such requests on shutdown. 252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) SuggestionDeletionHandlers deletion_handlers_; 253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif // COMPONENTS_OMNIBOX_BASE_SEARCH_PROVIDER_H_ 258