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

Side by Side Diff: ui/file_manager/zip_archiver/cpp/volume.cc

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Delete BUILD.gn Created 3 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 2014 The Chromium OS Authors. All rights reserved. 1 // Copyright 2014 The Chromium OS 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 "volume.h" 5 #include "volume.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "request.h" 10 #include "request.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 file_system_id_, request_id, volume_archive_->error_message()); 323 file_system_id_, request_id, volume_archive_->error_message());
324 ClearJob(); 324 ClearJob();
325 delete volume_archive_; 325 delete volume_archive_;
326 volume_archive_ = NULL; 326 volume_archive_ = NULL;
327 return; 327 return;
328 } 328 }
329 329
330 // Read and construct metadata. 330 // Read and construct metadata.
331 pp::VarDictionary root_metadata = CreateEntry(-1, "" /* name */, true, 0, 0); 331 pp::VarDictionary root_metadata = CreateEntry(-1, "" /* name */, true, 0, 0);
332 332
333 const char* path_name = NULL; 333 std::string path_name;
334 int64_t size = 0; 334 int64_t size = 0;
335 bool is_directory = false; 335 bool is_directory = false;
336 time_t modification_time = 0; 336 time_t modification_time = 0;
337 int64_t index = 0; 337 int64_t index = 0;
338 338
339 for (;;) { 339 for (;;) {
340 VolumeArchive::Result ret = volume_archive_->GetNextHeader( 340 path_name.clear();
341 &path_name, &size, &is_directory, &modification_time); 341 if (volume_archive_->GetCurrentFileInfo(
342 if (ret == VolumeArchive::RESULT_FAIL) { 342 &path_name,
343 message_sender_->SendFileSystemError( 343 &size,
344 file_system_id_, request_id, volume_archive_->error_message()); 344 &is_directory,
345 &modification_time) == VolumeArchive::RESULT_FAIL) {
346 message_sender_->SendFileSystemError(file_system_id_, request_id,
347 volume_archive_->error_message());
345 ClearJob(); 348 ClearJob();
346 delete volume_archive_; 349 delete volume_archive_;
347 volume_archive_ = NULL; 350 volume_archive_ = NULL;
348 return; 351 return;
349 } else if (ret == VolumeArchive::RESULT_EOF) 352 }
353
354 if (path_name.empty()) // End of archive.
350 break; 355 break;
351 356
352 ConstructMetadata(index, path_name, size, is_directory, modification_time, 357 ConstructMetadata(index, path_name.c_str(), size, is_directory,
353 &root_metadata); 358 modification_time, &root_metadata);
359
360 index_to_pathname_[index] = path_name;
354 361
355 ++index; 362 ++index;
363
364 int return_value = volume_archive_->GoToNextFile();
mtomasz 2017/04/10 07:15:09 Please check performance of opening large files. I
takise 2017/04/11 06:00:51 I compared the time to open https://github.com/tor
mtomasz 2017/04/11 06:36:45 Thanks for checking. 2 times slower on such a larg
365 if (return_value == VolumeArchive::RESULT_FAIL) {
366 message_sender_->SendFileSystemError(file_system_id_, request_id,
367 volume_archive_->error_message());
368 ClearJob();
369 delete volume_archive_;
370 volume_archive_ = NULL;
371 return;
372 }
373 if (return_value == VolumeArchive::RESULT_EOF)
374 break;
356 } 375 }
357 376
358 ClearJob(); 377 ClearJob();
359 378
360 // Send metadata back to JavaScript. 379 // Send metadata back to JavaScript.
361 message_sender_->SendReadMetadataDone( 380 message_sender_->SendReadMetadataDone(file_system_id_, request_id,
362 file_system_id_, request_id, root_metadata); 381 root_metadata);
363 } 382 }
364 383
365 void Volume::OpenFileCallback(int32_t /*result*/, 384 void Volume::OpenFileCallback(int32_t /*result*/,
366 const OpenFileArgs& args) { 385 const OpenFileArgs& args) {
367 if (!volume_archive_) { 386 if (!volume_archive_) {
368 message_sender_->SendFileSystemError( 387 message_sender_->SendFileSystemError(
369 file_system_id_, args.request_id, "NOT_OPENED"); 388 file_system_id_, args.request_id, "NOT_OPENED");
370 return; 389 return;
371 } 390 }
372 391
373 job_lock_.Acquire(); 392 job_lock_.Acquire();
374 if (!reader_request_id_.empty()) { 393 if (!reader_request_id_.empty()) {
375 // It is illegal to open a file while another operation is in progress or 394 // It is illegal to open a file while another operation is in progress or
376 // another file is opened. 395 // another file is opened.
377 message_sender_->SendFileSystemError( 396 message_sender_->SendFileSystemError(
378 file_system_id_, args.request_id, "ILLEGAL"); 397 file_system_id_, args.request_id, "ILLEGAL");
379 job_lock_.Release(); 398 job_lock_.Release();
380 return; 399 return;
381 } 400 }
382 static_cast<VolumeReaderJavaScriptStream*>(volume_archive_->reader())-> 401
383 SetRequestId(args.request_id); 402 static_cast<VolumeReaderJavaScriptStream*>(volume_archive_->reader())
403 ->SetRequestId(args.request_id);
384 reader_request_id_ = args.request_id; 404 reader_request_id_ = args.request_id;
385 job_lock_.Release(); 405 job_lock_.Release();
386 406
387 if (!volume_archive_->SeekHeader(args.index)) { 407 std::string path_name = index_to_pathname_[args.index];
388 message_sender_->SendFileSystemError( 408 int64_t size = 0;
389 file_system_id_, args.request_id, volume_archive_->error_message()); 409 bool is_directory = false;
410 time_t modification_time = 0;
411
412 if (!volume_archive_->SeekHeader(path_name)) {
413 message_sender_->SendFileSystemError(file_system_id_, args.request_id,
414 volume_archive_->error_message());
390 ClearJob(); 415 ClearJob();
391 return; 416 return;
392 } 417 }
393 418
394 if (volume_archive_->GetNextHeader() == VolumeArchive::RESULT_FAIL) { 419 if (volume_archive_->GetCurrentFileInfo(
395 message_sender_->SendFileSystemError( 420 &path_name,
396 file_system_id_, args.request_id, volume_archive_->error_message()); 421 &size,
422 &is_directory,
423 &modification_time) != VolumeArchive::RESULT_SUCCESS) {
424 message_sender_->SendFileSystemError(file_system_id_, args.request_id,
425 volume_archive_->error_message());
397 ClearJob(); 426 ClearJob();
398 return; 427 return;
399 } 428 }
400 429
401 // Send successful opened file response to NaCl. 430 // Send successful opened file response to NaCl.
402 message_sender_->SendOpenFileDone(file_system_id_, args.request_id); 431 message_sender_->SendOpenFileDone(file_system_id_, args.request_id);
403 } 432 }
404 433
405 void Volume::CloseFileCallback(int32_t /*result*/, 434 void Volume::CloseFileCallback(int32_t /*result*/,
406 const std::string& request_id, 435 const std::string& request_id,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 509 }
481 volume_archive_->MaybeDecompressAhead(); 510 volume_archive_->MaybeDecompressAhead();
482 } 511 }
483 512
484 513
485 void Volume::ClearJob() { 514 void Volume::ClearJob() {
486 job_lock_.Acquire(); 515 job_lock_.Acquire();
487 reader_request_id_ = ""; 516 reader_request_id_ = "";
488 job_lock_.Release(); 517 job_lock_.Release();
489 } 518 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698