Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
index 7f75a630fface7dc5dbfea47b93447b4d1a1ebf2..cf68bf5c102bb1abac116077755c33424872e7cf 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
@@ -4168,4 +4168,86 @@ void GDataFileSystem::OnCloseFileFinished( |
callback.Run(result); |
} |
+void GDataFileSystem::PrepareWritableFileAndRun( |
+ const FilePath& file_path, |
+ const OpenFileCallback& callback) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
+ BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ RunTaskOnUIThread( |
+ base::Bind(&GDataFileSystem::PrepareWritableFileAndRunOnUIThread, |
+ ui_weak_ptr_, |
+ file_path, |
+ callback)); |
+} |
+ |
+void GDataFileSystem::PrepareWritableFileAndRunOnUIThread( |
+ const FilePath& file_path, |
+ const OpenFileCallback& callback) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ CreateFileOnUIThread( |
+ file_path, |
+ false, // it is not an error, even if the path already exists. |
+ base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterCreateFile, |
+ ui_weak_ptr_, |
+ file_path, |
+ callback)); |
+} |
+ |
+void GDataFileSystem::PrepareWritableFileAndRunAfterCreateFile( |
+ const FilePath& file_path, |
+ const OpenFileCallback& callback, |
+ GDataFileError result) { |
satorux1
2012/07/27 22:56:29
result -> error
kinaba
2012/08/01 13:48:45
Done.
|
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (result != gdata::GDATA_FILE_OK) { |
+ if (!callback.is_null()) { |
+ content::BrowserThread::GetBlockingPool()->PostTask( |
+ FROM_HERE, |
+ base::Bind(callback, result, FilePath())); |
satorux1
2012/07/27 22:56:29
we should just run the callback here.
PostTask sh
kinaba
2012/08/01 13:48:45
This is not a PostTask to the current thread, it i
|
+ } |
+ return; |
+ } |
+ OpenFileOnUIThread( |
+ file_path, |
+ base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterOpenFile, |
+ ui_weak_ptr_, |
+ file_path, |
+ callback)); |
+} |
+ |
+void GDataFileSystem::PrepareWritableFileAndRunAfterOpenFile( |
+ const FilePath& file_path, |
+ const OpenFileCallback& callback, |
+ GDataFileError result, |
satorux1
2012/07/27 22:56:29
error
kinaba
2012/08/01 13:48:45
Done.
|
+ const FilePath& local_cache_path) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (result != gdata::GDATA_FILE_OK) { |
+ if (!callback.is_null()) { |
+ content::BrowserThread::GetBlockingPool()->PostTask( |
satorux1
2012/07/27 22:56:29
ditto
kinaba
2012/08/01 13:48:45
See the reply above.
|
+ FROM_HERE, |
+ base::Bind(callback, result, FilePath())); |
+ } |
+ return; |
+ } |
+ |
+ if (!callback.is_null()) { |
+ content::BrowserThread::GetBlockingPool()->PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(callback, GDATA_FILE_OK, local_cache_path), |
+ base::Bind(&GDataFileSystem::PrepareWritableFileAndRunAfterCallback, |
+ ui_weak_ptr_, |
+ file_path)); |
+ } else { |
+ PrepareWritableFileAndRunAfterCallback(file_path); |
+ } |
+} |
+ |
+void GDataFileSystem::PrepareWritableFileAndRunAfterCallback( |
+ const FilePath& file_path) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ CloseFileOnUIThread(file_path, FileOperationCallback()); |
+} |
+ |
} // namespace gdata |