Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: chrome/utility/chrome_content_utility_client.cc

Issue 1028543002: Turn the utility process image decoder into a Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up and add test. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/safe_browsing/zip_analyzer_results.h" 14 #include "chrome/common/safe_browsing/zip_analyzer_results.h"
15 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h" 15 #include "chrome/utility/chrome_content_utility_ipc_whitelist.h"
16 #include "chrome/utility/utility_message_handler.h" 16 #include "chrome/utility/utility_message_handler.h"
17 #include "content/public/child/image_decoder_utils.h" 17 #include "content/public/child/image_decoder_utils.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "content/public/common/service_registry.h" 19 #include "content/public/common/service_registry.h"
20 #include "content/public/utility/utility_thread.h" 20 #include "content/public/utility/utility_thread.h"
21 #include "courgette/courgette.h" 21 #include "courgette/courgette.h"
22 #include "courgette/third_party/bsdiff.h" 22 #include "courgette/third_party/bsdiff.h"
23 #include "ipc/ipc_channel.h" 23 #include "ipc/ipc_channel.h"
24 #include "services/image_decoder/image_decoder_impl.h"
24 #include "skia/ext/image_operations.h" 25 #include "skia/ext/image_operations.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/zlib/google/zip.h" 27 #include "third_party/zlib/google/zip.h"
27 #include "ui/gfx/codec/jpeg_codec.h" 28 #include "ui/gfx/codec/jpeg_codec.h"
28 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
29 30
30 #if !defined(OS_ANDROID) 31 #if !defined(OS_ANDROID)
31 #include "chrome/utility/profile_import_handler.h" 32 #include "chrome/utility/profile_import_handler.h"
32 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" 33 #include "net/proxy/mojo_proxy_resolver_factory_impl.h"
33 #endif 34 #endif
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void CreateProxyResolverFactory( 83 void CreateProxyResolverFactory(
83 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) { 84 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) {
84 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it 85 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it
85 // is connected to. When that message pipe is closed, either explicitly on the 86 // is connected to. When that message pipe is closed, either explicitly on the
86 // other end (in the browser process), or by a connection error, this object 87 // other end (in the browser process), or by a connection error, this object
87 // will be destroyed. 88 // will be destroyed.
88 new net::MojoProxyResolverFactoryImpl(request.Pass()); 89 new net::MojoProxyResolverFactoryImpl(request.Pass());
89 } 90 }
90 #endif // OS_ANDROID 91 #endif // OS_ANDROID
91 92
93 // A simple Mojo service wrapper that reference counts this utility process.
94 template <class Impl, class Request>
95 class RefCountingMojoService : public Impl {
96 public:
97 RefCountingMojoService(ChromeContentUtilityClient* utility_client,
98 Request req)
99 : Impl(req.Pass()), utility_client_(utility_client) {
100 DCHECK(utility_client);
101 utility_client_->MojoRef();
102 }
103 ~RefCountingMojoService() override { utility_client_->MojoUnref(); }
104
105 private:
106 ChromeContentUtilityClient* utility_client_;
107 };
108
109 template <class Interface, class Impl>
110 void CreateMojoService(ChromeContentUtilityClient* utility_client,
111 mojo::InterfaceRequest<Interface> request) {
112 // The Mojo service implementation is assumed to use a StrongBinding<>, which
113 // causes the implementation to be deleted automatically when the Mojo
114 // connection is closed.
115 new RefCountingMojoService<Impl, mojo::InterfaceRequest<Interface>>(
116 utility_client, request.Pass());
117 }
118
92 } // namespace 119 } // namespace
93 120
94 int64_t ChromeContentUtilityClient::max_ipc_message_size_ = 121 int64_t ChromeContentUtilityClient::max_ipc_message_size_ =
95 IPC::Channel::kMaximumMessageSize; 122 IPC::Channel::kMaximumMessageSize;
96 123
97 ChromeContentUtilityClient::ChromeContentUtilityClient() 124 ChromeContentUtilityClient::ChromeContentUtilityClient()
98 : filter_messages_(false) { 125 : filter_messages_(false), mojo_service_ref_count_(0) {
99 #if !defined(OS_ANDROID) 126 #if !defined(OS_ANDROID)
100 handlers_.push_back(new ProfileImportHandler()); 127 handlers_.push_back(new ProfileImportHandler());
101 #endif 128 #endif
102 129
103 #if defined(ENABLE_EXTENSIONS) 130 #if defined(ENABLE_EXTENSIONS)
104 handlers_.push_back(new extensions::ExtensionsHandler()); 131 handlers_.push_back(new extensions::ExtensionsHandler());
105 handlers_.push_back(new image_writer::ImageWriterHandler()); 132 handlers_.push_back(new image_writer::ImageWriterHandler());
106 #endif 133 #endif
107 134
108 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN) 135 #if defined(ENABLE_PRINT_PREVIEW) || defined(OS_WIN)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 208
182 return handled; 209 return handled;
183 } 210 }
184 211
185 void ChromeContentUtilityClient::RegisterMojoServices( 212 void ChromeContentUtilityClient::RegisterMojoServices(
186 content::ServiceRegistry* registry) { 213 content::ServiceRegistry* registry) {
187 #if !defined(OS_ANDROID) 214 #if !defined(OS_ANDROID)
188 registry->AddService<net::interfaces::ProxyResolverFactory>( 215 registry->AddService<net::interfaces::ProxyResolverFactory>(
189 base::Bind(CreateProxyResolverFactory)); 216 base::Bind(CreateProxyResolverFactory));
190 #endif 217 #endif
218 registry->AddService<services::ImageDecoder>(base::Bind(
219 CreateMojoService<services::ImageDecoder, services::ImageDecoderImpl>,
220 this));
221 }
222
223 void ChromeContentUtilityClient::MojoRef() {
224 mojo_service_ref_count_++;
225 DCHECK_GT(mojo_service_ref_count_, 0);
226 }
227
228 void ChromeContentUtilityClient::MojoUnref() {
229 DCHECK_GT(mojo_service_ref_count_, 0);
230 mojo_service_ref_count_--;
231 if (mojo_service_ref_count_ <= 0) {
232 ReleaseProcessIfNeeded();
233 }
191 } 234 }
192 235
193 // static 236 // static
194 void ChromeContentUtilityClient::PreSandboxStartup() { 237 void ChromeContentUtilityClient::PreSandboxStartup() {
195 #if defined(ENABLE_EXTENSIONS) 238 #if defined(ENABLE_EXTENSIONS)
196 extensions::ExtensionsHandler::PreSandboxStartup(); 239 extensions::ExtensionsHandler::PreSandboxStartup();
197 #endif 240 #endif
198 241
199 #if defined(ENABLE_MDNS) 242 #if defined(ENABLE_MDNS)
200 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 243 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 const std::string& mime_type, int64 total_size, bool get_attached_images) { 435 const std::string& mime_type, int64 total_size, bool get_attached_images) {
393 // Only one IPCDataSource may be created and added to the list of handlers. 436 // Only one IPCDataSource may be created and added to the list of handlers.
394 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); 437 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size);
395 handlers_.push_back(source); 438 handlers_.push_back(source);
396 439
397 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( 440 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser(
398 source, mime_type, get_attached_images); 441 source, mime_type, get_attached_images);
399 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); 442 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser)));
400 } 443 }
401 #endif 444 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698