Index: chrome/browser/autocomplete/base_search_provider.cc |
diff --git a/chrome/browser/autocomplete/base_search_provider.cc b/chrome/browser/autocomplete/base_search_provider.cc |
index 3d47edadc95ad8d42459c129cb5354b3de578d87..70942a170d9f6bdeebaef813d66031deb1facca2 100644 |
--- a/chrome/browser/autocomplete/base_search_provider.cc |
+++ b/chrome/browser/autocomplete/base_search_provider.cc |
@@ -12,6 +12,8 @@ |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/autocomplete/answers_image_service.h" |
+#include "chrome/browser/autocomplete/answers_image_service_factory.h" |
#include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
#include "chrome/browser/autocomplete/url_prefix.h" |
#include "chrome/browser/history/history_service.h" |
@@ -913,6 +915,7 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val, |
// Extract Answers, if provided. |
const base::DictionaryValue* answer_json = NULL; |
if (suggestion_detail->GetDictionary("ansa", &answer_json)) { |
+ PrefetchAnswersImages(answer_json); |
std::string contents; |
base::JSONWriter::Write(answer_json, &contents); |
answer_contents = base::UTF8ToUTF16(contents); |
@@ -935,6 +938,40 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val, |
return true; |
} |
+void BaseSearchProvider::PrefetchAnswersImages( |
+ const base::DictionaryValue* answer_json) { |
+ DCHECK(answer_json); |
+ const base::ListValue* lines = NULL; |
+ answer_json->GetList("l", &lines); |
+ if (!lines || lines->GetSize() == 0) |
+ return; |
+ |
+ // TODO(groby): Do we want prefetch in incognito? |
Peter Kasting
2014/06/05 23:42:47
We don't currently send suggest requests in incogn
groby-ooo-7-16
2014/06/14 00:22:08
Done.
|
+ AnswersImageService* image_service = |
+ AnswersImageServiceFactory::GetForBrowserContext(profile_); |
+ DCHECK(image_service); |
+ |
+ for (size_t line = 0; line < lines->GetSize(); ++line) { |
+ const base::DictionaryValue* imageLine = NULL; |
+ lines->GetDictionary(line, &imageLine); |
+ if (!imageLine) |
+ continue; |
+ const base::DictionaryValue* imageData = NULL; |
+ imageLine->GetDictionary("i", &imageData); |
+ if (!imageData) |
+ continue; |
+ std::string imageUrl; |
+ imageData->GetString("d", &imageUrl); |
+ |
+ // Not having an URL is technically a malformed reply, but crashing seems |
+ // overly harsh as response. |
Peter Kasting
2014/06/05 23:42:47
This comment doesn't seem necessary -- clearly we
groby-ooo-7-16
2014/06/14 00:22:08
Removed.
|
+ if (imageUrl.empty()) |
+ continue; |
+ LOG(ERROR) << "Prefetching image for " << imageUrl; |
Peter Kasting
2014/06/05 23:42:47
I don't think you should check this line in.
groby-ooo-7-16
2014/06/14 00:22:08
Done.
|
+ image_service->Prefetch(GURL(imageUrl)); |
Peter Kasting
2014/06/05 23:42:47
What if GURL(imageUrl) is invalid? This can happe
groby-ooo-7-16
2014/06/14 00:22:08
Done.
|
+ } |
+} |
+ |
void BaseSearchProvider::SortResults(bool is_keyword, |
const base::ListValue* relevances, |
Results* results) { |