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

Side by Side Diff: chrome/browser/autocomplete/base_search_provider.cc

Issue 314013003: [AiS] Add prefetching for Answers images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@img-bridge
Patch Set: Rebase to HEAD Created 6 years, 6 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
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 "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"
11 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 15 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
16 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
17 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
16 #include "chrome/browser/history/history_service.h" 18 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/history/history_service_factory.h" 19 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/omnibox/omnibox_field_trial.h" 20 #include "chrome/browser/omnibox/omnibox_field_trial.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search/instant_service.h" 22 #include "chrome/browser/search/instant_service.h"
21 #include "chrome/browser/search/instant_service_factory.h" 23 #include "chrome/browser/search/instant_service_factory.h"
22 #include "chrome/browser/search/search.h" 24 #include "chrome/browser/search/search.h"
23 #include "chrome/browser/search_engines/template_url.h" 25 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 26 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
25 #include "chrome/browser/search_engines/template_url_service.h" 27 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // Error correction for bad data from server. 919 // Error correction for bad data from server.
918 if (match_contents.empty()) 920 if (match_contents.empty())
919 match_contents = suggestion; 921 match_contents = suggestion;
920 suggestion_detail->GetString("a", &annotation); 922 suggestion_detail->GetString("a", &annotation);
921 suggestion_detail->GetString("q", &suggest_query_params); 923 suggestion_detail->GetString("q", &suggest_query_params);
922 924
923 // Extract Answers, if provided. 925 // Extract Answers, if provided.
924 const base::DictionaryValue* answer_json = NULL; 926 const base::DictionaryValue* answer_json = NULL;
925 if (suggestion_detail->GetDictionary("ansa", &answer_json)) { 927 if (suggestion_detail->GetDictionary("ansa", &answer_json)) {
926 match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER; 928 match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
929 PrefetchAnswersImages(answer_json);
927 std::string contents; 930 std::string contents;
928 base::JSONWriter::Write(answer_json, &contents); 931 base::JSONWriter::Write(answer_json, &contents);
929 answer_contents = base::UTF8ToUTF16(contents); 932 answer_contents = base::UTF8ToUTF16(contents);
930 suggestion_detail->GetString("ansb", &answer_type); 933 suggestion_detail->GetString("ansb", &answer_type);
931 } 934 }
932 } 935 }
933 } 936 }
934 937
935 bool should_prefetch = static_cast<int>(index) == prefetch_index; 938 bool should_prefetch = static_cast<int>(index) == prefetch_index;
936 // TODO(kochi): Improve calculator suggestion presentation. 939 // TODO(kochi): Improve calculator suggestion presentation.
937 results->suggest_results.push_back(SuggestResult( 940 results->suggest_results.push_back(SuggestResult(
938 base::CollapseWhitespace(suggestion, false), match_type, 941 base::CollapseWhitespace(suggestion, false), match_type,
939 base::CollapseWhitespace(match_contents, false), 942 base::CollapseWhitespace(match_contents, false),
940 match_contents_prefix, annotation, answer_contents, answer_type, 943 match_contents_prefix, annotation, answer_contents, answer_type,
941 suggest_query_params, deletion_url, is_keyword_result, relevance, 944 suggest_query_params, deletion_url, is_keyword_result, relevance,
942 relevances != NULL, should_prefetch, trimmed_input)); 945 relevances != NULL, should_prefetch, trimmed_input));
943 } 946 }
944 } 947 }
945 SortResults(is_keyword_result, relevances, results); 948 SortResults(is_keyword_result, relevances, results);
946 return true; 949 return true;
947 } 950 }
948 951
952 void BaseSearchProvider::PrefetchAnswersImages(
953 const base::DictionaryValue* answer_json) {
954 DCHECK(answer_json);
955 const base::ListValue* lines = NULL;
956 answer_json->GetList("l", &lines);
957 if (!lines || lines->GetSize() == 0)
958 return;
959
960 BitmapFetcherService* image_service =
961 BitmapFetcherServiceFactory::GetForBrowserContext(profile_);
962 DCHECK(image_service);
963
964 for (size_t line = 0; line < lines->GetSize(); ++line) {
965 const base::DictionaryValue* imageLine = NULL;
966 lines->GetDictionary(line, &imageLine);
967 if (!imageLine)
968 continue;
969 const base::DictionaryValue* imageData = NULL;
970 imageLine->GetDictionary("i", &imageData);
971 if (!imageData)
972 continue;
973 std::string imageUrl;
974 imageData->GetString("d", &imageUrl);
975 image_service->Prefetch(GURL(imageUrl));
976 }
977 }
978
949 void BaseSearchProvider::SortResults(bool is_keyword, 979 void BaseSearchProvider::SortResults(bool is_keyword,
950 const base::ListValue* relevances, 980 const base::ListValue* relevances,
951 Results* results) { 981 Results* results) {
952 } 982 }
953 983
954 bool BaseSearchProvider::StoreSuggestionResponse( 984 bool BaseSearchProvider::StoreSuggestionResponse(
955 const std::string& json_data, 985 const std::string& json_data,
956 const base::Value& parsed_data) { 986 const base::Value& parsed_data) {
957 return false; 987 return false;
958 } 988 }
(...skipping 18 matching lines...) Expand all
977 } 1007 }
978 1008
979 void BaseSearchProvider::OnDeletionComplete( 1009 void BaseSearchProvider::OnDeletionComplete(
980 bool success, SuggestionDeletionHandler* handler) { 1010 bool success, SuggestionDeletionHandler* handler) {
981 RecordDeletionResult(success); 1011 RecordDeletionResult(success);
982 SuggestionDeletionHandlers::iterator it = std::find( 1012 SuggestionDeletionHandlers::iterator it = std::find(
983 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 1013 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
984 DCHECK(it != deletion_handlers_.end()); 1014 DCHECK(it != deletion_handlers_.end());
985 deletion_handlers_.erase(it); 1015 deletion_handlers_.erase(it);
986 } 1016 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698