Chromium Code Reviews| 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/extensions/file_manager/private_api_file_syste m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste m.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 152 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 153 | 153 |
| 154 file_manager::EventRouter* event_router = | 154 file_manager::EventRouter* event_router = |
| 155 GetEventRouterByProfileId(profile_id); | 155 GetEventRouterByProfileId(profile_id); |
| 156 if (event_router) | 156 if (event_router) |
| 157 event_router->OnCopyCompleted( | 157 event_router->OnCopyCompleted( |
| 158 operation_id, | 158 operation_id, |
| 159 source_url.ToGURL(), destination_url.ToGURL(), error); | 159 source_url.ToGURL(), destination_url.ToGURL(), error); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void OnRemoveAfterFailedCopyCompleted(base::File::Error error) { | |
| 163 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 164 | |
| 165 // We just ignore the status. | |
| 166 DLOG_IF(WARNING, error != base::File::FILE_OK) | |
| 167 << "Failed to remove the destination file after failed copy: " << error; | |
| 168 } | |
| 169 | |
| 162 // Callback invoked upon completion of Copy() (regardless of succeeded or | 170 // Callback invoked upon completion of Copy() (regardless of succeeded or |
| 163 // failed). | 171 // failed). |
| 164 void OnCopyCompleted( | 172 void OnCopyCompleted( |
| 165 void* profile_id, | 173 void* profile_id, |
| 174 scoped_refptr<storage::FileSystemContext> file_system_context, | |
| 166 storage::FileSystemOperationRunner::OperationID* operation_id, | 175 storage::FileSystemOperationRunner::OperationID* operation_id, |
| 167 const FileSystemURL& source_url, | 176 const FileSystemURL& source_url, |
| 168 const FileSystemURL& destination_url, | 177 const FileSystemURL& destination_url, |
| 169 base::File::Error error) { | 178 base::File::Error error) { |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 179 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 171 | 180 |
| 181 if (error != base::File::FILE_OK) { | |
| 182 file_system_context->operation_runner()->Remove( | |
| 183 destination_url, false, base::Bind(&OnRemoveAfterFailedCopyCompleted)); | |
|
fukino
2017/06/05 04:20:08
Is it safe to call NotifyCopyCompletion before Rem
| |
| 184 } | |
| 185 | |
| 172 BrowserThread::PostTask( | 186 BrowserThread::PostTask( |
| 173 BrowserThread::UI, FROM_HERE, | 187 BrowserThread::UI, FROM_HERE, |
| 174 base::BindOnce(&NotifyCopyCompletion, profile_id, *operation_id, | 188 base::BindOnce(&NotifyCopyCompletion, profile_id, *operation_id, |
| 175 source_url, destination_url, error)); | 189 source_url, destination_url, error)); |
| 176 } | 190 } |
| 177 | 191 |
| 178 // Starts the copy operation via FileSystemOperationRunner. | 192 // Starts the copy operation via FileSystemOperationRunner. |
| 179 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( | 193 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( |
| 180 void* profile_id, | 194 void* profile_id, |
| 181 scoped_refptr<storage::FileSystemContext> file_system_context, | 195 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 182 const FileSystemURL& source_url, | 196 const FileSystemURL& source_url, |
| 183 const FileSystemURL& destination_url) { | 197 const FileSystemURL& destination_url) { |
| 184 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 198 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 185 | 199 |
| 186 // Note: |operation_id| is owned by the callback for | 200 // Note: |operation_id| is owned by the callback for |
| 187 // FileSystemOperationRunner::Copy(). It is always called in the next message | 201 // FileSystemOperationRunner::Copy(). It is always called in the next message |
| 188 // loop or later, so at least during this invocation it should alive. | 202 // loop or later, so at least during this invocation it should alive. |
| 189 // | 203 // |
| 190 // TODO(yawano): change ERROR_BEHAVIOR_ABORT to ERROR_BEHAVIOR_SKIP after | 204 // TODO(yawano): change ERROR_BEHAVIOR_ABORT to ERROR_BEHAVIOR_SKIP after |
| 191 // error messages of individual operations become appear in the Files app | 205 // error messages of individual operations become appear in the Files app |
| 192 // UI. | 206 // UI. |
| 193 storage::FileSystemOperationRunner::OperationID* operation_id = | 207 storage::FileSystemOperationRunner::OperationID* operation_id = |
| 194 new storage::FileSystemOperationRunner::OperationID; | 208 new storage::FileSystemOperationRunner::OperationID; |
| 195 *operation_id = file_system_context->operation_runner()->Copy( | 209 *operation_id = file_system_context->operation_runner()->Copy( |
|
fukino
2017/06/05 04:20:08
It might be better to remove incomplete file insid
| |
| 196 source_url, destination_url, | 210 source_url, destination_url, |
| 197 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, | 211 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, |
| 198 storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, | 212 storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, |
| 199 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), | 213 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), |
| 200 base::Bind(&OnCopyCompleted, profile_id, base::Owned(operation_id), | 214 base::Bind(&OnCopyCompleted, profile_id, file_system_context, |
| 201 source_url, destination_url)); | 215 base::Owned(operation_id), source_url, destination_url)); |
| 202 return *operation_id; | 216 return *operation_id; |
| 203 } | 217 } |
| 204 | 218 |
| 205 void OnCopyCancelled(base::File::Error error) { | 219 void OnCopyCancelled(base::File::Error error) { |
| 206 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 220 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 207 | 221 |
| 208 // We just ignore the status if the copy is actually cancelled or not, | 222 // We just ignore the status if the copy is actually cancelled or not, |
| 209 // because failing cancellation means the operation is not running now. | 223 // because failing cancellation means the operation is not running now. |
| 210 DLOG_IF(WARNING, error != base::File::FILE_OK) | 224 DLOG_IF(WARNING, error != base::File::FILE_OK) |
| 211 << "Failed to cancel copy: " << error; | 225 << "Failed to cancel copy: " << error; |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 return true; | 1061 return true; |
| 1048 } | 1062 } |
| 1049 | 1063 |
| 1050 void FileManagerPrivateInternalGetDirectorySizeFunction:: | 1064 void FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 1051 OnDirectorySizeRetrieved(int64_t size) { | 1065 OnDirectorySizeRetrieved(int64_t size) { |
| 1052 SetResult(base::MakeUnique<base::Value>(static_cast<double>(size))); | 1066 SetResult(base::MakeUnique<base::Value>(static_cast<double>(size))); |
| 1053 SendResponse(true); | 1067 SendResponse(true); |
| 1054 } | 1068 } |
| 1055 | 1069 |
| 1056 } // namespace extensions | 1070 } // namespace extensions |
| OLD | NEW |