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 d82c23bf5479e1b7cf85f27b64a0953c7d635c47..4e1058afef5e0d240af30a3e34e3a716c56bc009 100644 |
--- a/chrome/utility/chrome_content_utility_client.cc |
+++ b/chrome/utility/chrome_content_utility_client.cc |
@@ -20,6 +20,7 @@ |
#include "courgette/courgette.h" |
#include "courgette/third_party/bsdiff.h" |
#include "ipc/ipc_channel.h" |
+#include "services/image_decoder/services/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" |
@@ -84,13 +85,43 @@ 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 |
@@ -179,6 +210,27 @@ void ChromeContentUtilityClient::RegisterMojoServices( |
registry->AddService<net::interfaces::ProxyResolverFactory>( |
base::Bind(CreateProxyResolverFactory)); |
#endif |
+ registry->AddService<services::image_decoder::ImageDecoder>( |
+ base::Bind( |
+ CreateMojoService<services::image_decoder::ImageDecoder, |
+ services::image_decoder::ImageDecoderImpl>, |
+ this)); |
+} |
+ |
+void ChromeContentUtilityClient::MojoRef() { |
+ LOG(INFO) << "ChromeContentUtilityClient::MojoRef"; |
+ mojo_service_ref_count_++; |
+ DCHECK_GT(mojo_service_ref_count_, 0); |
+} |
+ |
+void ChromeContentUtilityClient::MojoUnref() { |
+ LOG(INFO) << "ChromeContentUtilityClient::MojoUnref"; |
+ DCHECK_GT(mojo_service_ref_count_, 0); |
+ mojo_service_ref_count_--; |
+ if (mojo_service_ref_count_ <= 0) { |
+ LOG(INFO) << "Releasing Mojo process"; |
+ ReleaseProcessIfNeeded(); |
+ } |
} |
// static |