OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/utility/chrome_content_utility_client.h" | 5 #include "chrome/utility/chrome_content_utility_client.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/common/chrome_utility_messages.h" | 12 #include "chrome/common/chrome_utility_messages.h" |
13 #include "chrome/common/safe_browsing/zip_analyzer.h" | 13 #include "chrome/common/safe_browsing/zip_analyzer.h" |
14 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" | 14 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" |
15 #include "chrome/utility/utility_message_handler.h" | 15 #include "chrome/utility/utility_message_handler.h" |
16 #include "content/public/child/image_decoder_utils.h" | 16 #include "content/public/child/image_decoder_utils.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 #include "content/public/common/service_registry.h" | 18 #include "content/public/common/service_registry.h" |
19 #include "content/public/utility/utility_thread.h" | 19 #include "content/public/utility/utility_thread.h" |
20 #include "courgette/courgette.h" | 20 #include "courgette/courgette.h" |
21 #include "courgette/third_party/bsdiff.h" | 21 #include "courgette/third_party/bsdiff.h" |
22 #include "ipc/ipc_channel.h" | 22 #include "ipc/ipc_channel.h" |
| 23 #include "services/image_decoder/image_decoder_impl.h" |
23 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
25 #include "third_party/zlib/google/zip.h" | 26 #include "third_party/zlib/google/zip.h" |
26 #include "ui/gfx/codec/jpeg_codec.h" | 27 #include "ui/gfx/codec/jpeg_codec.h" |
27 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
28 | 29 |
29 #if !defined(OS_ANDROID) | 30 #if !defined(OS_ANDROID) |
30 #include "chrome/utility/profile_import_handler.h" | 31 #include "chrome/utility/profile_import_handler.h" |
31 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" | 32 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" |
32 #endif | 33 #endif |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 void CreateProxyResolverFactory( | 78 void CreateProxyResolverFactory( |
78 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) { | 79 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) { |
79 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it | 80 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it |
80 // is connected to. When that message pipe is closed, either explicitly on the | 81 // is connected to. When that message pipe is closed, either explicitly on the |
81 // other end (in the browser process), or by a connection error, this object | 82 // other end (in the browser process), or by a connection error, this object |
82 // will be destroyed. | 83 // will be destroyed. |
83 new net::MojoProxyResolverFactoryImpl(request.Pass()); | 84 new net::MojoProxyResolverFactoryImpl(request.Pass()); |
84 } | 85 } |
85 #endif // OS_ANDROID | 86 #endif // OS_ANDROID |
86 | 87 |
| 88 // A simple Mojo service wrapper that reference counts this utility process. |
| 89 template <class Impl, class Request> |
| 90 class RefCountingMojoService : public Impl { |
| 91 public: |
| 92 RefCountingMojoService(ChromeContentUtilityClient* utility_client, |
| 93 Request req) |
| 94 : Impl(req.Pass()), |
| 95 utility_client_(utility_client) { |
| 96 DCHECK(utility_client); |
| 97 utility_client_->MojoRef(); |
| 98 } |
| 99 ~RefCountingMojoService() override { |
| 100 utility_client_->MojoUnref(); |
| 101 } |
| 102 |
| 103 private: |
| 104 ChromeContentUtilityClient* utility_client_; |
| 105 }; |
| 106 |
| 107 template <class Interface, class Impl> |
| 108 void CreateMojoService(ChromeContentUtilityClient* utility_client, |
| 109 mojo::InterfaceRequest<Interface> request) { |
| 110 // The Mojo service implementation is assumed to use a StrongBinding<>, which |
| 111 // causes the implementation to be deleted automatically when the Mojo |
| 112 // connection is closed. |
| 113 new RefCountingMojoService<Impl, mojo::InterfaceRequest<Interface>>( |
| 114 utility_client, request.Pass()); |
| 115 } |
| 116 |
87 } // namespace | 117 } // namespace |
88 | 118 |
89 int64_t ChromeContentUtilityClient::max_ipc_message_size_ = | 119 int64_t ChromeContentUtilityClient::max_ipc_message_size_ = |
90 IPC::Channel::kMaximumMessageSize; | 120 IPC::Channel::kMaximumMessageSize; |
91 | 121 |
92 ChromeContentUtilityClient::ChromeContentUtilityClient() | 122 ChromeContentUtilityClient::ChromeContentUtilityClient() |
93 : filter_messages_(false) { | 123 : filter_messages_(false), |
| 124 mojo_service_ref_count_(0) { |
94 #if !defined(OS_ANDROID) | 125 #if !defined(OS_ANDROID) |
95 handlers_.push_back(new ProfileImportHandler()); | 126 handlers_.push_back(new ProfileImportHandler()); |
96 #endif | 127 #endif |
97 | 128 |
98 #if defined(ENABLE_EXTENSIONS) | 129 #if defined(ENABLE_EXTENSIONS) |
99 handlers_.push_back(new extensions::ExtensionsHandler()); | 130 handlers_.push_back(new extensions::ExtensionsHandler()); |
100 handlers_.push_back(new image_writer::ImageWriterHandler()); | 131 handlers_.push_back(new image_writer::ImageWriterHandler()); |
101 #endif | 132 #endif |
102 | 133 |
103 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) | 134 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 203 |
173 return handled; | 204 return handled; |
174 } | 205 } |
175 | 206 |
176 void ChromeContentUtilityClient::RegisterMojoServices( | 207 void ChromeContentUtilityClient::RegisterMojoServices( |
177 content::ServiceRegistry* registry) { | 208 content::ServiceRegistry* registry) { |
178 #if !defined(OS_ANDROID) | 209 #if !defined(OS_ANDROID) |
179 registry->AddService<net::interfaces::ProxyResolverFactory>( | 210 registry->AddService<net::interfaces::ProxyResolverFactory>( |
180 base::Bind(CreateProxyResolverFactory)); | 211 base::Bind(CreateProxyResolverFactory)); |
181 #endif | 212 #endif |
| 213 registry->AddService<services::image_decoder::ImageDecoder>( |
| 214 base::Bind( |
| 215 CreateMojoService<services::image_decoder::ImageDecoder, |
| 216 services::image_decoder::ImageDecoderImpl>, |
| 217 this)); |
| 218 } |
| 219 |
| 220 void ChromeContentUtilityClient::MojoRef() { |
| 221 LOG(INFO) << "ChromeContentUtilityClient::MojoRef"; |
| 222 mojo_service_ref_count_++; |
| 223 DCHECK_GT(mojo_service_ref_count_, 0); |
| 224 } |
| 225 |
| 226 void ChromeContentUtilityClient::MojoUnref() { |
| 227 LOG(INFO) << "ChromeContentUtilityClient::MojoUnref"; |
| 228 DCHECK_GT(mojo_service_ref_count_, 0); |
| 229 mojo_service_ref_count_--; |
| 230 if (mojo_service_ref_count_ <= 0) { |
| 231 LOG(INFO) << "Releasing Mojo process"; |
| 232 ReleaseProcessIfNeeded(); |
| 233 } |
182 } | 234 } |
183 | 235 |
184 // static | 236 // static |
185 void ChromeContentUtilityClient::PreSandboxStartup() { | 237 void ChromeContentUtilityClient::PreSandboxStartup() { |
186 #if defined(ENABLE_EXTENSIONS) | 238 #if defined(ENABLE_EXTENSIONS) |
187 extensions::ExtensionsHandler::PreSandboxStartup(); | 239 extensions::ExtensionsHandler::PreSandboxStartup(); |
188 #endif | 240 #endif |
189 | 241 |
190 #if defined(ENABLE_MDNS) | 242 #if defined(ENABLE_MDNS) |
191 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 243 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 417 const std::string& mime_type, int64 total_size, bool get_attached_images) { |
366 // Only one IPCDataSource may be created and added to the list of handlers. | 418 // Only one IPCDataSource may be created and added to the list of handlers. |
367 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 419 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
368 handlers_.push_back(source); | 420 handlers_.push_back(source); |
369 | 421 |
370 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 422 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
371 source, mime_type, get_attached_images); | 423 source, mime_type, get_attached_images); |
372 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 424 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
373 } | 425 } |
374 #endif | 426 #endif |
OLD | NEW |