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

Side by Side Diff: net/tools/dump_cache/upgrade.cc

Issue 2827043: Disk cache: Switch the disk cache to use the cache_thread. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: ... and the fix Created 10 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_path.h" 5 #include "base/file_path.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 READ_DATA, 97 READ_DATA,
98 // End processing requests. 98 // End processing requests.
99 QUIT 99 QUIT
100 }; 100 };
101 101
102 // The list of return codes. 102 // The list of return codes.
103 enum { 103 enum {
104 RESULT_OK = 0, 104 RESULT_OK = 0,
105 RESULT_UNKNOWN_COMMAND, 105 RESULT_UNKNOWN_COMMAND,
106 RESULT_INVALID_PARAMETER, 106 RESULT_INVALID_PARAMETER,
107 RESULT_NAME_OVERFLOW 107 RESULT_NAME_OVERFLOW,
108 RESULT_PENDING // This error code is NOT expected by the master process.
108 }; 109 };
109 110
110 // ----------------------------------------------------------------------- 111 // -----------------------------------------------------------------------
111 112
112 class BaseSM : public MessageLoopForIO::IOHandler { 113 class BaseSM : public MessageLoopForIO::IOHandler {
113 public: 114 public:
114 explicit BaseSM(HANDLE channel); 115 explicit BaseSM(HANDLE channel);
115 virtual ~BaseSM(); 116 virtual ~BaseSM();
116 117
117 protected: 118 protected:
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 private: 569 private:
569 enum { 570 enum {
570 SLAVE_INITIAL = 0, 571 SLAVE_INITIAL = 0,
571 SLAVE_WAITING, 572 SLAVE_WAITING,
572 SLAVE_END 573 SLAVE_END
573 }; 574 };
574 575
575 void DoGetNextEntry(); 576 void DoGetNextEntry();
576 void DoGetPrevEntry(); 577 void DoGetPrevEntry();
577 int32 GetEntryFromList(); 578 int32 GetEntryFromList();
579 void DoGetEntryComplete(int result);
578 void DoCloseEntry(); 580 void DoCloseEntry();
579 void DoGetKey(); 581 void DoGetKey();
580 void DoGetUseTimes(); 582 void DoGetUseTimes();
581 void DoGetDataSize(); 583 void DoGetDataSize();
582 void DoReadData(); 584 void DoReadData();
583 void DoReadDataComplete(int ret); 585 void DoReadDataComplete(int ret);
584 void DoEnd(); 586 void DoEnd();
585 void Fail(); 587 void Fail();
586 588
587 void* iterator_; 589 void* iterator_;
588 Message msg_; // Only used for DoReadDataComplete. 590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete.
589 591
590 net::CompletionCallbackImpl<SlaveSM> read_callback_; 592 net::CompletionCallbackImpl<SlaveSM> read_callback_;
593 net::CompletionCallbackImpl<SlaveSM> next_callback_;
591 scoped_ptr<disk_cache::BackendImpl> cache_; 594 scoped_ptr<disk_cache::BackendImpl> cache_;
592 }; 595 };
593 596
594 SlaveSM::SlaveSM(const std::wstring& path, HANDLE channel) 597 SlaveSM::SlaveSM(const std::wstring& path, HANDLE channel)
595 : BaseSM(channel), iterator_(NULL), 598 : BaseSM(channel), iterator_(NULL),
596 ALLOW_THIS_IN_INITIALIZER_LIST( 599 ALLOW_THIS_IN_INITIALIZER_LIST(
597 read_callback_(this, &SlaveSM::DoReadDataComplete)) { 600 read_callback_(this, &SlaveSM::DoReadDataComplete)),
601 ALLOW_THIS_IN_INITIALIZER_LIST(
602 next_callback_(this, &SlaveSM::DoGetEntryComplete)) {
598 disk_cache::Backend* cache; 603 disk_cache::Backend* cache;
599 TestCompletionCallback cb; 604 TestCompletionCallback cb;
600 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, 605 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
601 FilePath::FromWStringHack(path), 0, 606 FilePath::FromWStringHack(path), 0,
602 false, 607 false,
603 cache_thread_.message_loop_proxy(), 608 cache_thread_.message_loop_proxy(),
604 &cache, &cb); 609 &cache, &cb);
605 if (cb.GetResult(rv) != net::OK) { 610 if (cb.GetResult(rv) != net::OK) {
606 printf("Unable to open cache files\n"); 611 printf("Unable to open cache files\n");
607 return; 612 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 default: 670 default:
666 NOTREACHED(); 671 NOTREACHED();
667 break; 672 break;
668 } 673 }
669 } 674 }
670 675
671 bool SlaveSM::DoInit() { 676 bool SlaveSM::DoInit() {
672 DEBUGMSG("\t\t\tSlave DoInit\n"); 677 DEBUGMSG("\t\t\tSlave DoInit\n");
673 DCHECK(state_ == SLAVE_INITIAL); 678 DCHECK(state_ == SLAVE_INITIAL);
674 state_ = SLAVE_WAITING; 679 state_ = SLAVE_WAITING;
680 if (!cache_.get())
681 return false;
682
675 return ReceiveMsg(); 683 return ReceiveMsg();
676 } 684 }
677 685
678 void SlaveSM::DoGetNextEntry() { 686 void SlaveSM::DoGetNextEntry() {
679 DEBUGMSG("\t\t\tSlave DoGetNextEntry\n"); 687 DEBUGMSG("\t\t\tSlave DoGetNextEntry\n");
680 Message msg; 688 Message msg;
681 msg.command = GET_NEXT_ENTRY; 689 msg.command = GET_NEXT_ENTRY;
682 690
683 if (input_->msg.arg1) { 691 if (input_->msg.arg1) {
684 // We only support one list. 692 // We only support one list.
685 msg.result = RESULT_UNKNOWN_COMMAND; 693 msg.result = RESULT_UNKNOWN_COMMAND;
686 } else { 694 } else {
687 msg.result = GetEntryFromList(); 695 msg.result = GetEntryFromList();
688 msg.long_arg1 = reinterpret_cast<int64>(entry_); 696 msg.long_arg1 = reinterpret_cast<int64>(entry_);
689 } 697 }
690 SendMsg(msg); 698 SendMsg(msg);
691 } 699 }
692 700
693 void SlaveSM::DoGetPrevEntry() { 701 void SlaveSM::DoGetPrevEntry() {
694 DEBUGMSG("\t\t\tSlave DoGetPrevEntry\n"); 702 DEBUGMSG("\t\t\tSlave DoGetPrevEntry\n");
695 Message msg; 703 Message msg;
696 msg.command = GET_PREV_ENTRY; 704 msg.command = GET_PREV_ENTRY;
697 705
698 if (input_->msg.arg1) { 706 if (input_->msg.arg1) {
699 // We only support one list. 707 // We only support one list.
700 msg.result = RESULT_UNKNOWN_COMMAND; 708 msg.result = RESULT_UNKNOWN_COMMAND;
701 } else { 709 } else {
702 msg.result = GetEntryFromList(); 710 msg.result = GetEntryFromList();
711 if (msg.result == RESULT_PENDING) {
712 // We are not done yet.
713 msg_ = msg;
714 return;
715 }
703 msg.long_arg1 = reinterpret_cast<int64>(entry_); 716 msg.long_arg1 = reinterpret_cast<int64>(entry_);
704 } 717 }
705 SendMsg(msg); 718 SendMsg(msg);
706 } 719 }
707 720
708 // Move to the next or previous entry on the list. 721 // Move to the next or previous entry on the list.
709 int32 SlaveSM::GetEntryFromList() { 722 int32 SlaveSM::GetEntryFromList() {
710 DEBUGMSG("\t\t\tSlave GetEntryFromList\n"); 723 DEBUGMSG("\t\t\tSlave GetEntryFromList\n");
711 if (input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) 724 if (input_->msg.long_arg1 != reinterpret_cast<int64>(entry_))
712 return RESULT_INVALID_PARAMETER; 725 return RESULT_INVALID_PARAMETER;
713 726
714 // We know that the current iteration is valid. 727 // We know that the current iteration is valid.
715 if (entry_) 728 if (entry_)
716 entry_->Close(); 729 entry_->Close();
717 730
718 bool ret; 731 int rv;
719 if (input_->msg.command == GET_NEXT_ENTRY) { 732 if (input_->msg.command == GET_NEXT_ENTRY) {
720 ret = cache_->OpenNextEntry(&iterator_, 733 rv = cache_->OpenNextEntry(&iterator_,
721 reinterpret_cast<disk_cache::Entry**>(&entry_)); 734 reinterpret_cast<disk_cache::Entry**>(&entry_),
735 &next_callback_);
722 } else { 736 } else {
723 DCHECK(input_->msg.command == GET_PREV_ENTRY); 737 DCHECK(input_->msg.command == GET_PREV_ENTRY);
724 ret = cache_->OpenPrevEntry(&iterator_, 738 rv = cache_->OpenPrevEntry(&iterator_,
725 reinterpret_cast<disk_cache::Entry**>(&entry_)); 739 reinterpret_cast<disk_cache::Entry**>(&entry_),
740 &next_callback_);
741 }
742 DCHECK_EQ(net::ERR_IO_PENDING, rv);
743 return RESULT_PENDING;
744 }
745
746 void SlaveSM::DoGetEntryComplete(int result) {
747 DEBUGMSG("\t\t\tSlave DoGetEntryComplete\n");
748 if (result != net::OK) {
749 entry_ = NULL;
750 DEBUGMSG("\t\t\tSlave end of list\n");
726 } 751 }
727 752
728 if (!ret) 753 msg_.result = RESULT_OK;
729 entry_ = NULL; 754 msg_.long_arg1 = reinterpret_cast<int64>(entry_);
730 755 SendMsg(msg_);
731 if (!entry_)
732 DEBUGMSG("\t\t\tSlave end of list\n");
733
734 return RESULT_OK;
735 } 756 }
736 757
737 void SlaveSM::DoCloseEntry() { 758 void SlaveSM::DoCloseEntry() {
738 DEBUGMSG("\t\t\tSlave DoCloseEntry\n"); 759 DEBUGMSG("\t\t\tSlave DoCloseEntry\n");
739 Message msg; 760 Message msg;
740 msg.command = GET_KEY; 761 msg.command = GET_KEY;
741 762
742 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { 763 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) {
743 msg.result = RESULT_INVALID_PARAMETER; 764 msg.result = RESULT_INVALID_PARAMETER;
744 } else { 765 } else {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 919
899 SlaveSM slave(input_path, pipe); 920 SlaveSM slave(input_path, pipe);
900 if (!slave.DoInit()) { 921 if (!slave.DoInit()) {
901 printf("Unable to talk with the main process\n"); 922 printf("Unable to talk with the main process\n");
902 return -1; 923 return -1;
903 } 924 }
904 925
905 loop.Run(); 926 loop.Run();
906 return 0; 927 return 0;
907 } 928 }
OLDNEW
« net/disk_cache/backend_unittest.cc ('K') | « net/tools/crash_cache/crash_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698