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 "chrome/browser/autocomplete/base_search_provider.h" | 5 #include "chrome/browser/autocomplete/base_search_provider.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/search/search.h" | 22 #include "chrome/browser/search/search.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 23 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 24 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
25 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
27 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 27 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
28 #include "chrome/browser/sync/profile_sync_service.h" | 28 #include "chrome/browser/sync/profile_sync_service.h" |
29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 29 #include "chrome/browser/sync/profile_sync_service_factory.h" |
30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
31 #include "components/autocomplete/url_prefix.h" | 31 #include "components/autocomplete/url_prefix.h" |
| 32 #include "components/metrics/proto/omnibox_event.pb.h" |
32 #include "components/metrics/proto/omnibox_input_type.pb.h" | 33 #include "components/metrics/proto/omnibox_input_type.pb.h" |
33 #include "components/sync_driver/sync_prefs.h" | 34 #include "components/sync_driver/sync_prefs.h" |
34 #include "components/url_fixer/url_fixer.h" | 35 #include "components/url_fixer/url_fixer.h" |
35 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
36 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
37 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 39 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
39 #include "net/http/http_response_headers.h" | 40 #include "net/http/http_response_headers.h" |
40 #include "net/url_request/url_fetcher.h" | 41 #include "net/url_request/url_fetcher.h" |
41 #include "net/url_request/url_fetcher_delegate.h" | 42 #include "net/url_request/url_fetcher_delegate.h" |
42 #include "url/gurl.h" | 43 #include "url/gurl.h" |
43 | 44 |
| 45 using metrics::OmniboxEventProto; |
| 46 |
44 namespace { | 47 namespace { |
45 | 48 |
46 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 49 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
47 if (type == "ENTITY") | 50 if (type == "ENTITY") |
48 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 51 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
49 if (type == "INFINITE") | 52 if (type == "INFINITE") |
50 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 53 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
51 if (type == "PERSONALIZED_QUERY") | 54 if (type == "PERSONALIZED_QUERY") |
52 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; | 55 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
53 if (type == "PROFILE") | 56 if (type == "PROFILE") |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 if (error_code == 0) | 582 if (error_code == 0) |
580 return data.Pass(); | 583 return data.Pass(); |
581 } | 584 } |
582 return scoped_ptr<base::Value>(); | 585 return scoped_ptr<base::Value>(); |
583 } | 586 } |
584 | 587 |
585 // static | 588 // static |
586 bool BaseSearchProvider::ZeroSuggestEnabled( | 589 bool BaseSearchProvider::ZeroSuggestEnabled( |
587 const GURL& suggest_url, | 590 const GURL& suggest_url, |
588 const TemplateURL* template_url, | 591 const TemplateURL* template_url, |
589 AutocompleteInput::PageClassification page_classification, | 592 OmniboxEventProto::PageClassification page_classification, |
590 Profile* profile) { | 593 Profile* profile) { |
591 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) | 594 if (!OmniboxFieldTrial::InZeroSuggestFieldTrial()) |
592 return false; | 595 return false; |
593 | 596 |
594 // Make sure we are sending the suggest request through HTTPS to prevent | 597 // Make sure we are sending the suggest request through HTTPS to prevent |
595 // exposing the current page URL or personalized results without encryption. | 598 // exposing the current page URL or personalized results without encryption. |
596 if (!suggest_url.SchemeIs(url::kHttpsScheme)) | 599 if (!suggest_url.SchemeIs(url::kHttpsScheme)) |
597 return false; | 600 return false; |
598 | 601 |
599 // Don't show zero suggest on the NTP. | 602 // Don't show zero suggest on the NTP. |
600 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP | 603 // TODO(hfung): Experiment with showing MostVisited zero suggest on NTP |
601 // under the conditions described in crbug.com/305366. | 604 // under the conditions described in crbug.com/305366. |
602 if ((page_classification == | 605 if ((page_classification == |
603 AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || | 606 OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS) || |
604 (page_classification == | 607 (page_classification == |
605 AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) | 608 OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS)) |
606 return false; | 609 return false; |
607 | 610 |
608 // Don't run if there's no profile or in incognito mode. | 611 // Don't run if there's no profile or in incognito mode. |
609 if (profile == NULL || profile->IsOffTheRecord()) | 612 if (profile == NULL || profile->IsOffTheRecord()) |
610 return false; | 613 return false; |
611 | 614 |
612 // Don't run if we can't get preferences or search suggest is not enabled. | 615 // Don't run if we can't get preferences or search suggest is not enabled. |
613 PrefService* prefs = profile->GetPrefs(); | 616 PrefService* prefs = profile->GetPrefs(); |
614 if (!prefs->GetBoolean(prefs::kSearchSuggestEnabled)) | 617 if (!prefs->GetBoolean(prefs::kSearchSuggestEnabled)) |
615 return false; | 618 return false; |
616 | 619 |
617 // Only make the request if we know that the provider supports zero suggest | 620 // Only make the request if we know that the provider supports zero suggest |
618 // (currently only the prepopulated Google provider). | 621 // (currently only the prepopulated Google provider). |
619 UIThreadSearchTermsData search_terms_data(profile); | 622 UIThreadSearchTermsData search_terms_data(profile); |
620 if (template_url == NULL || | 623 if (template_url == NULL || |
621 !template_url->SupportsReplacement(search_terms_data) || | 624 !template_url->SupportsReplacement(search_terms_data) || |
622 TemplateURLPrepopulateData::GetEngineType( | 625 TemplateURLPrepopulateData::GetEngineType( |
623 *template_url, search_terms_data) != SEARCH_ENGINE_GOOGLE) | 626 *template_url, search_terms_data) != SEARCH_ENGINE_GOOGLE) |
624 return false; | 627 return false; |
625 | 628 |
626 return true; | 629 return true; |
627 } | 630 } |
628 | 631 |
629 // static | 632 // static |
630 bool BaseSearchProvider::CanSendURL( | 633 bool BaseSearchProvider::CanSendURL( |
631 const GURL& current_page_url, | 634 const GURL& current_page_url, |
632 const GURL& suggest_url, | 635 const GURL& suggest_url, |
633 const TemplateURL* template_url, | 636 const TemplateURL* template_url, |
634 AutocompleteInput::PageClassification page_classification, | 637 OmniboxEventProto::PageClassification page_classification, |
635 Profile* profile) { | 638 Profile* profile) { |
636 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, | 639 if (!ZeroSuggestEnabled(suggest_url, template_url, page_classification, |
637 profile)) | 640 profile)) |
638 return false; | 641 return false; |
639 | 642 |
640 if (!current_page_url.is_valid()) | 643 if (!current_page_url.is_valid()) |
641 return false; | 644 return false; |
642 | 645 |
643 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search | 646 // Only allow HTTP URLs or HTTPS URLs for the same domain as the search |
644 // provider. | 647 // provider. |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 } | 980 } |
978 | 981 |
979 void BaseSearchProvider::OnDeletionComplete( | 982 void BaseSearchProvider::OnDeletionComplete( |
980 bool success, SuggestionDeletionHandler* handler) { | 983 bool success, SuggestionDeletionHandler* handler) { |
981 RecordDeletionResult(success); | 984 RecordDeletionResult(success); |
982 SuggestionDeletionHandlers::iterator it = std::find( | 985 SuggestionDeletionHandlers::iterator it = std::find( |
983 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 986 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
984 DCHECK(it != deletion_handlers_.end()); | 987 DCHECK(it != deletion_handlers_.end()); |
985 deletion_handlers_.erase(it); | 988 deletion_handlers_.erase(it); |
986 } | 989 } |
OLD | NEW |