| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/gdata/file_write_helper.h" | 5 #include "chrome/browser/chromeos/gdata/file_write_helper.h" |
| 6 | 6 |
| 7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 | 9 |
| 10 using content::BrowserThread; | 10 using content::BrowserThread; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 false, // it is not an error, even if the path already exists. | 33 false, // it is not an error, even if the path already exists. |
| 34 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile, | 34 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile, |
| 35 weak_ptr_factory_.GetWeakPtr(), | 35 weak_ptr_factory_.GetWeakPtr(), |
| 36 file_path, | 36 file_path, |
| 37 callback)); | 37 callback)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile( | 40 void FileWriteHelper::PrepareWritableFileAndRunAfterCreateFile( |
| 41 const FilePath& file_path, | 41 const FilePath& file_path, |
| 42 const OpenFileCallback& callback, | 42 const OpenFileCallback& callback, |
| 43 GDataFileError error) { | 43 DriveFileError error) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 45 | 45 |
| 46 if (error != gdata::GDATA_FILE_OK) { | 46 if (error != gdata::DRIVE_FILE_OK) { |
| 47 if (!callback.is_null()) { | 47 if (!callback.is_null()) { |
| 48 content::BrowserThread::GetBlockingPool()->PostTask( | 48 content::BrowserThread::GetBlockingPool()->PostTask( |
| 49 FROM_HERE, | 49 FROM_HERE, |
| 50 base::Bind(callback, error, FilePath())); | 50 base::Bind(callback, error, FilePath())); |
| 51 } | 51 } |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 file_system_->OpenFile( | 54 file_system_->OpenFile( |
| 55 file_path, | 55 file_path, |
| 56 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile, | 56 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile, |
| 57 weak_ptr_factory_.GetWeakPtr(), | 57 weak_ptr_factory_.GetWeakPtr(), |
| 58 file_path, | 58 file_path, |
| 59 callback)); | 59 callback)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile( | 62 void FileWriteHelper::PrepareWritableFileAndRunAfterOpenFile( |
| 63 const FilePath& file_path, | 63 const FilePath& file_path, |
| 64 const OpenFileCallback& callback, | 64 const OpenFileCallback& callback, |
| 65 GDataFileError error, | 65 DriveFileError error, |
| 66 const FilePath& local_cache_path) { | 66 const FilePath& local_cache_path) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 68 | 68 |
| 69 if (error != gdata::GDATA_FILE_OK) { | 69 if (error != gdata::DRIVE_FILE_OK) { |
| 70 if (!callback.is_null()) { | 70 if (!callback.is_null()) { |
| 71 content::BrowserThread::GetBlockingPool()->PostTask( | 71 content::BrowserThread::GetBlockingPool()->PostTask( |
| 72 FROM_HERE, | 72 FROM_HERE, |
| 73 base::Bind(callback, error, FilePath())); | 73 base::Bind(callback, error, FilePath())); |
| 74 } | 74 } |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!callback.is_null()) { | 78 if (!callback.is_null()) { |
| 79 content::BrowserThread::GetBlockingPool()->PostTaskAndReply( | 79 content::BrowserThread::GetBlockingPool()->PostTaskAndReply( |
| 80 FROM_HERE, | 80 FROM_HERE, |
| 81 base::Bind(callback, GDATA_FILE_OK, local_cache_path), | 81 base::Bind(callback, DRIVE_FILE_OK, local_cache_path), |
| 82 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCallback, | 82 base::Bind(&FileWriteHelper::PrepareWritableFileAndRunAfterCallback, |
| 83 weak_ptr_factory_.GetWeakPtr(), | 83 weak_ptr_factory_.GetWeakPtr(), |
| 84 file_path)); | 84 file_path)); |
| 85 } else { | 85 } else { |
| 86 PrepareWritableFileAndRunAfterCallback(file_path); | 86 PrepareWritableFileAndRunAfterCallback(file_path); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void FileWriteHelper::PrepareWritableFileAndRunAfterCallback( | 90 void FileWriteHelper::PrepareWritableFileAndRunAfterCallback( |
| 91 const FilePath& file_path) { | 91 const FilePath& file_path) { |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 93 file_system_->CloseFile(file_path, FileOperationCallback()); | 93 file_system_->CloseFile(file_path, FileOperationCallback()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace gdata | 96 } // namespace gdata |
| OLD | NEW |