| 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 "net/tools/dump_cache/upgrade_win.h" | 5 #include "net/tools/dump_cache/upgrade_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 15 #include "base/win/scoped_handle.h" | 16 #include "base/win/scoped_handle.h" |
| 16 #include "net/base/cache_type.h" | 17 #include "net/base/cache_type.h" |
| 17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 550 } |
| 550 | 551 |
| 551 void MasterSM::Fail() { | 552 void MasterSM::Fail() { |
| 552 DEBUGMSG("Master Fail\n"); | 553 DEBUGMSG("Master Fail\n"); |
| 553 printf("Unexpected failure\n"); | 554 printf("Unexpected failure\n"); |
| 554 SendQuit(); | 555 SendQuit(); |
| 555 } | 556 } |
| 556 | 557 |
| 557 // ----------------------------------------------------------------------- | 558 // ----------------------------------------------------------------------- |
| 558 | 559 |
| 559 class SlaveSM : public BaseSM { | 560 class SlaveSM FINAL : public BaseSM { |
| 560 public: | 561 public: |
| 561 SlaveSM(const base::FilePath& path, HANDLE channel); | 562 SlaveSM(const base::FilePath& path, HANDLE channel); |
| 562 virtual ~SlaveSM(); | |
| 563 | 563 |
| 564 bool DoInit(); | 564 bool DoInit(); |
| 565 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 565 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 566 DWORD bytes_transfered, | 566 DWORD bytes_transfered, |
| 567 DWORD error); | 567 DWORD error); |
| 568 | 568 |
| 569 private: | 569 private: |
| 570 enum { | 570 enum { |
| 571 SLAVE_INITIAL = 0, | 571 SLAVE_INITIAL = 0, |
| 572 SLAVE_WAITING, | 572 SLAVE_WAITING, |
| 573 SLAVE_END | 573 SLAVE_END |
| 574 }; | 574 }; |
| 575 | 575 |
| 576 void DoGetNextEntry(); | 576 void DoGetNextEntry(); |
| 577 void DoGetPrevEntry(); | 577 void DoGetPrevEntry(); |
| 578 int32 GetEntryFromList(); | 578 int32 GetEntryFromList(); |
| 579 void DoGetEntryComplete(int result); | 579 void DoGetEntryComplete(int result); |
| 580 void DoCloseEntry(); | 580 void DoCloseEntry(); |
| 581 void DoGetKey(); | 581 void DoGetKey(); |
| 582 void DoGetUseTimes(); | 582 void DoGetUseTimes(); |
| 583 void DoGetDataSize(); | 583 void DoGetDataSize(); |
| 584 void DoReadData(); | 584 void DoReadData(); |
| 585 void DoReadDataComplete(int ret); | 585 void DoReadDataComplete(int ret); |
| 586 void DoEnd(); | 586 void DoEnd(); |
| 587 void Fail(); | 587 void Fail(); |
| 588 | 588 |
| 589 void* iterator_; | 589 disk_cache::Backend::Iterator iterator_; |
| 590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. | 590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. |
| 591 | 591 |
| 592 scoped_ptr<disk_cache::BackendImpl> cache_; | 592 scoped_ptr<disk_cache::BackendImpl> cache_; |
| 593 }; | 593 }; |
| 594 | 594 |
| 595 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) | 595 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) : BaseSM(channel) { |
| 596 : BaseSM(channel), iterator_(NULL) { | |
| 597 scoped_ptr<disk_cache::Backend> cache; | 596 scoped_ptr<disk_cache::Backend> cache; |
| 598 net::TestCompletionCallback cb; | 597 net::TestCompletionCallback cb; |
| 599 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 598 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 600 net::CACHE_BACKEND_BLOCKFILE, path, 0, | 599 net::CACHE_BACKEND_BLOCKFILE, path, 0, |
| 601 false, | 600 false, |
| 602 cache_thread_.message_loop_proxy(), | 601 cache_thread_.message_loop_proxy(), |
| 603 NULL, &cache, cb.callback()); | 602 NULL, &cache, cb.callback()); |
| 604 if (cb.GetResult(rv) != net::OK) { | 603 if (cb.GetResult(rv) != net::OK) { |
| 605 printf("Unable to open cache files\n"); | 604 printf("Unable to open cache files\n"); |
| 606 return; | 605 return; |
| 607 } | 606 } |
| 608 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache.release())); | 607 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache.release())); |
| 609 cache_->SetUpgradeMode(); | 608 cache_->SetUpgradeMode(); |
| 610 } | 609 } |
| 611 | 610 |
| 612 SlaveSM::~SlaveSM() { | |
| 613 if (iterator_) | |
| 614 cache_->EndEnumeration(&iterator_); | |
| 615 } | |
| 616 | |
| 617 void SlaveSM::OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 611 void SlaveSM::OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 618 DWORD bytes_transfered, | 612 DWORD bytes_transfered, |
| 619 DWORD error) { | 613 DWORD error) { |
| 620 pending_count_--; | 614 pending_count_--; |
| 621 if (state_ == SLAVE_END) { | 615 if (state_ == SLAVE_END) { |
| 622 if (IsPending()) | 616 if (IsPending()) |
| 623 return; | 617 return; |
| 624 return DoEnd(); | 618 return DoEnd(); |
| 625 } | 619 } |
| 626 | 620 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 void SlaveSM::DoCloseEntry() { | 748 void SlaveSM::DoCloseEntry() { |
| 755 DEBUGMSG("\t\t\tSlave DoCloseEntry\n"); | 749 DEBUGMSG("\t\t\tSlave DoCloseEntry\n"); |
| 756 Message msg; | 750 Message msg; |
| 757 msg.command = GET_KEY; | 751 msg.command = GET_KEY; |
| 758 | 752 |
| 759 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { | 753 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
| 760 msg.result = RESULT_INVALID_PARAMETER; | 754 msg.result = RESULT_INVALID_PARAMETER; |
| 761 } else { | 755 } else { |
| 762 entry_->Close(); | 756 entry_->Close(); |
| 763 entry_ = NULL; | 757 entry_ = NULL; |
| 764 cache_->EndEnumeration(&iterator_); | 758 iterator_.reset(); |
| 765 msg.result = RESULT_OK; | 759 msg.result = RESULT_OK; |
| 766 } | 760 } |
| 767 SendMsg(msg); | 761 SendMsg(msg); |
| 768 } | 762 } |
| 769 | 763 |
| 770 void SlaveSM::DoGetKey() { | 764 void SlaveSM::DoGetKey() { |
| 771 DEBUGMSG("\t\t\tSlave DoGetKey\n"); | 765 DEBUGMSG("\t\t\tSlave DoGetKey\n"); |
| 772 Message msg; | 766 Message msg; |
| 773 msg.command = GET_KEY; | 767 msg.command = GET_KEY; |
| 774 | 768 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 | 912 |
| 919 SlaveSM slave(input_path, pipe); | 913 SlaveSM slave(input_path, pipe); |
| 920 if (!slave.DoInit()) { | 914 if (!slave.DoInit()) { |
| 921 printf("Unable to talk with the main process\n"); | 915 printf("Unable to talk with the main process\n"); |
| 922 return -1; | 916 return -1; |
| 923 } | 917 } |
| 924 | 918 |
| 925 loop.Run(); | 919 loop.Run(); |
| 926 return 0; | 920 return 0; |
| 927 } | 921 } |
| OLD | NEW |