Commit 81c11d04 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

ash: Launch Data Decoder without Service Manager

Ports ash usage of the Data Decoder service to use the service interface
directly rather than going through a Service Manager Connector.

Bug: 977637
Change-Id: I3cf24b34ab0eeff6665055b5add7fb1d90c591bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872918Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#708678}
parent 651418c8
...@@ -1352,6 +1352,7 @@ component("ash") { ...@@ -1352,6 +1352,7 @@ component("ash") {
"//components/discardable_memory/public/mojom", "//components/discardable_memory/public/mojom",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//services/data_decoder/public/mojom",
"//services/device/public/cpp/bluetooth", "//services/device/public/cpp/bluetooth",
"//services/device/public/mojom", "//services/device/public/mojom",
"//services/media_session/public/cpp", "//services/media_session/public/cpp",
......
...@@ -27,6 +27,7 @@ include_rules = [ ...@@ -27,6 +27,7 @@ include_rules = [
"+media", "+media",
"+mojo/public", "+mojo/public",
"+services/content/public", "+services/content/public",
"+services/data_decoder/public",
"+services/media_session/public", "+services/media_session/public",
"+services/preferences/public", "+services/preferences/public",
"+services/service_manager/public", "+services/service_manager/public",
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include <utility> #include <utility>
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "base/bind.h" #include "base/bind.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/cpp/decode_image.h" #include "services/data_decoder/public/cpp/decode_image.h"
namespace ash { namespace ash {
...@@ -40,9 +42,9 @@ void DecodeAnimation(const std::vector<uint8_t>& image_data, ...@@ -40,9 +42,9 @@ void DecodeAnimation(const std::vector<uint8_t>& image_data,
// also goes through libpng, but APNG support is handled specifically by // also goes through libpng, but APNG support is handled specifically by
// blink's PNGImageReader.cpp. // blink's PNGImageReader.cpp.
data_decoder::DecodeAnimation( data_decoder::DecodeAnimation(
Shell::Get()->connector(), image_data, true /*shrink_to_fit*/, Shell::Get()->shell_delegate()->LaunchDataDecoder(), image_data,
kMaxImageSizeInBytes, true /*shrink_to_fit*/, kMaxImageSizeInBytes,
base::Bind(&ConvertToAnimationFrame, Passed(&on_decoded))); base::BindOnce(&ConvertToAnimationFrame, std::move(on_decoded)));
} }
} // namespace ash } // namespace ash
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h" #include "chromeos/services/multidevice_setup/public/mojom/constants.mojom.h"
#include "services/content/public/mojom/constants.mojom.h" #include "services/content/public/mojom/constants.mojom.h"
#include "services/data_decoder/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/constants.mojom.h" #include "services/device/public/mojom/constants.mojom.h"
#include "services/preferences/public/mojom/preferences.mojom.h" #include "services/preferences/public/mojom/preferences.mojom.h"
#include "services/service_manager/public/cpp/manifest_builder.h" #include "services/service_manager/public/cpp/manifest_builder.h"
...@@ -43,7 +42,6 @@ const service_manager::Manifest& GetManifest() { ...@@ -43,7 +42,6 @@ const service_manager::Manifest& GetManifest() {
.RequireCapability("*", "accessibility") .RequireCapability("*", "accessibility")
.RequireCapability("*", "app") .RequireCapability("*", "app")
.RequireCapability(content::mojom::kServiceName, "navigation") .RequireCapability(content::mojom::kServiceName, "navigation")
.RequireCapability(data_decoder::mojom::kServiceName, "image_decoder")
.RequireCapability(device::mojom::kServiceName, .RequireCapability(device::mojom::kServiceName,
"device:bluetooth_system") "device:bluetooth_system")
.RequireCapability(device::mojom::kServiceName, "device:fingerprint") .RequireCapability(device::mojom::kServiceName, "device:fingerprint")
......
...@@ -33,5 +33,12 @@ bool ShellDelegateImpl::CanGoBack(gfx::NativeWindow window) const { ...@@ -33,5 +33,12 @@ bool ShellDelegateImpl::CanGoBack(gfx::NativeWindow window) const {
return true; return true;
} }
mojo::Remote<data_decoder::mojom::DataDecoderService>
ShellDelegateImpl::LaunchDataDecoder() {
mojo::Remote<data_decoder::mojom::DataDecoderService> remote;
ignore_result(remote.BindNewPipeAndPassReceiver());
return remote;
}
} // namespace shell } // namespace shell
} // namespace ash } // namespace ash
...@@ -24,6 +24,8 @@ class ShellDelegateImpl : public ShellDelegate { ...@@ -24,6 +24,8 @@ class ShellDelegateImpl : public ShellDelegate {
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override; std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override; AccessibilityDelegate* CreateAccessibilityDelegate() override;
bool CanGoBack(gfx::NativeWindow window) const override; bool CanGoBack(gfx::NativeWindow window) const override;
mojo::Remote<data_decoder::mojom::DataDecoderService> LaunchDataDecoder()
override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl); DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/mojom/data_decoder_service.mojom.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace aura { namespace aura {
...@@ -42,6 +44,12 @@ class ASH_EXPORT ShellDelegate { ...@@ -42,6 +44,12 @@ class ASH_EXPORT ShellDelegate {
virtual bool CanGoBack(gfx::NativeWindow window) const = 0; virtual bool CanGoBack(gfx::NativeWindow window) const = 0;
virtual void OpenKeyboardShortcutHelpPage() const {} virtual void OpenKeyboardShortcutHelpPage() const {}
// Launches an instance of the Data Decoder service and returns a remote
// endpoint to communicate with it. In testing environments, this may return
// a disconnected Remote.
virtual mojo::Remote<data_decoder::mojom::DataDecoderService>
LaunchDataDecoder() = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -33,4 +33,11 @@ bool TestShellDelegate::CanGoBack(gfx::NativeWindow window) const { ...@@ -33,4 +33,11 @@ bool TestShellDelegate::CanGoBack(gfx::NativeWindow window) const {
return true; return true;
} }
mojo::Remote<data_decoder::mojom::DataDecoderService>
TestShellDelegate::LaunchDataDecoder() {
mojo::Remote<data_decoder::mojom::DataDecoderService> remote;
ignore_result(remote.BindNewPipeAndPassReceiver());
return remote;
}
} // namespace ash } // namespace ash
...@@ -22,6 +22,8 @@ class TestShellDelegate : public ShellDelegate { ...@@ -22,6 +22,8 @@ class TestShellDelegate : public ShellDelegate {
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override; std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override; AccessibilityDelegate* CreateAccessibilityDelegate() override;
bool CanGoBack(gfx::NativeWindow window) const override; bool CanGoBack(gfx::NativeWindow window) const override;
mojo::Remote<data_decoder::mojom::DataDecoderService> LaunchDataDecoder()
override;
private: private:
DISALLOW_COPY_AND_ASSIGN(TestShellDelegate); DISALLOW_COPY_AND_ASSIGN(TestShellDelegate);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/wallpaper/wallpaper_utils/wallpaper_decoder.h" #include "ash/wallpaper/wallpaper_utils/wallpaper_decoder.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "base/bind.h" #include "base/bind.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
...@@ -32,16 +33,11 @@ void ConvertToImageSkia(OnWallpaperDecoded callback, const SkBitmap& image) { ...@@ -32,16 +33,11 @@ void ConvertToImageSkia(OnWallpaperDecoded callback, const SkBitmap& image) {
void DecodeWallpaper(const std::string& image_data, void DecodeWallpaper(const std::string& image_data,
const data_decoder::mojom::ImageCodec& image_codec, const data_decoder::mojom::ImageCodec& image_codec,
OnWallpaperDecoded callback) { OnWallpaperDecoded callback) {
// The connector for the mojo service manager is null in unit tests.
if (!Shell::Get()->connector()) {
std::move(callback).Run(gfx::ImageSkia());
return;
}
std::vector<uint8_t> image_bytes(image_data.begin(), image_data.end()); std::vector<uint8_t> image_bytes(image_data.begin(), image_data.end());
data_decoder::DecodeImage( data_decoder::DecodeImage(
Shell::Get()->connector(), std::move(image_bytes), image_codec, Shell::Get()->shell_delegate()->LaunchDataDecoder(),
/*shrink_to_fit=*/true, kMaxImageSizeInBytes, std::move(image_bytes), image_codec, /*shrink_to_fit=*/true,
/*desired_image_frame_size=*/gfx::Size(), kMaxImageSizeInBytes, /*desired_image_frame_size=*/gfx::Size(),
base::BindOnce(&ConvertToImageSkia, std::move(callback))); base::BindOnce(&ConvertToImageSkia, std::move(callback)));
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "content/public/browser/data_decoder_service.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -74,3 +75,8 @@ std::unique_ptr<ash::ScreenshotDelegate> ...@@ -74,3 +75,8 @@ std::unique_ptr<ash::ScreenshotDelegate>
ChromeShellDelegate::CreateScreenshotDelegate() { ChromeShellDelegate::CreateScreenshotDelegate() {
return std::make_unique<ChromeScreenshotGrabber>(); return std::make_unique<ChromeScreenshotGrabber>();
} }
mojo::Remote<data_decoder::mojom::DataDecoderService>
ChromeShellDelegate::LaunchDataDecoder() {
return content::LaunchDataDecoder();
}
...@@ -19,6 +19,8 @@ class ChromeShellDelegate : public ash::ShellDelegate { ...@@ -19,6 +19,8 @@ class ChromeShellDelegate : public ash::ShellDelegate {
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override; ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
void OpenKeyboardShortcutHelpPage() const override; void OpenKeyboardShortcutHelpPage() const override;
bool CanGoBack(gfx::NativeWindow window) const override; bool CanGoBack(gfx::NativeWindow window) const override;
mojo::Remote<data_decoder::mojom::DataDecoderService> LaunchDataDecoder()
override;
private: private:
DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate); DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate);
......
...@@ -20,13 +20,15 @@ namespace { ...@@ -20,13 +20,15 @@ namespace {
// Helper callback which owns a mojo::Remote<ImageDecoder> until invoked. This // Helper callback which owns a mojo::Remote<ImageDecoder> until invoked. This
// keeps the ImageDecoder pipe open just long enough to dispatch a reply, at // keeps the ImageDecoder pipe open just long enough to dispatch a reply, at
// which point the reply is forwarded to the wrapped |callback|. // which point the reply is forwarded to the wrapped |callback|.
void OnDecodeImage(mojo::Remote<mojom::ImageDecoder> decoder, void OnDecodeImage(mojo::Remote<mojom::DataDecoderService> service,
mojo::Remote<mojom::ImageDecoder> decoder,
mojom::ImageDecoder::DecodeImageCallback callback, mojom::ImageDecoder::DecodeImageCallback callback,
const SkBitmap& bitmap) { const SkBitmap& bitmap) {
std::move(callback).Run(bitmap); std::move(callback).Run(bitmap);
} }
void OnDecodeImages(mojo::Remote<mojom::ImageDecoder> decoder, void OnDecodeImages(mojo::Remote<mojom::DataDecoderService> service,
mojo::Remote<mojom::ImageDecoder> decoder,
mojom::ImageDecoder::DecodeAnimationCallback callback, mojom::ImageDecoder::DecodeAnimationCallback callback,
std::vector<mojom::AnimationFramePtr> bitmaps) { std::vector<mojom::AnimationFramePtr> bitmaps) {
std::move(callback).Run(std::move(bitmaps)); std::move(callback).Run(std::move(bitmaps));
...@@ -41,37 +43,95 @@ void DecodeImage(service_manager::Connector* connector, ...@@ -41,37 +43,95 @@ void DecodeImage(service_manager::Connector* connector,
uint64_t max_size_in_bytes, uint64_t max_size_in_bytes,
const gfx::Size& desired_image_frame_size, const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback) { mojom::ImageDecoder::DecodeImageCallback callback) {
mojo::PendingRemote<mojom::ImageDecoder> pending_decoder;
connector->Connect(mojom::kServiceName,
pending_decoder.InitWithNewPipeAndPassReceiver());
return DecodeImage(std::move(pending_decoder), encoded_bytes, codec,
shrink_to_fit, max_size_in_bytes, desired_image_frame_size,
std::move(callback));
}
void DecodeImage(mojo::PendingRemote<mojom::ImageDecoder> pending_decoder,
const std::vector<uint8_t>& encoded_bytes,
mojom::ImageCodec codec,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback) {
mojo::Remote<mojom::DataDecoderService> null_service;
mojo::Remote<mojom::ImageDecoder> decoder(std::move(pending_decoder));
// |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
decoder.set_disconnect_handler(base::BindOnce(call_once, SkBitmap()));
mojom::ImageDecoder* raw_decoder = decoder.get();
raw_decoder->DecodeImage(
encoded_bytes, codec, shrink_to_fit, max_size_in_bytes,
desired_image_frame_size,
base::BindOnce(&OnDecodeImage, std::move(null_service),
std::move(decoder), std::move(call_once)));
}
void DecodeImage(mojo::Remote<mojom::DataDecoderService> service,
const std::vector<uint8_t>& encoded_bytes,
mojom::ImageCodec codec,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback) {
mojo::Remote<mojom::ImageDecoder> decoder; mojo::Remote<mojom::ImageDecoder> decoder;
connector->Connect(mojom::kServiceName, decoder.BindNewPipeAndPassReceiver()); service->BindImageDecoder(decoder.BindNewPipeAndPassReceiver());
// |call_once| runs |callback| on its first invocation. // |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback)); auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
decoder.set_disconnect_handler(base::Bind(call_once, SkBitmap())); decoder.set_disconnect_handler(base::BindOnce(call_once, SkBitmap()));
mojom::ImageDecoder* raw_decoder = decoder.get(); mojom::ImageDecoder* raw_decoder = decoder.get();
raw_decoder->DecodeImage( raw_decoder->DecodeImage(
encoded_bytes, codec, shrink_to_fit, max_size_in_bytes, encoded_bytes, codec, shrink_to_fit, max_size_in_bytes,
desired_image_frame_size, desired_image_frame_size,
base::BindOnce(&OnDecodeImage, std::move(decoder), std::move(call_once))); base::BindOnce(&OnDecodeImage, std::move(service), std::move(decoder),
std::move(call_once)));
}
void DecodeAnimation(mojo::PendingRemote<mojom::ImageDecoder> pending_decoder,
const std::vector<uint8_t>& encoded_bytes,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
mojom::ImageDecoder::DecodeAnimationCallback callback) {
mojo::Remote<mojom::DataDecoderService> null_service;
mojo::Remote<mojom::ImageDecoder> decoder(std::move(pending_decoder));
// |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
decoder.set_disconnect_handler(base::BindOnce(
call_once, base::Passed(std::vector<mojom::AnimationFramePtr>())));
mojom::ImageDecoder* raw_decoder = decoder.get();
raw_decoder->DecodeAnimation(
encoded_bytes, shrink_to_fit, max_size_in_bytes,
base::BindOnce(&OnDecodeImages, std::move(null_service),
std::move(decoder), std::move(call_once)));
} }
void DecodeAnimation(service_manager::Connector* connector, void DecodeAnimation(mojo::Remote<mojom::DataDecoderService> service,
const std::vector<uint8_t>& encoded_bytes, const std::vector<uint8_t>& encoded_bytes,
bool shrink_to_fit, bool shrink_to_fit,
uint64_t max_size_in_bytes, uint64_t max_size_in_bytes,
mojom::ImageDecoder::DecodeAnimationCallback callback) { mojom::ImageDecoder::DecodeAnimationCallback callback) {
mojo::Remote<mojom::ImageDecoder> decoder; mojo::Remote<mojom::ImageDecoder> decoder;
connector->Connect(mojom::kServiceName, decoder.BindNewPipeAndPassReceiver()); service->BindImageDecoder(decoder.BindNewPipeAndPassReceiver());
// |call_once| runs |callback| on its first invocation. // |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback)); auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
decoder.set_disconnect_handler(base::Bind( decoder.set_disconnect_handler(base::BindOnce(
call_once, base::Passed(std::vector<mojom::AnimationFramePtr>()))); call_once, base::Passed(std::vector<mojom::AnimationFramePtr>())));
mojom::ImageDecoder* raw_decoder = decoder.get(); mojom::ImageDecoder* raw_decoder = decoder.get();
raw_decoder->DecodeAnimation( raw_decoder->DecodeAnimation(
encoded_bytes, shrink_to_fit, max_size_in_bytes, encoded_bytes, shrink_to_fit, max_size_in_bytes,
base::BindOnce(&OnDecodeImages, std::move(decoder), base::BindOnce(&OnDecodeImages, std::move(service), std::move(decoder),
std::move(call_once))); std::move(call_once)));
} }
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include <vector> #include <vector>
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/data_decoder/public/mojom/data_decoder_service.mojom.h"
#include "services/data_decoder/public/mojom/image_decoder.mojom.h" #include "services/data_decoder/public/mojom/image_decoder.mojom.h"
namespace gfx { namespace gfx {
...@@ -40,10 +43,38 @@ void DecodeImage(service_manager::Connector* connector, ...@@ -40,10 +43,38 @@ void DecodeImage(service_manager::Connector* connector,
const gfx::Size& desired_image_frame_size, const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback); mojom::ImageDecoder::DecodeImageCallback callback);
// Same as above but uses an ImageDecoder interface directly instead of going
// through the Service Manager.
void DecodeImage(mojo::PendingRemote<mojom::ImageDecoder> pending_decoder,
const std::vector<uint8_t>& encoded_bytes,
mojom::ImageCodec codec,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback);
// Same as above but uses a dedicated DataDecoderService instance for the
// operation.
void DecodeImage(mojo::Remote<mojom::DataDecoderService> service,
const std::vector<uint8_t>& encoded_bytes,
mojom::ImageCodec codec,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
const gfx::Size& desired_image_frame_size,
mojom::ImageDecoder::DecodeImageCallback callback);
// Helper function to decode an animation via the data_decoder service. Any // Helper function to decode an animation via the data_decoder service. Any
// image with multiple frames is considered an animation, so long as the frames // image with multiple frames is considered an animation, so long as the frames
// are all the same size. // are all the same size.
void DecodeAnimation(service_manager::Connector* connector, void DecodeAnimation(mojo::PendingRemote<mojom::ImageDecoder> pending_decoder,
const std::vector<uint8_t>& encoded_bytes,
bool shrink_to_fit,
uint64_t max_size_in_bytes,
mojom::ImageDecoder::DecodeAnimationCallback callback);
// Same as above but uses a dedicated DataDecoderService instance for the
// operation.
void DecodeAnimation(mojo::Remote<mojom::DataDecoderService> service,
const std::vector<uint8_t>& encoded_bytes, const std::vector<uint8_t>& encoded_bytes,
bool shrink_to_fit, bool shrink_to_fit,
uint64_t max_size_in_bytes, uint64_t max_size_in_bytes,
......
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