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