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

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

Issue 2705613003: Convert utility process zip creator IPC to mojo (Closed)
Patch Set: Add a comment about release references. Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector>
9 10
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "chrome/common/chrome_utility_messages.h" 17 #include "chrome/common/chrome_utility_messages.h"
17 #include "chrome/common/file_patcher.mojom.h" 18 #include "chrome/common/file_patcher.mojom.h"
18 #include "chrome/common/safe_browsing/zip_analyzer.h" 19 #include "chrome/common/safe_browsing/zip_analyzer.h"
(...skipping 17 matching lines...) Expand all
36 #include "ui/gfx/geometry/size.h" 37 #include "ui/gfx/geometry/size.h"
37 38
38 #if !defined(OS_ANDROID) 39 #if !defined(OS_ANDROID)
39 #include "chrome/common/resource_usage_reporter.mojom.h" 40 #include "chrome/common/resource_usage_reporter.mojom.h"
40 #include "chrome/utility/profile_import_handler.h" 41 #include "chrome/utility/profile_import_handler.h"
41 #include "mojo/public/cpp/bindings/strong_binding.h" 42 #include "mojo/public/cpp/bindings/strong_binding.h"
42 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" 43 #include "net/proxy/mojo_proxy_resolver_factory_impl.h"
43 #include "net/proxy/proxy_resolver_v8.h" 44 #include "net/proxy/proxy_resolver_v8.h"
44 #endif 45 #endif
45 46
47 #if defined(OS_CHROMEOS)
48 #include "chrome/common/zip_file_creator.mojom.h"
49 #endif
50
46 #if defined(OS_WIN) 51 #if defined(OS_WIN)
47 #include "chrome/utility/ipc_shell_handler_win.h" 52 #include "chrome/utility/ipc_shell_handler_win.h"
48 #include "chrome/utility/shell_handler_impl_win.h" 53 #include "chrome/utility/shell_handler_impl_win.h"
49 #endif 54 #endif
50 55
51 #if BUILDFLAG(ENABLE_EXTENSIONS) 56 #if BUILDFLAG(ENABLE_EXTENSIONS)
52 #include "chrome/utility/extensions/extensions_handler.h" 57 #include "chrome/utility/extensions/extensions_handler.h"
53 #endif 58 #endif
54 59
55 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ 60 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
56 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN)) 61 (BUILDFLAG(ENABLE_BASIC_PRINTING) && defined(OS_WIN))
57 #include "chrome/utility/printing_handler.h" 62 #include "chrome/utility/printing_handler.h"
58 #endif 63 #endif
59 64
60 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING) 65 #if defined(OS_MACOSX) && defined(FULL_SAFE_BROWSING)
61 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h" 66 #include "chrome/utility/safe_browsing/mac/dmg_analyzer.h"
62 #endif 67 #endif
63 68
64 namespace { 69 namespace {
65 70
66 #if defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
67 bool Send(IPC::Message* message) {
68 return content::UtilityThread::Get()->Send(message);
69 }
70
71 void ReleaseProcessIfNeeded() {
72 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
73 }
74 #endif // defined(OS_CHROMEOS) || defined(FULL_SAFE_BROWSING)
75
76 class FilePatcherImpl : public chrome::mojom::FilePatcher { 71 class FilePatcherImpl : public chrome::mojom::FilePatcher {
77 public: 72 public:
78 FilePatcherImpl() = default; 73 FilePatcherImpl() = default;
79 ~FilePatcherImpl() override = default; 74 ~FilePatcherImpl() override = default;
80 75
81 static void Create(chrome::mojom::FilePatcherRequest request) { 76 static void Create(chrome::mojom::FilePatcherRequest request) {
82 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(), 77 mojo::MakeStrongBinding(base::MakeUnique<FilePatcherImpl>(),
83 std::move(request)); 78 std::move(request));
84 } 79 }
85 80
(...skipping 13 matching lines...) Expand all
99 base::File output_file, 94 base::File output_file,
100 const PatchFileCourgetteCallback& callback) override { 95 const PatchFileCourgetteCallback& callback) override {
101 const int patch_result_status = courgette::ApplyEnsemblePatch( 96 const int patch_result_status = courgette::ApplyEnsemblePatch(
102 std::move(input_file), std::move(patch_file), std::move(output_file)); 97 std::move(input_file), std::move(patch_file), std::move(output_file));
103 callback.Run(patch_result_status); 98 callback.Run(patch_result_status);
104 } 99 }
105 100
106 DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl); 101 DISALLOW_COPY_AND_ASSIGN(FilePatcherImpl);
107 }; 102 };
108 103
104 #if defined(OS_CHROMEOS)
105 class ZipFileCreatorImpl : public chrome::mojom::ZipFileCreator {
106 public:
107 ZipFileCreatorImpl() = default;
108 ~ZipFileCreatorImpl() override = default;
109
110 static void Create(chrome::mojom::ZipFileCreatorRequest request) {
111 mojo::MakeStrongBinding(base::MakeUnique<ZipFileCreatorImpl>(),
112 std::move(request));
113 }
114
115 private:
116 // chrome::mojom::ZipFileCreator:
117 void CreateZipFile(const base::FilePath& source_dir,
118 const std::vector<base::FilePath>& source_relative_paths,
119 base::File zip_file,
120 const CreateZipFileCallback& callback) override {
121 DCHECK(zip_file.IsValid());
122
123 for (const auto& path : source_relative_paths) {
124 if (path.IsAbsolute() || path.ReferencesParent()) {
125 callback.Run(false);
126 return;
127 }
128 }
129
130 callback.Run(zip::ZipFiles(source_dir, source_relative_paths,
131 zip_file.GetPlatformFile()));
132 }
133
134 DISALLOW_COPY_AND_ASSIGN(ZipFileCreatorImpl);
135 };
136 #endif // defined(OS_CHROMEOS)
137
109 #if !defined(OS_ANDROID) 138 #if !defined(OS_ANDROID)
110 void CreateProxyResolverFactory( 139 void CreateProxyResolverFactory(
111 net::interfaces::ProxyResolverFactoryRequest request) { 140 net::interfaces::ProxyResolverFactoryRequest request) {
112 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(), 141 mojo::MakeStrongBinding(base::MakeUnique<net::MojoProxyResolverFactoryImpl>(),
113 std::move(request)); 142 std::move(request));
114 } 143 }
115 144
116 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter { 145 class ResourceUsageReporterImpl : public chrome::mojom::ResourceUsageReporter {
117 public: 146 public:
118 ResourceUsageReporterImpl() {} 147 ResourceUsageReporterImpl() {}
119 ~ResourceUsageReporterImpl() override {} 148 ~ResourceUsageReporterImpl() override {}
120 149
121 private: 150 private:
122 void GetUsageData(const GetUsageDataCallback& callback) override { 151 void GetUsageData(const GetUsageDataCallback& callback) override {
123 chrome::mojom::ResourceUsageDataPtr data = 152 chrome::mojom::ResourceUsageDataPtr data =
124 chrome::mojom::ResourceUsageData::New(); 153 chrome::mojom::ResourceUsageData::New();
125 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize(); 154 size_t total_heap_size = net::ProxyResolverV8::GetTotalHeapSize();
126 if (total_heap_size) { 155 if (total_heap_size) {
127 data->reports_v8_stats = true; 156 data->reports_v8_stats = true;
128 data->v8_bytes_allocated = total_heap_size; 157 data->v8_bytes_allocated = total_heap_size;
129 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize(); 158 data->v8_bytes_used = net::ProxyResolverV8::GetUsedHeapSize();
130 } 159 }
131 callback.Run(std::move(data)); 160 callback.Run(std::move(data));
132 } 161 }
162
163 DISALLOW_COPY_AND_ASSIGN(ResourceUsageReporterImpl);
133 }; 164 };
134 165
135 void CreateResourceUsageReporter( 166 void CreateResourceUsageReporter(
136 mojo::InterfaceRequest<chrome::mojom::ResourceUsageReporter> request) { 167 mojo::InterfaceRequest<chrome::mojom::ResourceUsageReporter> request) {
137 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(), 168 mojo::MakeStrongBinding(base::MakeUnique<ResourceUsageReporterImpl>(),
138 std::move(request)); 169 std::move(request));
139 } 170 }
140 #endif // !defined(OS_ANDROID) 171 #endif // !defined(OS_ANDROID)
141 172
142 std::unique_ptr<service_manager::Service> CreateImageDecoderService() { 173 std::unique_ptr<service_manager::Service> CreateImageDecoderService() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 bool handled = true; 213 bool handled = true;
183 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message) 214 IPC_BEGIN_MESSAGE_MAP(ChromeContentUtilityClient, message)
184 #if defined(FULL_SAFE_BROWSING) 215 #if defined(FULL_SAFE_BROWSING)
185 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection, 216 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeZipFileForDownloadProtection,
186 OnAnalyzeZipFileForDownloadProtection) 217 OnAnalyzeZipFileForDownloadProtection)
187 #if defined(OS_MACOSX) 218 #if defined(OS_MACOSX)
188 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection, 219 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_AnalyzeDmgFileForDownloadProtection,
189 OnAnalyzeDmgFileForDownloadProtection) 220 OnAnalyzeDmgFileForDownloadProtection)
190 #endif // defined(OS_MACOSX) 221 #endif // defined(OS_MACOSX)
191 #endif // defined(FULL_SAFE_BROWSING) 222 #endif // defined(FULL_SAFE_BROWSING)
192 #if defined(OS_CHROMEOS)
193 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_CreateZipFile, OnCreateZipFile)
194 #endif
195 IPC_MESSAGE_UNHANDLED(handled = false) 223 IPC_MESSAGE_UNHANDLED(handled = false)
196 IPC_END_MESSAGE_MAP() 224 IPC_END_MESSAGE_MAP()
197 225
198 if (handled) 226 if (handled)
199 return true; 227 return true;
200 228
201 for (auto* handler : handlers_) { 229 for (auto* handler : handlers_) {
202 if (handler->OnMessageReceived(message)) 230 if (handler->OnMessageReceived(message))
203 return true; 231 return true;
204 } 232 }
(...skipping 17 matching lines...) Expand all
222 registry->AddInterface<net::interfaces::ProxyResolverFactory>( 250 registry->AddInterface<net::interfaces::ProxyResolverFactory>(
223 base::Bind(CreateProxyResolverFactory)); 251 base::Bind(CreateProxyResolverFactory));
224 registry->AddInterface(base::Bind(CreateResourceUsageReporter)); 252 registry->AddInterface(base::Bind(CreateResourceUsageReporter));
225 registry->AddInterface(base::Bind(&ProfileImportHandler::Create)); 253 registry->AddInterface(base::Bind(&ProfileImportHandler::Create));
226 #endif 254 #endif
227 registry->AddInterface( 255 registry->AddInterface(
228 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create)); 256 base::Bind(&safe_json::SafeJsonParserMojoImpl::Create));
229 #if defined(OS_WIN) 257 #if defined(OS_WIN)
230 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create)); 258 registry->AddInterface(base::Bind(&ShellHandlerImpl::Create));
231 #endif 259 #endif
260 #if defined(OS_CHROMEOS)
261 registry->AddInterface(base::Bind(&ZipFileCreatorImpl::Create));
262 #endif
232 } 263 }
233 264
234 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) { 265 void ChromeContentUtilityClient::RegisterServices(StaticServiceMap* services) {
235 content::ServiceInfo image_decoder_info; 266 content::ServiceInfo image_decoder_info;
236 image_decoder_info.factory = base::Bind(&CreateImageDecoderService); 267 image_decoder_info.factory = base::Bind(&CreateImageDecoderService);
237 services->insert( 268 services->insert(
238 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info)); 269 std::make_pair(image_decoder::mojom::kServiceName, image_decoder_info));
239 } 270 }
240 271
241 // static 272 // static
242 void ChromeContentUtilityClient::PreSandboxStartup() { 273 void ChromeContentUtilityClient::PreSandboxStartup() {
243 #if BUILDFLAG(ENABLE_EXTENSIONS) 274 #if BUILDFLAG(ENABLE_EXTENSIONS)
244 extensions::ExtensionsHandler::PreSandboxStartup(); 275 extensions::ExtensionsHandler::PreSandboxStartup();
245 #endif 276 #endif
246 } 277 }
247 278
248 #if defined(OS_CHROMEOS)
249 void ChromeContentUtilityClient::OnCreateZipFile(
250 const base::FilePath& src_dir,
251 const std::vector<base::FilePath>& src_relative_paths,
252 const base::FileDescriptor& dest_fd) {
253 // dest_fd should be closed in the function. See ipc/ipc_message_util.h for
254 // details.
255 base::ScopedFD fd_closer(dest_fd.fd);
256 bool succeeded = true;
257
258 // Check sanity of source relative paths. Reject if path is absolute or
259 // contains any attempt to reference a parent directory ("../" tricks).
260 for (std::vector<base::FilePath>::const_iterator iter =
261 src_relative_paths.begin(); iter != src_relative_paths.end();
262 ++iter) {
263 if (iter->IsAbsolute() || iter->ReferencesParent()) {
264 succeeded = false;
265 break;
266 }
267 }
268
269 if (succeeded)
270 succeeded = zip::ZipFiles(src_dir, src_relative_paths, dest_fd.fd);
271
272 if (succeeded)
273 Send(new ChromeUtilityHostMsg_CreateZipFile_Succeeded());
274 else
275 Send(new ChromeUtilityHostMsg_CreateZipFile_Failed());
276 ReleaseProcessIfNeeded();
277 }
278 #endif // defined(OS_CHROMEOS)
279
280 #if defined(FULL_SAFE_BROWSING) 279 #if defined(FULL_SAFE_BROWSING)
281 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection( 280 void ChromeContentUtilityClient::OnAnalyzeZipFileForDownloadProtection(
282 const IPC::PlatformFileForTransit& zip_file, 281 const IPC::PlatformFileForTransit& zip_file,
283 const IPC::PlatformFileForTransit& temp_file) { 282 const IPC::PlatformFileForTransit& temp_file) {
284 safe_browsing::zip_analyzer::Results results; 283 safe_browsing::zip_analyzer::Results results;
285 safe_browsing::zip_analyzer::AnalyzeZipFile( 284 safe_browsing::zip_analyzer::AnalyzeZipFile(
286 IPC::PlatformFileForTransitToFile(zip_file), 285 IPC::PlatformFileForTransitToFile(zip_file),
287 IPC::PlatformFileForTransitToFile(temp_file), &results); 286 IPC::PlatformFileForTransitToFile(temp_file), &results);
288 Send(new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished( 287 content::UtilityThread::Get()->Send(
289 results)); 288 new ChromeUtilityHostMsg_AnalyzeZipFileForDownloadProtection_Finished(
290 ReleaseProcessIfNeeded(); 289 results));
290 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
291 } 291 }
292 292
293 #if defined(OS_MACOSX) 293 #if defined(OS_MACOSX)
294 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection( 294 void ChromeContentUtilityClient::OnAnalyzeDmgFileForDownloadProtection(
295 const IPC::PlatformFileForTransit& dmg_file) { 295 const IPC::PlatformFileForTransit& dmg_file) {
296 safe_browsing::zip_analyzer::Results results; 296 safe_browsing::zip_analyzer::Results results;
297 safe_browsing::dmg::AnalyzeDMGFile( 297 safe_browsing::dmg::AnalyzeDMGFile(
298 IPC::PlatformFileForTransitToFile(dmg_file), &results); 298 IPC::PlatformFileForTransitToFile(dmg_file), &results);
299 Send(new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished( 299 content::UtilityThread::Get()->Send(
300 results)); 300 new ChromeUtilityHostMsg_AnalyzeDmgFileForDownloadProtection_Finished(
301 ReleaseProcessIfNeeded(); 301 results));
302 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
302 } 303 }
303 #endif // defined(OS_MACOSX) 304 #endif // defined(OS_MACOSX)
304 305
305 #endif // defined(FULL_SAFE_BROWSING) 306 #endif // defined(FULL_SAFE_BROWSING)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698