0

Change FileStream to use FilePath instead of wstring.

Review URL: http://codereview.chromium.org/18764

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8663 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
erikkay@google.com
2009-01-26 21:38:11 +00:00
parent 25a873babf
commit 07167e8f26
8 changed files with 19 additions and 14 deletions

@ -4,6 +4,7 @@
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/platform_file.h"
@ -71,7 +72,7 @@ const size_t kIndentSize = 4;
// Class responsible for the actual writing.
class Writer : public Task {
public:
Writer(Value* bookmarks, const std::wstring& path)
Writer(Value* bookmarks, const FilePath& path)
: bookmarks_(bookmarks),
path_(path) {
}
@ -300,7 +301,7 @@ class Writer : public Task {
scoped_ptr<Value> bookmarks_;
// Path we're writing to.
std::wstring path_;
FilePath path_;
// File we're writing to.
net::FileStream file_stream_;
@ -319,7 +320,8 @@ void WriteBookmarks(MessageLoop* thread,
// for the duration of the write), as such we make a copy of the
// BookmarkModel using BookmarkCodec then write from that.
BookmarkCodec codec;
scoped_ptr<Writer> writer(new Writer(codec.Encode(model), path));
scoped_ptr<Writer> writer(new Writer(codec.Encode(model),
FilePath::FromWStringHack(path)));
if (thread)
thread->PostTask(FROM_HERE, writer.release());
else

@ -62,7 +62,7 @@ static bool ExtractCurrentFile(unzFile zip_file,
net::FileStream stream;
int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE;
if (stream.Open(dest_file.ToWStringHack(), flags) != 0)
if (stream.Open(dest_file, flags) != 0)
return false;
bool ret = true;

@ -10,6 +10,7 @@
#ifndef NET_BASE_FILE_STREAM_H_
#define NET_BASE_FILE_STREAM_H_
#include "base/file_path.h"
#include "base/platform_file.h"
#include "net/base/completion_callback.h"
@ -37,7 +38,7 @@ class FileStream {
// 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
int Open(const std::wstring& path, int open_flags);
int Open(const FilePath& path, int open_flags);
// Returns true if Open succeeded and Close has not been called.
bool IsOpen() const;

@ -74,14 +74,14 @@ static int64 MapErrorCode(int err) {
}
}
int FileStream::Open(const std::wstring& path, int open_flags) {
int FileStream::Open(const FilePath& path, int open_flags) {
if (IsOpen()) {
DLOG(FATAL) << "File is already open!";
return ERR_UNEXPECTED;
}
open_flags_ = open_flags;
file_ = base::CreatePlatformFile(path, open_flags_, NULL);
file_ = base::CreatePlatformFile(path.ToWStringHack(), open_flags_, NULL);
if (file_ == base::kInvalidPlatformFileValue) {
LOG(WARNING) << "Failed to open file: " << errno;
return MapErrorCode(errno);

@ -19,16 +19,17 @@ class FileStreamTest : public PlatformTest {
PlatformTest::SetUp();
file_util::CreateTemporaryFileName(&temp_file_path_);
file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize);
file_util::WriteFile(temp_file_path_.ToWStringHack(),
kTestData, kTestDataSize);
}
virtual void TearDown() {
file_util::Delete(temp_file_path_, false);
PlatformTest::TearDown();
}
const std::wstring temp_file_path() const { return temp_file_path_; }
const FilePath temp_file_path() const { return temp_file_path_; }
private:
std::wstring temp_file_path_;
FilePath temp_file_path_;
};
TEST_F(FileStreamTest, BasicOpenClose) {

@ -125,14 +125,14 @@ void FileStream::Close() {
}
}
int FileStream::Open(const std::wstring& path, int open_flags) {
int FileStream::Open(const FilePath& path, int open_flags) {
if (IsOpen()) {
DLOG(FATAL) << "File is already open!";
return ERR_UNEXPECTED;
}
open_flags_ = open_flags;
file_ = base::CreatePlatformFile(path, open_flags_, NULL);
file_ = base::CreatePlatformFile(path.value(), open_flags_, NULL);
if (file_ == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
LOG(WARNING) << "Failed to open file: " << error;

@ -65,7 +65,8 @@ void UploadDataStream::FillBuf() {
if (!next_element_stream_.IsOpen()) {
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ;
int rv = next_element_stream_.Open(element.file_path(), flags);
int rv = next_element_stream_.Open(
FilePath::FromWStringHack(element.file_path()), flags);
// If the file does not exist, that's technically okay.. we'll just
// upload an empty file. This is for consistency with Mozilla.
DLOG_IF(WARNING, rv != OK) << "Failed to open \"" <<

@ -172,7 +172,7 @@ void URLRequestFileJob::DidResolve(
int flags = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_READ |
base::PLATFORM_FILE_ASYNC;
rv = stream_.Open(file_path_.ToWStringHack(), flags);
rv = stream_.Open(file_path_, flags);
}
if (rv == net::OK) {