Commit da47f994 authored by markusheintz's avatar markusheintz Committed by Commit bot

Add ios_image_decoder_impl.* and pass an instance to the NTPSnippetsService...

Add ios_image_decoder_impl.* and pass an instance to the NTPSnippetsService when it is instantiated on iOS.

BUG=609127

Review-Url: https://codereview.chromium.org/2111573002
Cr-Commit-Position: refs/heads/master@{#403198}
parent 125c85c4
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#define COMPONENTS_IMAGE_FETCHER_IMAGE_DECODER_H_ #define COMPONENTS_IMAGE_FETCHER_IMAGE_DECODER_H_
#include <string> #include <string>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h"
namespace gfx { namespace gfx {
class Image; class Image;
......
...@@ -586,7 +586,7 @@ void NTPSnippetsService::OnSnippetImageFetchedFromDatabase( ...@@ -586,7 +586,7 @@ void NTPSnippetsService::OnSnippetImageFetchedFromDatabase(
const std::string& snippet_id, const std::string& snippet_id,
const ImageFetchedCallback& callback, const ImageFetchedCallback& callback,
std::string data) { std::string data) {
// |image_decoder_| is null on iOS and in tests. // |image_decoder_| is null in tests.
if (image_decoder_ && !data.empty()) { if (image_decoder_ && !data.empty()) {
image_decoder_->DecodeImage( image_decoder_->DecodeImage(
std::move(data), std::move(data),
......
...@@ -408,6 +408,8 @@ source_set("browser") { ...@@ -408,6 +408,8 @@ source_set("browser") {
"ssl/ios_ssl_blocking_page.mm", "ssl/ios_ssl_blocking_page.mm",
"suggestions/image_fetcher_impl.h", "suggestions/image_fetcher_impl.h",
"suggestions/image_fetcher_impl.mm", "suggestions/image_fetcher_impl.mm",
"suggestions/ios_image_decoder_impl.h",
"suggestions/ios_image_decoder_impl.mm",
"suggestions/suggestions_service_factory.h", "suggestions/suggestions_service_factory.h",
"suggestions/suggestions_service_factory.mm", "suggestions/suggestions_service_factory.mm",
"sync/glue/sync_start_util.cc", "sync/glue/sync_start_util.cc",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ios/chrome/browser/signin/oauth2_token_service_factory.h" #include "ios/chrome/browser/signin/oauth2_token_service_factory.h"
#include "ios/chrome/browser/signin/signin_manager_factory.h" #include "ios/chrome/browser/signin/signin_manager_factory.h"
#include "ios/chrome/browser/suggestions/image_fetcher_impl.h" #include "ios/chrome/browser/suggestions/image_fetcher_impl.h"
#include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
#include "ios/chrome/browser/suggestions/suggestions_service_factory.h" #include "ios/chrome/browser/suggestions/suggestions_service_factory.h"
#include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
#include "ios/chrome/common/channel_info.h" #include "ios/chrome/common/channel_info.h"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
using suggestions::ImageFetcherImpl; using suggestions::ImageFetcherImpl;
using suggestions::IOSImageDecoderImpl;
using suggestions::SuggestionsService; using suggestions::SuggestionsService;
using suggestions::SuggestionsServiceFactory; using suggestions::SuggestionsServiceFactory;
...@@ -122,7 +124,7 @@ IOSChromeNTPSnippetsServiceFactory::BuildServiceInstanceFor( ...@@ -122,7 +124,7 @@ IOSChromeNTPSnippetsServiceFactory::BuildServiceInstanceFor(
GetChannel() == version_info::Channel::STABLE)), GetChannel() == version_info::Channel::STABLE)),
base::WrapUnique(new ImageFetcherImpl(request_context.get(), base::WrapUnique(new ImageFetcherImpl(request_context.get(),
web::WebThread::GetBlockingPool())), web::WebThread::GetBlockingPool())),
nullptr, /* image_decoder */ base::MakeUnique<IOSImageDecoderImpl>(),
base::WrapUnique( base::WrapUnique(
new ntp_snippets::NTPSnippetsDatabase(database_dir, task_runner)), new ntp_snippets::NTPSnippetsDatabase(database_dir, task_runner)),
base::WrapUnique(new ntp_snippets::NTPSnippetsStatusService( base::WrapUnique(new ntp_snippets::NTPSnippetsStatusService(
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_SUGGESTIONS_IOS_IMAGE_DECODER_IMPL_H_
#define IOS_CHROME_BROWSER_SUGGESTIONS_IOS_IMAGE_DECODER_IMPL_H_
#include "base/macros.h"
#include "components/image_fetcher/image_decoder.h"
namespace suggestions {
class IOSImageDecoderImpl : public image_fetcher::ImageDecoder {
public:
IOSImageDecoderImpl();
~IOSImageDecoderImpl() override;
void DecodeImage(
const std::string& image_data,
const image_fetcher::ImageDecodedCallback& callback) override;
private:
DISALLOW_COPY_AND_ASSIGN(IOSImageDecoderImpl);
};
} // namespace suggestions
#endif // IOS_CHROME_BROWSER_SUGGESTIONS_IOS_IMAGE_DECODER_IMPL_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/suggestions/ios_image_decoder_impl.h"
#include <UIKit/UIKit.h>
#include "base/callback.h"
#include "ui/gfx/image/image.h"
namespace suggestions {
IOSImageDecoderImpl::IOSImageDecoderImpl() {}
IOSImageDecoderImpl::~IOSImageDecoderImpl() {}
void IOSImageDecoderImpl::DecodeImage(
const std::string& image_data,
const image_fetcher::ImageDecodedCallback& callback) {
// Convert the |image_data| std::string to a NSData buffer.
NSData* data =
[NSData dataWithBytesNoCopy:const_cast<char*>(image_data.c_str())
length:image_data.length()
freeWhenDone:NO];
// Decode the Image using UIImage.
if (data) {
// Most likely always returns 1x images.
UIImage* ui_image = [UIImage imageWithData:data scale:1];
if (ui_image) {
gfx::Image gfx_image(ui_image);
callback.Run(gfx_image);
return;
}
}
gfx::Image empty_image;
callback.Run(empty_image);
}
} // namespace suggestions
...@@ -545,6 +545,8 @@ ...@@ -545,6 +545,8 @@
'browser/ssl/ios_ssl_blocking_page.mm', 'browser/ssl/ios_ssl_blocking_page.mm',
'browser/suggestions/image_fetcher_impl.h', 'browser/suggestions/image_fetcher_impl.h',
'browser/suggestions/image_fetcher_impl.mm', 'browser/suggestions/image_fetcher_impl.mm',
'browser/suggestions/ios_image_decoder_impl.h',
'browser/suggestions/ios_image_decoder_impl.mm',
'browser/suggestions/suggestions_service_factory.h', 'browser/suggestions/suggestions_service_factory.h',
'browser/suggestions/suggestions_service_factory.mm', 'browser/suggestions/suggestions_service_factory.mm',
'browser/sync/glue/sync_start_util.cc', 'browser/sync/glue/sync_start_util.cc',
......
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