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

Unified Diff: chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc

Issue 389893002: [fsp] Add support for creating files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 5 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: chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc
diff --git a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc
index c88414ce729fcc90d3ddcb4ce6531915b10bd9c6..0c1e2fc676a7439410bc51cd3c5b2f64f622acda 100644
--- a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc
+++ b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc
@@ -129,6 +129,36 @@ void OnDeleteEntry(const fileapi::AsyncFileUtil::StatusCallback& callback,
BrowserThread::IO, FROM_HERE, base::Bind(callback, result));
}
+// Executes CreateFile on the UI thread.
+void CreateFileOnUIThread(
+ scoped_ptr<fileapi::FileSystemOperationContext> context,
+ const fileapi::FileSystemURL& url,
+ const fileapi::AsyncFileUtil::StatusCallback& callback) {
+ util::FileSystemURLParser parser(url);
+ if (!parser.Parse()) {
+ callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
+ return;
+ }
+
+ parser.file_system()->CreateFile(parser.file_path(), callback);
+}
+
+// Routes the response of CreateFile to a callback of EnsureFileExists() on the
+// IO thread.
+void OnCreateFileForEnsureFileExists(
+ const fileapi::AsyncFileUtil::EnsureFileExistsCallback& callback,
+ base::File::Error result) {
+ const bool created = result == base::File::FILE_OK;
+
+ // If the file already existed, then return success anyway, since it is not
+ // an error.
+ const base::File::Error error =
+ result == base::File::FILE_ERROR_EXISTS ? base::File::FILE_OK : result;
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(callback, error, created));
+}
+
} // namespace
ProviderAsyncFileUtil::ProviderAsyncFileUtil() {}
@@ -160,7 +190,13 @@ void ProviderAsyncFileUtil::EnsureFileExists(
const fileapi::FileSystemURL& url,
const EnsureFileExistsCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- callback.Run(base::File::FILE_ERROR_ACCESS_DENIED, false /* created */);
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&CreateFileOnUIThread,
+ base::Passed(&context),
+ url,
+ base::Bind(&OnCreateFileForEnsureFileExists, callback)));
}
void ProviderAsyncFileUtil::CreateDirectory(

Powered by Google App Engine
This is Rietveld 408576698