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

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: 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 side-by-side diff with in-line comments
Download patch
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 70833e992478e19fd5cfe3c1d7b6cde97c0251a1..c7ee41ea404fe3369cda3b879c0c8ee18b76fa98 100644
--- a/chrome/browser/autocomplete/base_search_provider.cc
+++ b/chrome/browser/autocomplete/base_search_provider.cc
@@ -13,6 +13,8 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
+#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
+#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_field_trial.h"
@@ -924,6 +926,7 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val,
const base::DictionaryValue* answer_json = NULL;
if (suggestion_detail->GetDictionary("ansa", &answer_json)) {
match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
+ PrefetchAnswersImages(answer_json);
std::string contents;
base::JSONWriter::Write(answer_json, &contents);
answer_contents = base::UTF8ToUTF16(contents);
@@ -946,6 +949,33 @@ 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;
+
+ BitmapFetcherService* image_service =
+ BitmapFetcherServiceFactory::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);
+ image_service->Prefetch(GURL(imageUrl));
+ }
+}
+
void BaseSearchProvider::SortResults(bool is_keyword,
const base::ListValue* relevances,
Results* results) {

Powered by Google App Engine
This is Rietveld 408576698