| 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 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 // |profile_id| needs to be checked with ProfileManager::IsValidProfile | 97 // |profile_id| needs to be checked with ProfileManager::IsValidProfile |
| 98 // before using it. | 98 // before using it. |
| 99 Profile* profile = reinterpret_cast<Profile*>(profile_id); | 99 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 100 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 100 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 101 return NULL; | 101 return NULL; |
| 102 | 102 |
| 103 return file_manager::EventRouterFactory::GetForProfile(profile); | 103 return file_manager::EventRouterFactory::GetForProfile(profile); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Notifies the error to extension via event router. |
| 107 void NotifyCopyError( |
| 108 void* profile_id, |
| 109 storage::FileSystemOperationRunner::OperationID operation_id, |
| 110 const FileSystemURL& source_url, |
| 111 const FileSystemURL& destination_url) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 |
| 114 file_manager::EventRouter* event_router = |
| 115 GetEventRouterByProfileId(profile_id); |
| 116 if (event_router) { |
| 117 event_router->OnCopyError(operation_id, source_url.ToGURL(), |
| 118 destination_url.ToGURL()); |
| 119 } |
| 120 } |
| 121 |
| 122 // Callback invoked when an error had happened during copy operation. |
| 123 void OnCopyError(void* profile_id, |
| 124 storage::FileSystemOperationRunner::OperationID* operation_id, |
| 125 base::File::Error /*error*/, |
| 126 const FileSystemURL& source_url, |
| 127 const FileSystemURL& destination_url) { |
| 128 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 129 |
| 130 BrowserThread::PostTask( |
| 131 BrowserThread::UI, FROM_HERE, |
| 132 base::Bind(&NotifyCopyError, profile_id, *operation_id, source_url, |
| 133 destination_url)); |
| 134 } |
| 135 |
| 106 // Notifies the copy progress to extensions via event router. | 136 // Notifies the copy progress to extensions via event router. |
| 107 void NotifyCopyProgress( | 137 void NotifyCopyProgress( |
| 108 void* profile_id, | 138 void* profile_id, |
| 109 storage::FileSystemOperationRunner::OperationID operation_id, | 139 storage::FileSystemOperationRunner::OperationID operation_id, |
| 110 storage::FileSystemOperation::CopyProgressType type, | 140 storage::FileSystemOperation::CopyProgressType type, |
| 111 const FileSystemURL& source_url, | 141 const FileSystemURL& source_url, |
| 112 const FileSystemURL& destination_url, | 142 const FileSystemURL& destination_url, |
| 113 int64 size) { | 143 int64 size) { |
| 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 144 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 115 | 145 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( | 207 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( |
| 178 void* profile_id, | 208 void* profile_id, |
| 179 scoped_refptr<storage::FileSystemContext> file_system_context, | 209 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 180 const FileSystemURL& source_url, | 210 const FileSystemURL& source_url, |
| 181 const FileSystemURL& destination_url) { | 211 const FileSystemURL& destination_url) { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 183 | 213 |
| 184 // Note: |operation_id| is owned by the callback for | 214 // Note: |operation_id| is owned by the callback for |
| 185 // FileSystemOperationRunner::Copy(). It is always called in the next message | 215 // FileSystemOperationRunner::Copy(). It is always called in the next message |
| 186 // loop or later, so at least during this invocation it should alive. | 216 // loop or later, so at least during this invocation it should alive. |
| 217 // |
| 218 // TODO(yawano): Flip continue_with_error to true after copy error messages |
| 219 // become to appear in the UI of Files.app. |
| 187 storage::FileSystemOperationRunner::OperationID* operation_id = | 220 storage::FileSystemOperationRunner::OperationID* operation_id = |
| 188 new storage::FileSystemOperationRunner::OperationID; | 221 new storage::FileSystemOperationRunner::OperationID; |
| 189 *operation_id = file_system_context->operation_runner()->Copy( | 222 *operation_id = file_system_context->operation_runner()->Copy( |
| 190 source_url, | 223 source_url, destination_url, |
| 191 destination_url, | 224 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, false, |
| 192 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, | 225 base::Bind(&OnCopyError, profile_id, base::Unretained(operation_id)), |
| 193 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), | 226 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), |
| 194 base::Bind(&OnCopyCompleted, | 227 base::Bind(&OnCopyCompleted, profile_id, base::Owned(operation_id), |
| 195 profile_id, | 228 source_url, destination_url)); |
| 196 base::Owned(operation_id), | |
| 197 source_url, | |
| 198 destination_url)); | |
| 199 return *operation_id; | 229 return *operation_id; |
| 200 } | 230 } |
| 201 | 231 |
| 202 void OnCopyCancelled(base::File::Error error) { | 232 void OnCopyCancelled(base::File::Error error) { |
| 203 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 233 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 204 | 234 |
| 205 // We just ignore the status if the copy is actually cancelled or not, | 235 // We just ignore the status if the copy is actually cancelled or not, |
| 206 // because failing cancellation means the operation is not running now. | 236 // because failing cancellation means the operation is not running now. |
| 207 DLOG_IF(WARNING, error != base::File::FILE_OK) | 237 DLOG_IF(WARNING, error != base::File::FILE_OK) |
| 208 << "Failed to cancel copy: " << error; | 238 << "Failed to cancel copy: " << error; |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 return RespondLater(); | 966 return RespondLater(); |
| 937 } | 967 } |
| 938 | 968 |
| 939 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( | 969 void FileManagerPrivateSetEntryTagFunction::OnSetEntryPropertyCompleted( |
| 940 drive::FileError result) { | 970 drive::FileError result) { |
| 941 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 971 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
| 942 : Error("Failed to set a tag.")); | 972 : Error("Failed to set a tag.")); |
| 943 } | 973 } |
| 944 | 974 |
| 945 } // namespace extensions | 975 } // namespace extensions |
| OLD | NEW |