| 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/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 "components/image_decoder/image_decoder_impl.h" |
| 17 #include "content/public/child/image_decoder_utils.h" | 18 #include "content/public/child/image_decoder_utils.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/common/service_registry.h" | 20 #include "content/public/common/service_registry.h" |
| 20 #include "content/public/utility/utility_thread.h" | 21 #include "content/public/utility/utility_thread.h" |
| 21 #include "courgette/courgette.h" | 22 #include "courgette/courgette.h" |
| 22 #include "courgette/third_party/bsdiff.h" | 23 #include "courgette/third_party/bsdiff.h" |
| 23 #include "ipc/ipc_channel.h" | 24 #include "ipc/ipc_channel.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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 metadata::MediaMetadataParser* /* parser */, | 79 metadata::MediaMetadataParser* /* parser */, |
| 79 const extensions::api::media_galleries::MediaMetadata& metadata, | 80 const extensions::api::media_galleries::MediaMetadata& metadata, |
| 80 const std::vector<metadata::AttachedImage>& attached_images) { | 81 const std::vector<metadata::AttachedImage>& attached_images) { |
| 81 Send(new ChromeUtilityHostMsg_ParseMediaMetadata_Finished( | 82 Send(new ChromeUtilityHostMsg_ParseMediaMetadata_Finished( |
| 82 true, *metadata.ToValue(), attached_images)); | 83 true, *metadata.ToValue(), attached_images)); |
| 83 ReleaseProcessIfNeeded(); | 84 ReleaseProcessIfNeeded(); |
| 84 } | 85 } |
| 85 #endif | 86 #endif |
| 86 | 87 |
| 87 #if !defined(OS_ANDROID) | 88 #if !defined(OS_ANDROID) |
| 88 void CreateProxyResolverFactory( | |
| 89 mojo::InterfaceRequest<net::interfaces::ProxyResolverFactory> request) { | |
| 90 // MojoProxyResolverFactoryImpl is strongly bound to the Mojo message pipe it | |
| 91 // is connected to. When that message pipe is closed, either explicitly on the | |
| 92 // other end (in the browser process), or by a connection error, this object | |
| 93 // will be destroyed. | |
| 94 new net::MojoProxyResolverFactoryImpl(request.Pass()); | |
| 95 } | |
| 96 | 89 |
| 97 class ResourceUsageReporterImpl : public ResourceUsageReporter { | 90 class ResourceUsageReporterImpl : public ResourceUsageReporter { |
| 98 public: | 91 public: |
| 99 explicit ResourceUsageReporterImpl( | 92 explicit ResourceUsageReporterImpl( |
| 100 mojo::InterfaceRequest<ResourceUsageReporter> req) | 93 mojo::InterfaceRequest<ResourceUsageReporter> req) |
| 101 : binding_(this, req.Pass()) {} | 94 : binding_(this, req.Pass()) {} |
| 102 ~ResourceUsageReporterImpl() override {} | 95 ~ResourceUsageReporterImpl() override {} |
| 103 | 96 |
| 104 private: | 97 private: |
| 105 void GetUsageData( | 98 void GetUsageData( |
| 106 const mojo::Callback<void(ResourceUsageDataPtr)>& callback) override { | 99 const mojo::Callback<void(ResourceUsageDataPtr)>& callback) override { |
| 107 ResourceUsageDataPtr data = ResourceUsageData::New(); | 100 ResourceUsageDataPtr data = ResourceUsageData::New(); |
| 108 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize(); | 101 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize(); |
| 109 if (total_heap_size) { | 102 if (total_heap_size) { |
| 110 data->reports_v8_stats = true; | 103 data->reports_v8_stats = true; |
| 111 data->v8_bytes_allocated = total_heap_size; | 104 data->v8_bytes_allocated = total_heap_size; |
| 112 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize(); | 105 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize(); |
| 113 } | 106 } |
| 114 callback.Run(data.Pass()); | 107 callback.Run(data.Pass()); |
| 115 } | 108 } |
| 116 | 109 |
| 117 mojo::StrongBinding<ResourceUsageReporter> binding_; | 110 mojo::StrongBinding<ResourceUsageReporter> binding_; |
| 118 }; | 111 }; |
| 112 #endif // OS_ANDROID |
| 119 | 113 |
| 120 void CreateResourceUsageReporter( | 114 template <class Interface, class Impl> |
| 121 mojo::InterfaceRequest<ResourceUsageReporter> request) { | 115 void CreateMojoService(mojo::InterfaceRequest<Interface> request) { |
| 122 new ResourceUsageReporterImpl(request.Pass()); | 116 // The Mojo service implementation is assumed to use a StrongBinding<>, which |
| 117 // causes the implementation to be deleted automatically when the Mojo |
| 118 // connection is closed. |
| 119 new Impl(request.Pass()); |
| 123 } | 120 } |
| 124 #endif // OS_ANDROID | |
| 125 | 121 |
| 126 } // namespace | 122 } // namespace |
| 127 | 123 |
| 128 int64_t ChromeContentUtilityClient::max_ipc_message_size_ = | 124 int64_t ChromeContentUtilityClient::max_ipc_message_size_ = |
| 129 IPC::Channel::kMaximumMessageSize; | 125 IPC::Channel::kMaximumMessageSize; |
| 130 | 126 |
| 131 ChromeContentUtilityClient::ChromeContentUtilityClient() | 127 ChromeContentUtilityClient::ChromeContentUtilityClient() |
| 132 : filter_messages_(false) { | 128 : filter_messages_(false) { |
| 133 #if !defined(OS_ANDROID) | 129 #if !defined(OS_ANDROID) |
| 134 handlers_.push_back(new ProfileImportHandler()); | 130 handlers_.push_back(new ProfileImportHandler()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 handled = (*it)->OnMessageReceived(message); | 211 handled = (*it)->OnMessageReceived(message); |
| 216 } | 212 } |
| 217 | 213 |
| 218 return handled; | 214 return handled; |
| 219 } | 215 } |
| 220 | 216 |
| 221 void ChromeContentUtilityClient::RegisterMojoServices( | 217 void ChromeContentUtilityClient::RegisterMojoServices( |
| 222 content::ServiceRegistry* registry) { | 218 content::ServiceRegistry* registry) { |
| 223 #if !defined(OS_ANDROID) | 219 #if !defined(OS_ANDROID) |
| 224 registry->AddService<net::interfaces::ProxyResolverFactory>( | 220 registry->AddService<net::interfaces::ProxyResolverFactory>( |
| 225 base::Bind(CreateProxyResolverFactory)); | 221 base::Bind(CreateMojoService<net::interfaces::ProxyResolverFactory, |
| 222 net::MojoProxyResolverFactoryImpl>)); |
| 226 registry->AddService<ResourceUsageReporter>( | 223 registry->AddService<ResourceUsageReporter>( |
| 227 base::Bind(CreateResourceUsageReporter)); | 224 base::Bind(CreateMojoService<ResourceUsageReporter, |
| 225 ResourceUsageReporterImpl>)); |
| 228 #endif | 226 #endif |
| 227 registry->AddService<image_decoder::ImageDecoder>(base::Bind( |
| 228 CreateMojoService<image_decoder::ImageDecoder, |
| 229 image_decoder::ImageDecoderImpl>)); |
| 229 } | 230 } |
| 230 | 231 |
| 231 // static | 232 // static |
| 232 void ChromeContentUtilityClient::PreSandboxStartup() { | 233 void ChromeContentUtilityClient::PreSandboxStartup() { |
| 233 #if defined(ENABLE_EXTENSIONS) | 234 #if defined(ENABLE_EXTENSIONS) |
| 234 extensions::ExtensionsHandler::PreSandboxStartup(); | 235 extensions::ExtensionsHandler::PreSandboxStartup(); |
| 235 #endif | 236 #endif |
| 236 | 237 |
| 237 #if defined(ENABLE_MDNS) | 238 #if defined(ENABLE_MDNS) |
| 238 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 239 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 const std::string& mime_type, int64 total_size, bool get_attached_images) { | 442 const std::string& mime_type, int64 total_size, bool get_attached_images) { |
| 442 // Only one IPCDataSource may be created and added to the list of handlers. | 443 // Only one IPCDataSource may be created and added to the list of handlers. |
| 443 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); | 444 metadata::IPCDataSource* source = new metadata::IPCDataSource(total_size); |
| 444 handlers_.push_back(source); | 445 handlers_.push_back(source); |
| 445 | 446 |
| 446 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( | 447 metadata::MediaMetadataParser* parser = new metadata::MediaMetadataParser( |
| 447 source, mime_type, get_attached_images); | 448 source, mime_type, get_attached_images); |
| 448 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); | 449 parser->Start(base::Bind(&FinishParseMediaMetadata, base::Owned(parser))); |
| 449 } | 450 } |
| 450 #endif | 451 #endif |
| OLD | NEW |