OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "net/base/io_buffer.h" | |
9 #include "net/disk_cache/backend_impl.h" | 8 #include "net/disk_cache/backend_impl.h" |
10 #include "net/disk_cache/entry_impl.h" | 9 #include "net/disk_cache/entry_impl.h" |
11 | 10 |
12 namespace { | 11 namespace { |
13 | 12 |
14 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; | 13 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; |
15 const int kChannelSize = 64 * 1024; | 14 const int kChannelSize = 64 * 1024; |
16 const int kNumStreams = 4; | 15 const int kNumStreams = 4; |
17 | 16 |
18 // Simple macro to print out formatted debug messages. It is similar to a DLOG | 17 // Simple macro to print out formatted debug messages. It is similar to a DLOG |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 if (input_->msg.result != RESULT_OK) | 437 if (input_->msg.result != RESULT_OK) |
439 return Fail(); | 438 return Fail(); |
440 | 439 |
441 int read_size = input_->msg.buffer_bytes; | 440 int read_size = input_->msg.buffer_bytes; |
442 if (!read_size) { | 441 if (!read_size) { |
443 printf("Read failed, entry \"%s\" truncated!\n", entry_->GetKey().c_str()); | 442 printf("Read failed, entry \"%s\" truncated!\n", entry_->GetKey().c_str()); |
444 bytes_remaining_ = 0; | 443 bytes_remaining_ = 0; |
445 return SendReadData(); | 444 return SendReadData(); |
446 } | 445 } |
447 | 446 |
448 scoped_refptr<net::WrappedIOBuffer> buf = | 447 if (read_size != entry_->WriteData(stream_, offset_, input_->buffer, |
449 new net::WrappedIOBuffer(input_->buffer); | 448 read_size, NULL, false)) |
450 if (read_size != entry_->WriteData(stream_, offset_, buf, read_size, NULL, | |
451 false)) | |
452 return Fail(); | 449 return Fail(); |
453 | 450 |
454 offset_ += read_size; | 451 offset_ += read_size; |
455 bytes_remaining_ -= read_size; | 452 bytes_remaining_ -= read_size; |
456 // Read some more. | 453 // Read some more. |
457 SendReadData(); | 454 SendReadData(); |
458 } | 455 } |
459 | 456 |
460 void MasterSM::SendQuit() { | 457 void MasterSM::SendQuit() { |
461 DEBUGMSG("Master SendQuit\n"); | 458 DEBUGMSG("Master SendQuit\n"); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 DEBUGMSG("\t\t\tSlave DoReadData\n"); | 706 DEBUGMSG("\t\t\tSlave DoReadData\n"); |
710 Message msg; | 707 Message msg; |
711 msg.command = READ_DATA; | 708 msg.command = READ_DATA; |
712 | 709 |
713 int stream = input_->msg.arg1; | 710 int stream = input_->msg.arg1; |
714 int size = input_->msg.arg2; | 711 int size = input_->msg.arg2; |
715 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || | 712 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || |
716 stream < 0 || stream > 1 || size > kBufferSize) { | 713 stream < 0 || stream > 1 || size > kBufferSize) { |
717 msg.result = RESULT_INVALID_PARAMETER; | 714 msg.result = RESULT_INVALID_PARAMETER; |
718 } else { | 715 } else { |
719 scoped_refptr<net::WrappedIOBuffer> buf = | 716 int ret = entry_->ReadData(stream, input_->msg.arg3, output_->buffer, size, |
720 new net::WrappedIOBuffer(output_->buffer); | 717 NULL); |
721 int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size, NULL); | |
722 | 718 |
723 msg.buffer_bytes = (ret < 0) ? 0 : ret; | 719 msg.buffer_bytes = (ret < 0) ? 0 : ret; |
724 msg.result = RESULT_OK; | 720 msg.result = RESULT_OK; |
725 } | 721 } |
726 SendMsg(msg); | 722 SendMsg(msg); |
727 } | 723 } |
728 | 724 |
729 void SlaveSM::DoEnd() { | 725 void SlaveSM::DoEnd() { |
730 DEBUGMSG("\t\t\tSlave DoEnd\n"); | 726 DEBUGMSG("\t\t\tSlave DoEnd\n"); |
731 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 727 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 | 793 |
798 SlaveSM slave(&cache, pipe); | 794 SlaveSM slave(&cache, pipe); |
799 if (!slave.DoInit()) { | 795 if (!slave.DoInit()) { |
800 printf("Unable to talk with the main process\n"); | 796 printf("Unable to talk with the main process\n"); |
801 return -1; | 797 return -1; |
802 } | 798 } |
803 | 799 |
804 loop.Run(); | 800 loop.Run(); |
805 return 0; | 801 return 0; |
806 } | 802 } |
OLD | NEW |