Commit 9d95f04c authored by groby@chromium.org's avatar groby@chromium.org

[AiS] Add prefetching for Answers images.

BUG=380916

R=pkasting@chromium.org
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/314013003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278653 0039d316-1c4b-4281-b951-d872f2087c98
parent 7d561359
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_provider_listener.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.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/omnibox/omnibox_field_trial.h"
...@@ -924,6 +926,7 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val, ...@@ -924,6 +926,7 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val,
const base::DictionaryValue* answer_json = NULL; const base::DictionaryValue* answer_json = NULL;
if (suggestion_detail->GetDictionary("ansa", &answer_json)) { if (suggestion_detail->GetDictionary("ansa", &answer_json)) {
match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER; match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
PrefetchAnswersImages(answer_json);
std::string contents; std::string contents;
base::JSONWriter::Write(answer_json, &contents); base::JSONWriter::Write(answer_json, &contents);
answer_contents = base::UTF8ToUTF16(contents); answer_contents = base::UTF8ToUTF16(contents);
...@@ -946,6 +949,33 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val, ...@@ -946,6 +949,33 @@ bool BaseSearchProvider::ParseSuggestResults(const base::Value& root_val,
return true; 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, void BaseSearchProvider::SortResults(bool is_keyword,
const base::ListValue* relevances, const base::ListValue* relevances,
Results* results) { Results* results) {
......
...@@ -28,6 +28,7 @@ class SuggestionDeletionHandler; ...@@ -28,6 +28,7 @@ class SuggestionDeletionHandler;
class TemplateURL; class TemplateURL;
namespace base { namespace base {
class DictionaryValue;
class ListValue; class ListValue;
class Value; class Value;
} }
...@@ -434,6 +435,9 @@ class BaseSearchProvider : public AutocompleteProvider, ...@@ -434,6 +435,9 @@ class BaseSearchProvider : public AutocompleteProvider,
bool is_keyword_result, bool is_keyword_result,
Results* results); Results* results);
// Prefetches any images in Answers results.
void PrefetchAnswersImages(const base::DictionaryValue* answers_json);
// Called at the end of ParseSuggestResults to rank the |results|. // Called at the end of ParseSuggestResults to rank the |results|.
virtual void SortResults(bool is_keyword, virtual void SortResults(bool is_keyword,
const base::ListValue* relevances, const base::ListValue* relevances,
......
...@@ -114,6 +114,7 @@ BitmapFetcherService::RequestId BitmapFetcherService::RequestImage( ...@@ -114,6 +114,7 @@ BitmapFetcherService::RequestId BitmapFetcherService::RequestImage(
} }
void BitmapFetcherService::Prefetch(const GURL& url) { void BitmapFetcherService::Prefetch(const GURL& url) {
if (url.is_valid())
EnsureFetcherForUrl(url); EnsureFetcherForUrl(url);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment