summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-08 21:57:08 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-08 21:57:08 +0000
commitd20ab94f4e849e91a3e415a405b88a23afa408c6 (patch)
tree92189e9ce3b53aaf0185f16d6a0dd2b4bb4140e6 /net
parentfae7753433ce0fff8e5f28bedde84f7b164bc422 (diff)
downloadchromium_src-d20ab94f4e849e91a3e415a405b88a23afa408c6.zip
chromium_src-d20ab94f4e849e91a3e415a405b88a23afa408c6.tar.gz
chromium_src-d20ab94f4e849e91a3e415a405b88a23afa408c6.tar.bz2
net: Rename FileStream::Open/Close with OpenSync/CloseSync.
This is in preparation for implementing async versions of Open() and Close(). The existing clients are changed to use OpenSync/CloseSync. No logic is changed. TEST=try bots to confirm everythign is built as before. BUG=72001 Review URL: http://codereview.chromium.org/9349005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/file_stream.h20
-rw-r--r--net/base/file_stream_posix.cc6
-rw-r--r--net/base/file_stream_unittest.cc64
-rw-r--r--net/base/file_stream_win.cc6
-rw-r--r--net/base/mock_file_stream.cc6
-rw-r--r--net/base/mock_file_stream.h2
-rw-r--r--net/base/upload_data.cc7
-rw-r--r--net/base/upload_data_stream.cc2
-rw-r--r--net/tools/dump_cache/dump_files.cc2
-rw-r--r--net/url_request/url_request_file_job.cc4
10 files changed, 62 insertions, 57 deletions
diff --git a/net/base/file_stream.h b/net/base/file_stream.h
index a50d9c0..39863a5 100644
--- a/net/base/file_stream.h
+++ b/net/base/file_stream.h
@@ -47,16 +47,20 @@ class NET_EXPORT FileStream {
virtual ~FileStream();
- // Call this method to close the FileStream. It is OK to call Close
- // multiple times. Redundant calls are ignored.
+ // Call this method to close the FileStream synchronously.
+ // It is OK to call Close multiple times. Redundant calls are ignored.
// Note that if there are any pending async operations, they'll be aborted.
- virtual void Close();
+ //
+ // TODO(satorux): Implement the asynchronous version of this.
+ virtual void CloseSync();
- // Call this method to open the FileStream. The remaining methods
- // cannot be used unless this method returns OK. If the file cannot be
- // opened then an error code is returned.
- // open_flags is a bitfield of base::PlatformFileFlags
- virtual int Open(const FilePath& path, int open_flags);
+ // Call this method to open the FileStream synchronously.
+ // The remaining methods cannot be used unless this method returns OK. If
+ // the file cannot be opened then an error code is returned. open_flags is
+ // a bitfield of base::PlatformFileFlags
+ //
+ // TODO(satorux): Implement the asynchronous version of this.
+ virtual int OpenSync(const FilePath& path, int open_flags);
// Returns true if Open succeeded and Close has not been called.
virtual bool IsOpen() const;
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index a094eed..86f64ec 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -341,12 +341,12 @@ FileStream::FileStream(base::PlatformFile file, int flags, net::NetLog* net_log)
FileStream::~FileStream() {
if (auto_closed_)
- Close();
+ CloseSync();
bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL);
}
-void FileStream::Close() {
+void FileStream::CloseSync() {
bound_net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL);
// Abort any existing asynchronous operations.
@@ -361,7 +361,7 @@ void FileStream::Close() {
}
}
-int FileStream::Open(const FilePath& path, int open_flags) {
+int FileStream::OpenSync(const FilePath& path, int open_flags) {
if (IsOpen()) {
DLOG(FATAL) << "File is already open!";
return ERR_UNEXPECTED;
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index c92ce9f..a0500c1 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -54,7 +54,7 @@ TEST_F(FileStreamTest, BasicOpenClose) {
base::PlatformFile file = base::kInvalidPlatformFileValue;
{
FileStream stream(NULL);
- int rv = stream.Open(temp_file_path(),
+ int rv = stream.OpenSync(temp_file_path(),
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
EXPECT_EQ(OK, rv);
EXPECT_TRUE(stream.IsOpen());
@@ -108,7 +108,7 @@ TEST_F(FileStreamTest, UseFileHandle) {
ASSERT_EQ(kTestDataSize,
read_stream.Read(buffer, kTestDataSize, CompletionCallback()));
ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize));
- read_stream.Close();
+ read_stream.CloseSync();
// 2. Test writing with a file handle.
file_util::Delete(temp_file_path(), false);
@@ -119,7 +119,7 @@ TEST_F(FileStreamTest, UseFileHandle) {
ASSERT_EQ(0, write_stream.Seek(FROM_BEGIN, 0));
ASSERT_EQ(kTestDataSize,
write_stream.Write(kTestData, kTestDataSize, CompletionCallback()));
- write_stream.Close();
+ write_stream.CloseSync();
// Read into buffer and compare to make sure the handle worked fine.
ASSERT_EQ(kTestDataSize,
@@ -154,7 +154,7 @@ TEST_F(FileStreamTest, BasicRead) {
FileStream stream(NULL);
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -185,7 +185,7 @@ TEST_F(FileStreamTest, AsyncRead) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -220,7 +220,7 @@ TEST_F(FileStreamTest, AsyncRead_EarlyClose) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -230,7 +230,7 @@ TEST_F(FileStreamTest, AsyncRead_EarlyClose) {
char buf[4];
rv = stream.Read(buf, arraysize(buf), callback.callback());
- stream.Close();
+ stream.CloseSync();
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
@@ -249,7 +249,7 @@ TEST_F(FileStreamTest, BasicRead_FromOffset) {
FileStream stream(NULL);
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
const int64 kOffset = 3;
@@ -285,7 +285,7 @@ TEST_F(FileStreamTest, AsyncRead_FromOffset) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
const int64 kOffset = 3;
@@ -319,7 +319,7 @@ TEST_F(FileStreamTest, SeekAround) {
FileStream stream(NULL);
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
const int64 kOffset = 3;
@@ -342,7 +342,7 @@ TEST_F(FileStreamTest, BasicWrite) {
FileStream stream(NULL);
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 file_size;
@@ -352,7 +352,7 @@ TEST_F(FileStreamTest, BasicWrite) {
rv = stream.Write(kTestData, kTestDataSize, CompletionCallback());
EXPECT_EQ(kTestDataSize, rv);
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -364,7 +364,7 @@ TEST_F(FileStreamTest, AsyncWrite) {
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 file_size;
@@ -396,7 +396,7 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyClose) {
int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 file_size;
@@ -410,7 +410,7 @@ TEST_F(FileStreamTest, AsyncWrite_EarlyClose) {
rv = stream.Write(kTestData + total_bytes_written,
kTestDataSize - total_bytes_written,
callback.callback());
- stream.Close();
+ stream.CloseSync();
if (rv < 0) {
EXPECT_EQ(ERR_IO_PENDING, rv);
// The callback should not be called if the request is cancelled.
@@ -427,7 +427,7 @@ TEST_F(FileStreamTest, BasicWrite_FromOffset) {
FileStream stream(NULL);
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 file_size;
@@ -441,7 +441,7 @@ TEST_F(FileStreamTest, BasicWrite_FromOffset) {
rv = stream.Write(kTestData, kTestDataSize, CompletionCallback());
EXPECT_EQ(kTestDataSize, rv);
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -457,7 +457,7 @@ TEST_F(FileStreamTest, AsyncWrite_FromOffset) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
const int64 kOffset = 0;
@@ -492,7 +492,7 @@ TEST_F(FileStreamTest, BasicReadWrite) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -515,7 +515,7 @@ TEST_F(FileStreamTest, BasicReadWrite) {
rv = stream.Write(kTestData, kTestDataSize, CompletionCallback());
EXPECT_EQ(kTestDataSize, rv);
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -531,7 +531,7 @@ TEST_F(FileStreamTest, BasicWriteRead) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -558,7 +558,7 @@ TEST_F(FileStreamTest, BasicWriteRead) {
total_bytes_read += rv;
data_read.append(buf, rv);
}
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -580,7 +580,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) {
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -618,7 +618,7 @@ TEST_F(FileStreamTest, BasicAsyncReadWrite) {
total_bytes_written += rv;
}
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -635,7 +635,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) {
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -678,7 +678,7 @@ TEST_F(FileStreamTest, BasicAsyncWriteRead) {
total_bytes_read += rv;
data_read.append(buf, rv);
}
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -790,7 +790,7 @@ TEST_F(FileStreamTest, AsyncWriteRead) {
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -813,7 +813,7 @@ TEST_F(FileStreamTest, AsyncWriteRead) {
EXPECT_LT(0, rv);
EXPECT_EQ(kTestDataSize, total_bytes_written);
- stream.Close();
+ stream.CloseSync();
ok = file_util::GetFileSize(temp_file_path(), &file_size);
EXPECT_TRUE(ok);
@@ -867,7 +867,7 @@ class TestWriteCloseCompletionCallback {
rv = callback.WaitForResult();
*total_bytes_written_ += total_bytes_written;
} else { // We're done writing all data. Close the file.
- stream_->Close();
+ stream_->CloseSync();
}
result_ = *total_bytes_written_;
@@ -896,7 +896,7 @@ TEST_F(FileStreamTest, AsyncWriteClose) {
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_WRITE |
base::PLATFORM_FILE_ASYNC;
- int rv = stream.Open(temp_file_path(), flags);
+ int rv = stream.OpenSync(temp_file_path(), flags);
EXPECT_EQ(OK, rv);
int64 total_bytes_avail = stream.Available();
@@ -924,7 +924,7 @@ TEST_F(FileStreamTest, Truncate) {
int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE;
FileStream write_stream(NULL);
- ASSERT_EQ(OK, write_stream.Open(temp_file_path(), flags));
+ ASSERT_EQ(OK, write_stream.OpenSync(temp_file_path(), flags));
// Write some data to the file.
const char test_data[] = "0123456789";
@@ -937,7 +937,7 @@ TEST_F(FileStreamTest, Truncate) {
write_stream.Write(test_data, 4, CompletionCallback());
// Close the stream.
- write_stream.Close();
+ write_stream.CloseSync();
// Read in the contents and make sure we get back what we expected.
std::string read_contents;
diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc
index 9e1f686f..425a3f7 100644
--- a/net/base/file_stream_win.cc
+++ b/net/base/file_stream_win.cc
@@ -169,12 +169,12 @@ FileStream::FileStream(base::PlatformFile file, int flags, net::NetLog* net_log)
FileStream::~FileStream() {
if (auto_closed_)
- Close();
+ CloseSync();
bound_net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL);
}
-void FileStream::Close() {
+void FileStream::CloseSync() {
bound_net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL);
if (file_ != INVALID_HANDLE_VALUE)
CancelIo(file_);
@@ -189,7 +189,7 @@ void FileStream::Close() {
}
}
-int FileStream::Open(const FilePath& path, int open_flags) {
+int FileStream::OpenSync(const FilePath& path, int open_flags) {
if (IsOpen()) {
DLOG(FATAL) << "File is already open!";
return ERR_UNEXPECTED;
diff --git a/net/base/mock_file_stream.cc b/net/base/mock_file_stream.cc
index cb59cf9..afca747 100644
--- a/net/base/mock_file_stream.cc
+++ b/net/base/mock_file_stream.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,9 +8,9 @@ namespace net {
namespace testing {
-int MockFileStream::Open(const FilePath& path, int open_flags) {
+int MockFileStream::OpenSync(const FilePath& path, int open_flags) {
path_ = path;
- return ReturnError(FileStream::Open(path, open_flags));
+ return ReturnError(FileStream::OpenSync(path, open_flags));
}
int64 MockFileStream::Seek(Whence whence, int64 offset) {
diff --git a/net/base/mock_file_stream.h b/net/base/mock_file_stream.h
index d8a56d7..f07785a 100644
--- a/net/base/mock_file_stream.h
+++ b/net/base/mock_file_stream.h
@@ -27,7 +27,7 @@ class MockFileStream : public net::FileStream {
: net::FileStream(file, flags, net_log), forced_error_(net::OK) {}
// FileStream methods.
- virtual int Open(const FilePath& path, int open_flags) OVERRIDE;
+ virtual int OpenSync(const FilePath& path, int open_flags) OVERRIDE;
virtual int64 Seek(net::Whence whence, int64 offset) OVERRIDE;
virtual int64 Available() OVERRIDE;
virtual int Read(char* buf,
diff --git a/net/base/upload_data.cc b/net/base/upload_data.cc
index 908fb2d..bffe13b 100644
--- a/net/base/upload_data.cc
+++ b/net/base/upload_data.cc
@@ -31,7 +31,7 @@ UploadData::Element::~Element() {
if (file_stream_) {
// Temporarily allow until fix: http://crbug.com/72001.
base::ThreadRestrictions::ScopedAllowIO allow_io;
- file_stream_->Close();
+ file_stream_->CloseSync();
delete file_stream_;
}
}
@@ -107,8 +107,9 @@ FileStream* UploadData::Element::NewFileStreamForReading() {
base::ThreadRestrictions::ScopedAllowIO allow_io;
scoped_ptr<FileStream> file(new FileStream(NULL));
- int64 rv = file->Open(file_path_,
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
+ int64 rv = file->OpenSync(
+ file_path_,
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
if (rv != OK) {
// If the file can't be opened, we'll just upload an empty file.
DLOG(WARNING) << "Failed to open \"" << file_path_.value()
diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc
index 937ee09..cee54c7 100644
--- a/net/base/upload_data_stream.cc
+++ b/net/base/upload_data_stream.cc
@@ -154,7 +154,7 @@ void UploadDataStream::AdvanceToNextElement() {
if (element_file_stream_.get()) {
// Temporarily allow until fix: http://crbug.com/72001.
base::ThreadRestrictions::ScopedAllowIO allow_io;
- element_file_stream_->Close();
+ element_file_stream_->CloseSync();
element_file_stream_.reset();
}
}
diff --git a/net/tools/dump_cache/dump_files.cc b/net/tools/dump_cache/dump_files.cc
index 4fab6f2..f5656b0 100644
--- a/net/tools/dump_cache/dump_files.cc
+++ b/net/tools/dump_cache/dump_files.cc
@@ -27,7 +27,7 @@ const wchar_t kDataPrefix[] = L"data_";
// Reads the |header_size| bytes from the beginning of file |name|.
bool ReadHeader(const std::wstring& name, char* header, int header_size) {
net::FileStream file(NULL);
- file.Open(FilePath::FromWStringHack(name),
+ file.OpenSync(FilePath::FromWStringHack(name),
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
if (!file.IsOpen()) {
printf("Unable to open file %ls\n", name.c_str());
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 8f32750..fa6d6a2 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -161,7 +161,7 @@ void URLRequestFileJob::Kill() {
// URL requests should not block on the disk!
// http://code.google.com/p/chromium/issues/detail?id=59849
base::ThreadRestrictions::ScopedAllowIO allow_io;
- stream_.Close();
+ stream_.CloseSync();
if (async_resolver_) {
async_resolver_->Cancel();
@@ -313,7 +313,7 @@ void URLRequestFileJob::DidResolve(
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
- rv = stream_.Open(file_path_, flags);
+ rv = stream_.OpenSync(file_path_, flags);
}
if (rv != OK) {