| Index: chrome/utility/chrome_content_utility_client.cc
|
| diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
|
| index 5d5dbfd7c30f8d6393af652fce1daff4e98a6e95..b0113c0943f0231fbc6d21b5f71c5f8de0857a40 100644
|
| --- a/chrome/utility/chrome_content_utility_client.cc
|
| +++ b/chrome/utility/chrome_content_utility_client.cc
|
| @@ -21,6 +21,7 @@
|
| #include "courgette/courgette.h"
|
| #include "courgette/third_party/bsdiff.h"
|
| #include "ipc/ipc_channel.h"
|
| +#include "services/image_decoder/image_decoder_impl.h"
|
| #include "skia/ext/image_operations.h"
|
| #include "third_party/skia/include/core/SkBitmap.h"
|
| #include "third_party/zlib/google/zip.h"
|
| @@ -89,13 +90,39 @@ void CreateProxyResolverFactory(
|
| }
|
| #endif // OS_ANDROID
|
|
|
| +// A simple Mojo service wrapper that reference counts this utility process.
|
| +template <class Impl, class Request>
|
| +class RefCountingMojoService : public Impl {
|
| + public:
|
| + RefCountingMojoService(ChromeContentUtilityClient* utility_client,
|
| + Request req)
|
| + : Impl(req.Pass()), utility_client_(utility_client) {
|
| + DCHECK(utility_client);
|
| + utility_client_->MojoRef();
|
| + }
|
| + ~RefCountingMojoService() override { utility_client_->MojoUnref(); }
|
| +
|
| + private:
|
| + ChromeContentUtilityClient* utility_client_;
|
| +};
|
| +
|
| +template <class Interface, class Impl>
|
| +void CreateMojoService(ChromeContentUtilityClient* utility_client,
|
| + mojo::InterfaceRequest<Interface> request) {
|
| + // The Mojo service implementation is assumed to use a StrongBinding<>, which
|
| + // causes the implementation to be deleted automatically when the Mojo
|
| + // connection is closed.
|
| + new RefCountingMojoService<Impl, mojo::InterfaceRequest<Interface>>(
|
| + utility_client, request.Pass());
|
| +}
|
| +
|
| } // namespace
|
|
|
| int64_t ChromeContentUtilityClient::max_ipc_message_size_ =
|
| IPC::Channel::kMaximumMessageSize;
|
|
|
| ChromeContentUtilityClient::ChromeContentUtilityClient()
|
| - : filter_messages_(false) {
|
| + : filter_messages_(false), mojo_service_ref_count_(0) {
|
| #if !defined(OS_ANDROID)
|
| handlers_.push_back(new ProfileImportHandler());
|
| #endif
|
| @@ -188,6 +215,22 @@ void ChromeContentUtilityClient::RegisterMojoServices(
|
| registry->AddService<net::interfaces::ProxyResolverFactory>(
|
| base::Bind(CreateProxyResolverFactory));
|
| #endif
|
| + registry->AddService<services::ImageDecoder>(base::Bind(
|
| + CreateMojoService<services::ImageDecoder, services::ImageDecoderImpl>,
|
| + this));
|
| +}
|
| +
|
| +void ChromeContentUtilityClient::MojoRef() {
|
| + mojo_service_ref_count_++;
|
| + DCHECK_GT(mojo_service_ref_count_, 0);
|
| +}
|
| +
|
| +void ChromeContentUtilityClient::MojoUnref() {
|
| + DCHECK_GT(mojo_service_ref_count_, 0);
|
| + mojo_service_ref_count_--;
|
| + if (mojo_service_ref_count_ <= 0) {
|
| + ReleaseProcessIfNeeded();
|
| + }
|
| }
|
|
|
| // static
|
|
|