| 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/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/sync/profile_sync_service.h" | 27 #include "chrome/browser/sync/profile_sync_service.h" |
| 28 #include "chrome/browser/sync/profile_sync_service_factory.h" | 28 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 29 #include "chrome/common/net/url_fixer_upper.h" | 29 #include "chrome/common/net/url_fixer_upper.h" |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "components/sync_driver/sync_prefs.h" | 31 #include "components/sync_driver/sync_prefs.h" |
| 32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
| 33 #include "net/base/escape.h" | 33 #include "net/base/escape.h" |
| 34 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 35 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 35 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 36 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
| 37 #include "net/url_request/url_fetcher.h" |
| 37 #include "net/url_request/url_fetcher_delegate.h" | 38 #include "net/url_request/url_fetcher_delegate.h" |
| 38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 43 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
| 43 if (type == "ENTITY") | 44 if (type == "ENTITY") |
| 44 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 45 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
| 45 if (type == "INFINITE") | 46 if (type == "INFINITE") |
| 46 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 47 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 GURL url(deletion_url); | 91 GURL url(deletion_url); |
| 91 DCHECK(url.is_valid()); | 92 DCHECK(url.is_valid()); |
| 92 | 93 |
| 93 deletion_fetcher_.reset(net::URLFetcher::Create( | 94 deletion_fetcher_.reset(net::URLFetcher::Create( |
| 94 BaseSearchProvider::kDeletionURLFetcherID, | 95 BaseSearchProvider::kDeletionURLFetcherID, |
| 95 url, | 96 url, |
| 96 net::URLFetcher::GET, | 97 net::URLFetcher::GET, |
| 97 this)); | 98 this)); |
| 98 deletion_fetcher_->SetRequestContext(profile->GetRequestContext()); | 99 deletion_fetcher_->SetRequestContext(profile->GetRequestContext()); |
| 99 deletion_fetcher_->Start(); | 100 deletion_fetcher_->Start(); |
| 100 }; | 101 } |
| 101 | 102 |
| 102 SuggestionDeletionHandler::~SuggestionDeletionHandler() { | 103 SuggestionDeletionHandler::~SuggestionDeletionHandler() { |
| 103 }; | 104 } |
| 104 | 105 |
| 105 void SuggestionDeletionHandler::OnURLFetchComplete( | 106 void SuggestionDeletionHandler::OnURLFetchComplete( |
| 106 const net::URLFetcher* source) { | 107 const net::URLFetcher* source) { |
| 107 DCHECK(source == deletion_fetcher_.get()); | 108 DCHECK(source == deletion_fetcher_.get()); |
| 108 callback_.Run( | 109 callback_.Run( |
| 109 source->GetStatus().is_success() && (source->GetResponseCode() == 200), | 110 source->GetStatus().is_success() && (source->GetResponseCode() == 200), |
| 110 this); | 111 this); |
| 111 }; | 112 } |
| 112 | 113 |
| 113 // BaseSearchProvider --------------------------------------------------------- | 114 // BaseSearchProvider --------------------------------------------------------- |
| 114 | 115 |
| 115 // static | 116 // static |
| 116 const int BaseSearchProvider::kDefaultProviderURLFetcherID = 1; | 117 const int BaseSearchProvider::kDefaultProviderURLFetcherID = 1; |
| 117 const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2; | 118 const int BaseSearchProvider::kKeywordProviderURLFetcherID = 2; |
| 118 const int BaseSearchProvider::kDeletionURLFetcherID = 3; | 119 const int BaseSearchProvider::kDeletionURLFetcherID = 3; |
| 119 | 120 |
| 120 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, | 121 BaseSearchProvider::BaseSearchProvider(AutocompleteProviderListener* listener, |
| 121 Profile* profile, | 122 Profile* profile, |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 } | 948 } |
| 948 | 949 |
| 949 void BaseSearchProvider::OnDeletionComplete( | 950 void BaseSearchProvider::OnDeletionComplete( |
| 950 bool success, SuggestionDeletionHandler* handler) { | 951 bool success, SuggestionDeletionHandler* handler) { |
| 951 RecordDeletionResult(success); | 952 RecordDeletionResult(success); |
| 952 SuggestionDeletionHandlers::iterator it = std::find( | 953 SuggestionDeletionHandlers::iterator it = std::find( |
| 953 deletion_handlers_.begin(), deletion_handlers_.end(), handler); | 954 deletion_handlers_.begin(), deletion_handlers_.end(), handler); |
| 954 DCHECK(it != deletion_handlers_.end()); | 955 DCHECK(it != deletion_handlers_.end()); |
| 955 deletion_handlers_.erase(it); | 956 deletion_handlers_.erase(it); |
| 956 } | 957 } |
| OLD | NEW |