| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/drive/file_system/get_file_for_saving_operatio
n.h" | 5 #include "chrome/browser/chromeos/drive/file_system/get_file_for_saving_operatio
n.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "chrome/browser/chromeos/drive/file_cache.h" | 10 #include "chrome/browser/chromeos/drive/file_cache.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 cache_(cache), | 62 cache_(cache), |
| 63 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 GetFileForSavingOperation::~GetFileForSavingOperation() { | 66 GetFileForSavingOperation::~GetFileForSavingOperation() { |
| 67 } | 67 } |
| 68 | 68 |
| 69 void GetFileForSavingOperation::GetFileForSaving( | 69 void GetFileForSavingOperation::GetFileForSaving( |
| 70 const base::FilePath& file_path, | 70 const base::FilePath& file_path, |
| 71 const GetFileCallback& callback) { | 71 const GetFileCallback& callback) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 73 DCHECK(!callback.is_null()); | 73 DCHECK(!callback.is_null()); |
| 74 | 74 |
| 75 create_file_operation_->CreateFile( | 75 create_file_operation_->CreateFile( |
| 76 file_path, | 76 file_path, |
| 77 false, // error_if_already_exists | 77 false, // error_if_already_exists |
| 78 std::string(), // no specific mime type | 78 std::string(), // no specific mime type |
| 79 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterCreate, | 79 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterCreate, |
| 80 weak_ptr_factory_.GetWeakPtr(), | 80 weak_ptr_factory_.GetWeakPtr(), |
| 81 file_path, | 81 file_path, |
| 82 callback)); | 82 callback)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void GetFileForSavingOperation::GetFileForSavingAfterCreate( | 85 void GetFileForSavingOperation::GetFileForSavingAfterCreate( |
| 86 const base::FilePath& file_path, | 86 const base::FilePath& file_path, |
| 87 const GetFileCallback& callback, | 87 const GetFileCallback& callback, |
| 88 FileError error) { | 88 FileError error) { |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 89 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 90 DCHECK(!callback.is_null()); | 90 DCHECK(!callback.is_null()); |
| 91 | 91 |
| 92 if (error != FILE_ERROR_OK) { | 92 if (error != FILE_ERROR_OK) { |
| 93 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 93 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 | 96 |
| 97 download_operation_->EnsureFileDownloadedByPath( | 97 download_operation_->EnsureFileDownloadedByPath( |
| 98 file_path, | 98 file_path, |
| 99 ClientContext(USER_INITIATED), | 99 ClientContext(USER_INITIATED), |
| 100 GetFileContentInitializedCallback(), | 100 GetFileContentInitializedCallback(), |
| 101 google_apis::GetContentCallback(), | 101 google_apis::GetContentCallback(), |
| 102 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterDownload, | 102 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterDownload, |
| 103 weak_ptr_factory_.GetWeakPtr(), | 103 weak_ptr_factory_.GetWeakPtr(), |
| 104 callback)); | 104 callback)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void GetFileForSavingOperation::GetFileForSavingAfterDownload( | 107 void GetFileForSavingOperation::GetFileForSavingAfterDownload( |
| 108 const GetFileCallback& callback, | 108 const GetFileCallback& callback, |
| 109 FileError error, | 109 FileError error, |
| 110 const base::FilePath& cache_path, | 110 const base::FilePath& cache_path, |
| 111 scoped_ptr<ResourceEntry> entry) { | 111 scoped_ptr<ResourceEntry> entry) { |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 DCHECK(!callback.is_null()); | 113 DCHECK(!callback.is_null()); |
| 114 | 114 |
| 115 if (error != FILE_ERROR_OK) { | 115 if (error != FILE_ERROR_OK) { |
| 116 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 116 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); |
| 117 return; | 117 return; |
| 118 } | 118 } |
| 119 | 119 |
| 120 const std::string& local_id = entry->local_id(); | 120 const std::string& local_id = entry->local_id(); |
| 121 ResourceEntry* entry_ptr = entry.get(); | 121 ResourceEntry* entry_ptr = entry.get(); |
| 122 scoped_ptr<base::ScopedClosureRunner>* file_closer = | 122 scoped_ptr<base::ScopedClosureRunner>* file_closer = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 base::Passed(&entry), | 137 base::Passed(&entry), |
| 138 base::Owned(file_closer))); | 138 base::Owned(file_closer))); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void GetFileForSavingOperation::GetFileForSavingAfterOpenForWrite( | 141 void GetFileForSavingOperation::GetFileForSavingAfterOpenForWrite( |
| 142 const GetFileCallback& callback, | 142 const GetFileCallback& callback, |
| 143 const base::FilePath& cache_path, | 143 const base::FilePath& cache_path, |
| 144 scoped_ptr<ResourceEntry> entry, | 144 scoped_ptr<ResourceEntry> entry, |
| 145 scoped_ptr<base::ScopedClosureRunner>* file_closer, | 145 scoped_ptr<base::ScopedClosureRunner>* file_closer, |
| 146 FileError error) { | 146 FileError error) { |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 147 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 148 DCHECK(!callback.is_null()); | 148 DCHECK(!callback.is_null()); |
| 149 | 149 |
| 150 if (error != FILE_ERROR_OK) { | 150 if (error != FILE_ERROR_OK) { |
| 151 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); | 151 callback.Run(error, base::FilePath(), scoped_ptr<ResourceEntry>()); |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 | 154 |
| 155 const std::string& local_id = entry->local_id(); | 155 const std::string& local_id = entry->local_id(); |
| 156 file_write_watcher_->StartWatch( | 156 file_write_watcher_->StartWatch( |
| 157 cache_path, | 157 cache_path, |
| 158 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterWatch, | 158 base::Bind(&GetFileForSavingOperation::GetFileForSavingAfterWatch, |
| 159 weak_ptr_factory_.GetWeakPtr(), | 159 weak_ptr_factory_.GetWeakPtr(), |
| 160 callback, | 160 callback, |
| 161 cache_path, | 161 cache_path, |
| 162 base::Passed(&entry)), | 162 base::Passed(&entry)), |
| 163 base::Bind(&GetFileForSavingOperation::OnWriteEvent, | 163 base::Bind(&GetFileForSavingOperation::OnWriteEvent, |
| 164 weak_ptr_factory_.GetWeakPtr(), | 164 weak_ptr_factory_.GetWeakPtr(), |
| 165 local_id, | 165 local_id, |
| 166 base::Passed(file_closer))); | 166 base::Passed(file_closer))); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void GetFileForSavingOperation::GetFileForSavingAfterWatch( | 169 void GetFileForSavingOperation::GetFileForSavingAfterWatch( |
| 170 const GetFileCallback& callback, | 170 const GetFileCallback& callback, |
| 171 const base::FilePath& cache_path, | 171 const base::FilePath& cache_path, |
| 172 scoped_ptr<ResourceEntry> entry, | 172 scoped_ptr<ResourceEntry> entry, |
| 173 bool success) { | 173 bool success) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 174 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 175 DCHECK(!callback.is_null()); | 175 DCHECK(!callback.is_null()); |
| 176 | 176 |
| 177 logger_->Log(logging::LOG_INFO, "Started watching modification to %s [%s].", | 177 logger_->Log(logging::LOG_INFO, "Started watching modification to %s [%s].", |
| 178 entry->local_id().c_str(), | 178 entry->local_id().c_str(), |
| 179 success ? "ok" : "fail"); | 179 success ? "ok" : "fail"); |
| 180 | 180 |
| 181 if (!success) { | 181 if (!success) { |
| 182 callback.Run(FILE_ERROR_FAILED, | 182 callback.Run(FILE_ERROR_FAILED, |
| 183 base::FilePath(), scoped_ptr<ResourceEntry>()); | 183 base::FilePath(), scoped_ptr<ResourceEntry>()); |
| 184 return; | 184 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 200 blocking_task_runner_->PostTask( | 200 blocking_task_runner_->PostTask( |
| 201 FROM_HERE, | 201 FROM_HERE, |
| 202 base::Bind(base::IgnoreResult( | 202 base::Bind(base::IgnoreResult( |
| 203 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor, | 203 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor, |
| 204 base::Unretained(cache_), | 204 base::Unretained(cache_), |
| 205 0)))); | 205 0)))); |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace file_system | 208 } // namespace file_system |
| 209 } // namespace drive | 209 } // namespace drive |
| OLD | NEW |