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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autocomplete/base_search_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « chrome/browser/autocomplete/base_search_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698