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