diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 04:08:41 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-15 04:08:41 +0000 |
commit | 6b230f4db95ebe798a6cec0045322e562065aef5 (patch) | |
tree | fedc9447bfb327132682cdafe95451bf86764bd1 /chrome | |
parent | 9f5dd1d37b5b0496fc4815f7c0c4b84a9f606985 (diff) | |
download | chromium_src-6b230f4db95ebe798a6cec0045322e562065aef5.zip chromium_src-6b230f4db95ebe798a6cec0045322e562065aef5.tar.gz chromium_src-6b230f4db95ebe798a6cec0045322e562065aef5.tar.bz2 |
net: Split FileStream::Read/Write() into sync and async versions.
Historically, FileStream::Read/Write() used to take NULL for synchronous
operations, but these are replaced with ComplocationCallback(), which
is rather ugly. ReadSync() and WriteSync() which do not take a
CompletionCallback are introduced for synchronous operations.
Having function separate signatures make clients code cleaner,
and easier to catch synchronous operations on wrong threads.
This convention also matches with Open/OpenSync and Close/CloseSync.
BUG=72001
TEST=try bots.
Review URL: https://chromiumcodereview.appspot.com/9365024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_html_writer.cc | 3 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/bloom_filter.cc | 27 | ||||
-rw-r--r-- | chrome/browser/sessions/session_backend.cc | 16 | ||||
-rw-r--r-- | chrome/common/zip.cc | 3 | ||||
-rw-r--r-- | chrome/common/zip_reader.cc | 3 |
5 files changed, 24 insertions, 28 deletions
diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index 5a6d670..2e9376e 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -189,8 +189,7 @@ class Writer : public base::RefCountedThreadSafe<Writer> { // Writes raw text out returning true on success. This does not escape // the text in anyway. bool Write(const std::string& text) { - size_t wrote = file_stream_.Write(text.c_str(), text.length(), - net::CompletionCallback()); + size_t wrote = file_stream_.WriteSync(text.c_str(), text.length()); bool result = (wrote == text.length()); DCHECK(result); return result; diff --git a/chrome/browser/safe_browsing/bloom_filter.cc b/chrome/browser/safe_browsing/bloom_filter.cc index 6f928b5..859d320 100644 --- a/chrome/browser/safe_browsing/bloom_filter.cc +++ b/chrome/browser/safe_browsing/bloom_filter.cc @@ -99,8 +99,8 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { // Make sure we have a file version that we can understand. int file_version; - int bytes_read = filter.Read(reinterpret_cast<char*>(&file_version), - sizeof(file_version), net::CompletionCallback()); + int bytes_read = filter.ReadSync(reinterpret_cast<char*>(&file_version), + sizeof(file_version)); if (bytes_read != sizeof(file_version) || file_version != kFileVersion) { RecordFailure(FAILURE_FILTER_READ_VERSION); return NULL; @@ -108,8 +108,8 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { // Get all the random hash keys. int num_keys; - bytes_read = filter.Read(reinterpret_cast<char*>(&num_keys), - sizeof(num_keys), net::CompletionCallback()); + bytes_read = filter.ReadSync(reinterpret_cast<char*>(&num_keys), + sizeof(num_keys)); if (bytes_read != sizeof(num_keys) || num_keys < 1 || num_keys > kNumHashKeys) { RecordFailure(FAILURE_FILTER_READ_NUM_KEYS); @@ -119,8 +119,7 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { HashKeys hash_keys; for (int i = 0; i < num_keys; ++i) { HashKey key; - bytes_read = filter.Read( - reinterpret_cast<char*>(&key), sizeof(key), net::CompletionCallback()); + bytes_read = filter.ReadSync(reinterpret_cast<char*>(&key), sizeof(key)); if (bytes_read != sizeof(key)) { RecordFailure(FAILURE_FILTER_READ_KEY); return NULL; @@ -140,7 +139,7 @@ BloomFilter* BloomFilter::LoadFile(const FilePath& filter_name) { int byte_size = static_cast<int>(remaining64); scoped_array<char> data(new char[byte_size]); - bytes_read = filter.Read(data.get(), byte_size, net::CompletionCallback()); + bytes_read = filter.ReadSync(data.get(), byte_size); if (bytes_read < byte_size) { RecordFailure(FAILURE_FILTER_READ_DATA_SHORT); return NULL; @@ -163,29 +162,29 @@ bool BloomFilter::WriteFile(const FilePath& filter_name) const { // Write the version information. int version = kFileVersion; - int bytes_written = filter.Write(reinterpret_cast<char*>(&version), - sizeof(version), net::CompletionCallback()); + int bytes_written = filter.WriteSync(reinterpret_cast<char*>(&version), + sizeof(version)); if (bytes_written != sizeof(version)) return false; // Write the number of random hash keys. int num_keys = static_cast<int>(hash_keys_.size()); - bytes_written = filter.Write(reinterpret_cast<char*>(&num_keys), - sizeof(num_keys), net::CompletionCallback()); + bytes_written = filter.WriteSync(reinterpret_cast<char*>(&num_keys), + sizeof(num_keys)); if (bytes_written != sizeof(num_keys)) return false; for (int i = 0; i < num_keys; ++i) { bytes_written = - filter.Write(reinterpret_cast<const char*>(&hash_keys_[i]), - sizeof(hash_keys_[i]), net::CompletionCallback()); + filter.WriteSync(reinterpret_cast<const char*>(&hash_keys_[i]), + sizeof(hash_keys_[i])); if (bytes_written != sizeof(hash_keys_[i])) return false; } // Write the filter data. bytes_written = - filter.Write(data_.get(), byte_size_, net::CompletionCallback()); + filter.WriteSync(data_.get(), byte_size_); if (bytes_written != byte_size_) return false; diff --git a/chrome/browser/sessions/session_backend.cc b/chrome/browser/sessions/session_backend.cc index 419678e..8a17036 100644 --- a/chrome/browser/sessions/session_backend.cc +++ b/chrome/browser/sessions/session_backend.cc @@ -318,22 +318,22 @@ bool SessionBackend::AppendCommandsToFile(net::FileStream* file, UMA_HISTOGRAM_COUNTS("TabRestore.command_size", total_size); else UMA_HISTOGRAM_COUNTS("SessionRestore.command_size", total_size); - wrote = file->Write(reinterpret_cast<const char*>(&total_size), - sizeof(total_size), net::CompletionCallback()); + wrote = file->WriteSync(reinterpret_cast<const char*>(&total_size), + sizeof(total_size)); if (wrote != sizeof(total_size)) { NOTREACHED() << "error writing"; return false; } id_type command_id = (*i)->id(); - wrote = file->Write(reinterpret_cast<char*>(&command_id), - sizeof(command_id), net::CompletionCallback()); + wrote = file->WriteSync(reinterpret_cast<char*>(&command_id), + sizeof(command_id)); if (wrote != sizeof(command_id)) { NOTREACHED() << "error writing"; return false; } if (content_size > 0) { - wrote = file->Write(reinterpret_cast<char*>((*i)->contents()), - content_size, net::CompletionCallback()); + wrote = file->WriteSync(reinterpret_cast<char*>((*i)->contents()), + content_size); if (wrote != content_size) { NOTREACHED() << "error writing"; return false; @@ -378,8 +378,8 @@ net::FileStream* SessionBackend::OpenAndWriteHeader(const FilePath& path) { FileHeader header; header.signature = kFileSignature; header.version = kFileCurrentVersion; - int wrote = file->Write(reinterpret_cast<char*>(&header), - sizeof(header), net::CompletionCallback()); + int wrote = file->WriteSync(reinterpret_cast<char*>(&header), + sizeof(header)); if (wrote != sizeof(header)) return NULL; return file.release(); diff --git a/chrome/common/zip.cc b/chrome/common/zip.cc index 1da9cff..ef50ead 100644 --- a/chrome/common/zip.cc +++ b/chrome/common/zip.cc @@ -29,8 +29,7 @@ bool AddFileToZip(zipFile zip_file, const FilePath& src_dir) { int num_bytes; char buf[zip::internal::kZipBufSize]; do { - num_bytes = stream.Read(buf, zip::internal::kZipBufSize, - net::CompletionCallback()); + num_bytes = stream.ReadSync(buf, zip::internal::kZipBufSize); if (num_bytes > 0) { if (ZIP_OK != zipWriteInFileInZip(zip_file, buf, num_bytes)) { DLOG(ERROR) << "Could not write data to zip for path " diff --git a/chrome/common/zip_reader.cc b/chrome/common/zip_reader.cc index c89ce29..898654bc 100644 --- a/chrome/common/zip_reader.cc +++ b/chrome/common/zip_reader.cc @@ -210,8 +210,7 @@ bool ZipReader::ExtractCurrentEntryToFilePath( break; } else if (num_bytes_read > 0) { // Some data is read. Write it to the output file. - if (num_bytes_read != stream.Write(buf, num_bytes_read, - net::CompletionCallback())) { + if (num_bytes_read != stream.WriteSync(buf, num_bytes_read)) { success = false; break; } |