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

Side by Side Diff: net/base/file_stream_unittest.cc

Issue 9384024: Prefer ScopedNestableTaskAllower over manual save/restore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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) 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/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 *total_bytes_read_ += total_bytes_read; 742 *total_bytes_read_ += total_bytes_read;
743 *data_read_ += data_read; 743 *data_read_ += data_read;
744 } else { // We're done writing all data. Start reading the data. 744 } else { // We're done writing all data. Start reading the data.
745 stream_->Seek(FROM_BEGIN, 0); 745 stream_->Seek(FROM_BEGIN, 0);
746 746
747 TestCompletionCallback callback; 747 TestCompletionCallback callback;
748 for (;;) { 748 for (;;) {
749 char buf[4]; 749 char buf[4];
750 rv = stream_->Read(buf, arraysize(buf), callback.callback()); 750 rv = stream_->Read(buf, arraysize(buf), callback.callback());
751 if (rv == ERR_IO_PENDING) { 751 if (rv == ERR_IO_PENDING) {
752 bool old_state = MessageLoop::current()->NestableTasksAllowed(); 752 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
753 MessageLoop::current()->SetNestableTasksAllowed(true);
754 rv = callback.WaitForResult(); 753 rv = callback.WaitForResult();
755 MessageLoop::current()->SetNestableTasksAllowed(old_state);
756 } 754 }
757 EXPECT_LE(0, rv); 755 EXPECT_LE(0, rv);
758 if (rv <= 0) 756 if (rv <= 0)
759 break; 757 break;
760 *total_bytes_read_ += rv; 758 *total_bytes_read_ += rv;
761 data_read_->append(buf, rv); 759 data_read_->append(buf, rv);
762 } 760 }
763 } 761 }
764 762
765 result_ = *total_bytes_written_; 763 result_ = *total_bytes_written_;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 // Read in the contents and make sure we get back what we expected. 940 // Read in the contents and make sure we get back what we expected.
943 std::string read_contents; 941 std::string read_contents;
944 EXPECT_TRUE(file_util::ReadFileToString(temp_file_path(), &read_contents)); 942 EXPECT_TRUE(file_util::ReadFileToString(temp_file_path(), &read_contents));
945 943
946 EXPECT_EQ("01230123", read_contents); 944 EXPECT_EQ("01230123", read_contents);
947 } 945 }
948 946
949 } // namespace 947 } // namespace
950 948
951 } // namespace net 949 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698