Commit f29505db authored by pke's avatar pke Committed by Commit bot

Remove snippet_id from ImageFetchedCallback

BUG=None

Review-Url: https://codereview.chromium.org/2280543003
Cr-Commit-Position: refs/heads/master@{#414709}
parent 166a7cf0
......@@ -324,7 +324,6 @@ void NTPSnippetsBridge::ContentSuggestionsServiceShutdown() {
}
void NTPSnippetsBridge::OnImageFetched(ScopedJavaGlobalRef<jobject> callback,
const std::string& snippet_id,
const gfx::Image& image) {
ScopedJavaLocalRef<jobject> j_bitmap;
if (!image.IsEmpty())
......
......@@ -115,7 +115,6 @@ class NTPSnippetsBridge
void ContentSuggestionsServiceShutdown() override;
void OnImageFetched(base::android::ScopedJavaGlobalRef<jobject> callback,
const std::string& snippet_id,
const gfx::Image& image);
ntp_snippets::Category CategoryFromIDValue(jint id);
......
......@@ -181,7 +181,7 @@ void BookmarkSuggestionsProvider::FetchSuggestionImage(
const std::string& suggestion_id,
const ImageFetchedCallback& callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
FROM_HERE, base::Bind(callback, gfx::Image()));
}
void BookmarkSuggestionsProvider::ClearCachedSuggestions(Category category) {
......
......@@ -28,8 +28,7 @@ namespace ntp_snippets {
// shut down by the ContentSuggestionsService.
class ContentSuggestionsProvider {
public:
using ImageFetchedCallback =
base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>;
using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
using DismissedSuggestionsCallback = base::Callback<void(
std::vector<ContentSuggestion> dismissed_suggestions)>;
......
......@@ -66,7 +66,7 @@ void ContentSuggestionsService::FetchSuggestionImage(
if (!id_category_map_.count(suggestion_id)) {
LOG(WARNING) << "Requested image for unknown suggestion " << suggestion_id;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
FROM_HERE, base::Bind(callback, gfx::Image()));
return;
}
Category category = id_category_map_.at(suggestion_id);
......@@ -74,7 +74,7 @@ void ContentSuggestionsService::FetchSuggestionImage(
LOG(WARNING) << "Requested image for suggestion " << suggestion_id
<< " for unavailable category " << category;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
FROM_HERE, base::Bind(callback, gfx::Image()));
return;
}
providers_by_category_[category]->FetchSuggestionImage(suggestion_id,
......
......@@ -31,8 +31,7 @@ class NTPSnippetsService;
class ContentSuggestionsService : public KeyedService,
public ContentSuggestionsProvider::Observer {
public:
using ImageFetchedCallback =
base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>;
using ImageFetchedCallback = base::Callback<void(const gfx::Image&)>;
using DismissedSuggestionsCallback = base::Callback<void(
std::vector<ContentSuggestion> dismissed_suggestions)>;
......
......@@ -195,8 +195,7 @@ class ContentSuggestionsServiceTest : public testing::Test {
return result;
}
MOCK_METHOD2(OnImageFetched,
void(const std::string& suggestion_id, const gfx::Image&));
MOCK_METHOD1(OnImageFetched, void(const gfx::Image&));
protected:
void CreateContentSuggestionsService(
......@@ -301,8 +300,7 @@ TEST_F(ContentSuggestionsServiceTest,
base::RunLoop run_loop;
std::string suggestion_id = "TestID";
EXPECT_CALL(*this, OnImageFetched(suggestion_id,
Property(&gfx::Image::IsEmpty, Eq(true))))
EXPECT_CALL(*this, OnImageFetched(Property(&gfx::Image::IsEmpty, Eq(true))))
.WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
service()->FetchSuggestionImage(
suggestion_id, base::Bind(&ContentSuggestionsServiceTest::OnImageFetched,
......
......@@ -700,7 +700,7 @@ void NTPSnippetsService::OnSnippetImageDecodedFromDatabase(
const std::string& snippet_id,
const gfx::Image& image) {
if (!image.IsEmpty()) {
callback.Run(MakeUniqueID(provided_category_, snippet_id), image);
callback.Run(image);
return;
}
......@@ -747,7 +747,7 @@ void NTPSnippetsService::OnSnippetImageDecodedFromNetwork(
const ImageFetchedCallback& callback,
const std::string& snippet_id,
const gfx::Image& image) {
callback.Run(MakeUniqueID(provided_category_, snippet_id), image);
callback.Run(image);
}
void NTPSnippetsService::EnterStateEnabled(bool fetch_snippets) {
......
......@@ -948,15 +948,12 @@ TEST_F(NTPSnippetsServiceTest, ImageReturnedWithTheSameId) {
gfx::Image image;
EXPECT_CALL(*image_fetcher(), StartOrQueueNetworkRequest(_, _, _))
.WillOnce(testing::WithArgs<0, 2>(Invoke(ServeOneByOneImage)));
testing::MockFunction<void(const std::string&, const gfx::Image&)>
image_fetched;
EXPECT_CALL(image_fetched, Call(MakeUniqueID(kSnippetUrl), _))
.WillOnce(testing::SaveArg<1>(&image));
testing::MockFunction<void(const gfx::Image&)> image_fetched;
EXPECT_CALL(image_fetched, Call(_)).WillOnce(testing::SaveArg<0>(&image));
service()->FetchSuggestionImage(
MakeUniqueID(kSnippetUrl),
base::Bind(&testing::MockFunction<void(const std::string&,
const gfx::Image&)>::Call,
base::Bind(&testing::MockFunction<void(const gfx::Image&)>::Call,
base::Unretained(&image_fetched)));
base::RunLoop().RunUntilIdle();
// Check that the image by ServeOneByOneImage is really served.
......@@ -966,16 +963,12 @@ TEST_F(NTPSnippetsServiceTest, ImageReturnedWithTheSameId) {
TEST_F(NTPSnippetsServiceTest, EmptyImageReturnedForNonExistentId) {
// Create a non-empty image so that we can test the image gets updated.
gfx::Image image = gfx::test::CreateImage(1, 1);
testing::MockFunction<void(const std::string&, const gfx::Image&)>
image_fetched;
EXPECT_CALL(image_fetched,
Call(MakeUniqueID(kSnippetUrl2), _))
.WillOnce(testing::SaveArg<1>(&image));
testing::MockFunction<void(const gfx::Image&)> image_fetched;
EXPECT_CALL(image_fetched, Call(_)).WillOnce(testing::SaveArg<0>(&image));
service()->FetchSuggestionImage(
MakeUniqueID(kSnippetUrl2),
base::Bind(&testing::MockFunction<void(const std::string&,
const gfx::Image&)>::Call,
base::Bind(&testing::MockFunction<void(const gfx::Image&)>::Call,
base::Unretained(&image_fetched)));
base::RunLoop().RunUntilIdle();
......
......@@ -147,7 +147,7 @@ void OfflinePageSuggestionsProvider::FetchSuggestionImage(
// TODO(pke): Fetch proper thumbnail from OfflinePageModel once it's available
// there.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, suggestion_id, gfx::Image()));
FROM_HERE, base::Bind(callback, gfx::Image()));
}
void OfflinePageSuggestionsProvider::ClearCachedSuggestions(Category category) {
......
......@@ -8,6 +8,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ui/gfx/image/image.h"
namespace ntp_snippets {
......@@ -80,6 +82,8 @@ void PhysicalWebPageSuggestionsProvider::DismissSuggestion(
void PhysicalWebPageSuggestionsProvider::FetchSuggestionImage(
const std::string& suggestion_id, const ImageFetchedCallback& callback) {
// TODO(vitaliii): Implement.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(callback, gfx::Image()));
}
void PhysicalWebPageSuggestionsProvider::ClearCachedSuggestions(
......
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