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

Unified Diff: components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc

Issue 1634293002: mojo filesystem: Simplify full file reading/writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Further cleanup of pref store. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc
diff --git a/components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc b/components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc
index d80a34ffd77247491b3d22978952aebdd844a429..26d9dbd1704ef53d9176650c08eb34fe00fe1de0 100644
--- a/components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc
+++ b/components/filesystem/public/cpp/prefs/filesystem_json_pref_store.cc
@@ -345,17 +345,6 @@ void FilesystemJsonPrefStore::OnOpenFilesystem(base::Closure callback,
}
void FilesystemJsonPrefStore::OnTempFileWriteStart() {
- // Open up a temporary file and truncate it.
- directory_->OpenFile(
- "tmp", GetProxy(&temporary_file_), kFlagWrite | kFlagCreate,
- Bind(&FilesystemJsonPrefStore::OnTempFileOpened, AsWeakPtr()));
-}
-
-void FilesystemJsonPrefStore::OnTempFileOpened(FileError err) {
- // TODO(erg): Error handling. The JsonPrefStore code assumes that writing the
- // file can never fail.
- CHECK_EQ(FileError::OK, err);
-
// Calculate what we want to write, and then write to the temporary file.
pending_lossy_write_ = false;
@@ -367,50 +356,30 @@ void FilesystemJsonPrefStore::OnTempFileOpened(FileError err) {
serializer.set_pretty_print(false);
serializer.Serialize(*prefs_);
- temporary_file_->Write(
- mojo::Array<uint8_t>::From(output), 0, Whence::FROM_CURRENT,
+ directory_->WriteFile(
+ "tmp",
+ mojo::Array<uint8_t>::From(output),
Bind(&FilesystemJsonPrefStore::OnTempFileWrite, AsWeakPtr()));
}
-void FilesystemJsonPrefStore::OnTempFileWrite(FileError err,
- uint32_t num_bytes_written) {
+void FilesystemJsonPrefStore::OnTempFileWrite(FileError err) {
// TODO(erg): Error handling. The JsonPrefStore code assumes that writing the
// file can never fail.
CHECK_EQ(FileError::OK, err);
- // Now that we've written the file, close it.
- temporary_file_->Close(
- Bind(&FilesystemJsonPrefStore::OnTempFileClosed, AsWeakPtr()));
-}
-
-void FilesystemJsonPrefStore::OnTempFileClosed(FileError err) {
- // TODO(erg): Error handling. The JsonPrefStore code assumes that writing the
- // file can never fail.
- CHECK_EQ(FileError::OK, err);
-
- temporary_file_.reset();
directory_->Rename(
"tmp", path_,
Bind(&FilesystemJsonPrefStore::OnTempFileRenamed, AsWeakPtr()));
}
-void FilesystemJsonPrefStore::OnTempFileRenamed(FileError err) {}
-
-void FilesystemJsonPrefStore::OnPreferencesReadStart() {
- // TODO(erg): implement me.
- directory_->OpenFile(
- path_, GetProxy(&preferences_file_), kFlagRead | kFlagOpen,
- Bind(&FilesystemJsonPrefStore::OnPreferencesFileOpened, AsWeakPtr()));
+void FilesystemJsonPrefStore::OnTempFileRenamed(FileError err) {
+ CHECK_EQ(FileError::OK, err);
sky 2016/01/27 01:08:40 Seems like we shouldn't crash here, but have some
Elliot Glaysher 2016/01/27 01:13:42 There's no real error checking here because there'
sky 2016/01/27 02:48:13 Error checking is different than crashing if there
}
-void FilesystemJsonPrefStore::OnPreferencesFileOpened(FileError err) {
- // TODO(erg): Error handling.
- if (err == FileError::OK) {
- preferences_file_->ReadEntireFile(
- Bind(&FilesystemJsonPrefStore::OnPreferencesFileRead, AsWeakPtr()));
- } else {
- OnPreferencesFileRead(err, mojo::Array<uint8_t>());
- }
+void FilesystemJsonPrefStore::OnPreferencesReadStart() {
+ directory_->ReadEntireFile(
+ path_,
+ Bind(&FilesystemJsonPrefStore::OnPreferencesFileRead, AsWeakPtr()));
}
void FilesystemJsonPrefStore::OnPreferencesFileRead(
@@ -420,12 +389,13 @@ void FilesystemJsonPrefStore::OnPreferencesFileRead(
new FilesystemJsonPrefStore::ReadResult);
// TODO(erg): Needs even better error handling.
switch (err) {
+ case FileError::FAILED:
case FileError::IN_USE:
- case FileError::ACCESS_DENIED: {
+ case FileError::ACCESS_DENIED:
+ case FileError::NOT_A_FILE: {
read_only_ = true;
break;
}
- case FileError::FAILED:
case FileError::NOT_FOUND: {
// If the file just doesn't exist, maybe this is the first run. Just
// don't pass a value.
@@ -442,8 +412,6 @@ void FilesystemJsonPrefStore::OnPreferencesFileRead(
}
}
- preferences_file_.reset();
-
OnFileRead(std::move(read_result));
}

Powered by Google App Engine
This is Rietveld 408576698