| 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 "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 22 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
| 23 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | 23 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/common/extensions/api/file_browser_private.h" | 26 #include "chrome/common/extensions/api/file_browser_private.h" |
| 27 #include "chrome/common/extensions/api/file_browser_private_internal.h" | 27 #include "chrome/common/extensions/api/file_browser_private_internal.h" |
| 28 #include "chromeos/disks/disk_mount_manager.h" | 28 #include "chromeos/disks/disk_mount_manager.h" |
| 29 #include "content/public/browser/child_process_security_policy.h" | 29 #include "content/public/browser/child_process_security_policy.h" |
| 30 #include "content/public/browser/render_process_host.h" | 30 #include "content/public/browser/render_process_host.h" |
| 31 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 32 #include "webkit/browser/fileapi/file_system_context.h" | 32 #include "storage/browser/fileapi/file_system_context.h" |
| 33 #include "webkit/browser/fileapi/file_system_file_util.h" | 33 #include "storage/browser/fileapi/file_system_file_util.h" |
| 34 #include "webkit/browser/fileapi/file_system_operation_context.h" | 34 #include "storage/browser/fileapi/file_system_operation_context.h" |
| 35 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 35 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 36 #include "webkit/browser/fileapi/file_system_url.h" | 36 #include "storage/browser/fileapi/file_system_url.h" |
| 37 #include "webkit/common/fileapi/file_system_info.h" | 37 #include "storage/common/fileapi/file_system_info.h" |
| 38 #include "webkit/common/fileapi/file_system_types.h" | 38 #include "storage/common/fileapi/file_system_types.h" |
| 39 #include "webkit/common/fileapi/file_system_util.h" | 39 #include "storage/common/fileapi/file_system_util.h" |
| 40 | 40 |
| 41 using chromeos::disks::DiskMountManager; | 41 using chromeos::disks::DiskMountManager; |
| 42 using content::BrowserThread; | 42 using content::BrowserThread; |
| 43 using content::ChildProcessSecurityPolicy; | 43 using content::ChildProcessSecurityPolicy; |
| 44 using file_manager::util::EntryDefinition; | 44 using file_manager::util::EntryDefinition; |
| 45 using file_manager::util::FileDefinition; | 45 using file_manager::util::FileDefinition; |
| 46 using fileapi::FileSystemURL; | 46 using storage::FileSystemURL; |
| 47 | 47 |
| 48 namespace extensions { | 48 namespace extensions { |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // Retrieves total and remaining available size on |mount_path|. | 51 // Retrieves total and remaining available size on |mount_path|. |
| 52 void GetSizeStatsOnBlockingPool(const std::string& mount_path, | 52 void GetSizeStatsOnBlockingPool(const std::string& mount_path, |
| 53 uint64* total_size, | 53 uint64* total_size, |
| 54 uint64* remaining_size) { | 54 uint64* remaining_size) { |
| 55 struct statvfs stat = {}; // Zero-clear | 55 struct statvfs stat = {}; // Zero-clear |
| 56 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { | 56 if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 81 Profile* profile = reinterpret_cast<Profile*>(profile_id); | 81 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 82 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 82 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 83 return NULL; | 83 return NULL; |
| 84 | 84 |
| 85 return file_manager::FileBrowserPrivateAPI::Get(profile)->event_router(); | 85 return file_manager::FileBrowserPrivateAPI::Get(profile)->event_router(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Notifies the copy progress to extensions via event router. | 88 // Notifies the copy progress to extensions via event router. |
| 89 void NotifyCopyProgress( | 89 void NotifyCopyProgress( |
| 90 void* profile_id, | 90 void* profile_id, |
| 91 fileapi::FileSystemOperationRunner::OperationID operation_id, | 91 storage::FileSystemOperationRunner::OperationID operation_id, |
| 92 fileapi::FileSystemOperation::CopyProgressType type, | 92 storage::FileSystemOperation::CopyProgressType type, |
| 93 const FileSystemURL& source_url, | 93 const FileSystemURL& source_url, |
| 94 const FileSystemURL& destination_url, | 94 const FileSystemURL& destination_url, |
| 95 int64 size) { | 95 int64 size) { |
| 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 97 | 97 |
| 98 file_manager::EventRouter* event_router = | 98 file_manager::EventRouter* event_router = |
| 99 GetEventRouterByProfileId(profile_id); | 99 GetEventRouterByProfileId(profile_id); |
| 100 if (event_router) { | 100 if (event_router) { |
| 101 event_router->OnCopyProgress( | 101 event_router->OnCopyProgress( |
| 102 operation_id, type, | 102 operation_id, type, |
| 103 source_url.ToGURL(), destination_url.ToGURL(), size); | 103 source_url.ToGURL(), destination_url.ToGURL(), size); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Callback invoked periodically on progress update of Copy(). | 107 // Callback invoked periodically on progress update of Copy(). |
| 108 void OnCopyProgress( | 108 void OnCopyProgress( |
| 109 void* profile_id, | 109 void* profile_id, |
| 110 fileapi::FileSystemOperationRunner::OperationID* operation_id, | 110 storage::FileSystemOperationRunner::OperationID* operation_id, |
| 111 fileapi::FileSystemOperation::CopyProgressType type, | 111 storage::FileSystemOperation::CopyProgressType type, |
| 112 const FileSystemURL& source_url, | 112 const FileSystemURL& source_url, |
| 113 const FileSystemURL& destination_url, | 113 const FileSystemURL& destination_url, |
| 114 int64 size) { | 114 int64 size) { |
| 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 116 | 116 |
| 117 BrowserThread::PostTask( | 117 BrowserThread::PostTask( |
| 118 BrowserThread::UI, FROM_HERE, | 118 BrowserThread::UI, FROM_HERE, |
| 119 base::Bind(&NotifyCopyProgress, | 119 base::Bind(&NotifyCopyProgress, |
| 120 profile_id, *operation_id, type, | 120 profile_id, *operation_id, type, |
| 121 source_url, destination_url, size)); | 121 source_url, destination_url, size)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Notifies the copy completion to extensions via event router. | 124 // Notifies the copy completion to extensions via event router. |
| 125 void NotifyCopyCompletion( | 125 void NotifyCopyCompletion( |
| 126 void* profile_id, | 126 void* profile_id, |
| 127 fileapi::FileSystemOperationRunner::OperationID operation_id, | 127 storage::FileSystemOperationRunner::OperationID operation_id, |
| 128 const FileSystemURL& source_url, | 128 const FileSystemURL& source_url, |
| 129 const FileSystemURL& destination_url, | 129 const FileSystemURL& destination_url, |
| 130 base::File::Error error) { | 130 base::File::Error error) { |
| 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 132 | 132 |
| 133 file_manager::EventRouter* event_router = | 133 file_manager::EventRouter* event_router = |
| 134 GetEventRouterByProfileId(profile_id); | 134 GetEventRouterByProfileId(profile_id); |
| 135 if (event_router) | 135 if (event_router) |
| 136 event_router->OnCopyCompleted( | 136 event_router->OnCopyCompleted( |
| 137 operation_id, | 137 operation_id, |
| 138 source_url.ToGURL(), destination_url.ToGURL(), error); | 138 source_url.ToGURL(), destination_url.ToGURL(), error); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Callback invoked upon completion of Copy() (regardless of succeeded or | 141 // Callback invoked upon completion of Copy() (regardless of succeeded or |
| 142 // failed). | 142 // failed). |
| 143 void OnCopyCompleted( | 143 void OnCopyCompleted( |
| 144 void* profile_id, | 144 void* profile_id, |
| 145 fileapi::FileSystemOperationRunner::OperationID* operation_id, | 145 storage::FileSystemOperationRunner::OperationID* operation_id, |
| 146 const FileSystemURL& source_url, | 146 const FileSystemURL& source_url, |
| 147 const FileSystemURL& destination_url, | 147 const FileSystemURL& destination_url, |
| 148 base::File::Error error) { | 148 base::File::Error error) { |
| 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 150 | 150 |
| 151 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
| 152 BrowserThread::UI, FROM_HERE, | 152 BrowserThread::UI, FROM_HERE, |
| 153 base::Bind(&NotifyCopyCompletion, | 153 base::Bind(&NotifyCopyCompletion, |
| 154 profile_id, *operation_id, | 154 profile_id, *operation_id, |
| 155 source_url, destination_url, error)); | 155 source_url, destination_url, error)); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Starts the copy operation via FileSystemOperationRunner. | 158 // Starts the copy operation via FileSystemOperationRunner. |
| 159 fileapi::FileSystemOperationRunner::OperationID StartCopyOnIOThread( | 159 storage::FileSystemOperationRunner::OperationID StartCopyOnIOThread( |
| 160 void* profile_id, | 160 void* profile_id, |
| 161 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 161 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 162 const FileSystemURL& source_url, | 162 const FileSystemURL& source_url, |
| 163 const FileSystemURL& destination_url) { | 163 const FileSystemURL& destination_url) { |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 165 | 165 |
| 166 // Note: |operation_id| is owned by the callback for | 166 // Note: |operation_id| is owned by the callback for |
| 167 // FileSystemOperationRunner::Copy(). It is always called in the next message | 167 // FileSystemOperationRunner::Copy(). It is always called in the next message |
| 168 // loop or later, so at least during this invocation it should alive. | 168 // loop or later, so at least during this invocation it should alive. |
| 169 fileapi::FileSystemOperationRunner::OperationID* operation_id = | 169 storage::FileSystemOperationRunner::OperationID* operation_id = |
| 170 new fileapi::FileSystemOperationRunner::OperationID; | 170 new storage::FileSystemOperationRunner::OperationID; |
| 171 *operation_id = file_system_context->operation_runner()->Copy( | 171 *operation_id = file_system_context->operation_runner()->Copy( |
| 172 source_url, destination_url, | 172 source_url, |
| 173 fileapi::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, | 173 destination_url, |
| 174 base::Bind(&OnCopyProgress, | 174 storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, |
| 175 profile_id, base::Unretained(operation_id)), | 175 base::Bind(&OnCopyProgress, profile_id, base::Unretained(operation_id)), |
| 176 base::Bind(&OnCopyCompleted, | 176 base::Bind(&OnCopyCompleted, |
| 177 profile_id, base::Owned(operation_id), | 177 profile_id, |
| 178 source_url, destination_url)); | 178 base::Owned(operation_id), |
| 179 source_url, |
| 180 destination_url)); |
| 179 return *operation_id; | 181 return *operation_id; |
| 180 } | 182 } |
| 181 | 183 |
| 182 void OnCopyCancelled(base::File::Error error) { | 184 void OnCopyCancelled(base::File::Error error) { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 184 | 186 |
| 185 // We just ignore the status if the copy is actually cancelled or not, | 187 // We just ignore the status if the copy is actually cancelled or not, |
| 186 // because failing cancellation means the operation is not running now. | 188 // because failing cancellation means the operation is not running now. |
| 187 DLOG_IF(WARNING, error != base::File::FILE_OK) | 189 DLOG_IF(WARNING, error != base::File::FILE_OK) |
| 188 << "Failed to cancel copy: " << error; | 190 << "Failed to cancel copy: " << error; |
| 189 } | 191 } |
| 190 | 192 |
| 191 // Cancels the running copy operation identified by |operation_id|. | 193 // Cancels the running copy operation identified by |operation_id|. |
| 192 void CancelCopyOnIOThread( | 194 void CancelCopyOnIOThread( |
| 193 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 195 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 194 fileapi::FileSystemOperationRunner::OperationID operation_id) { | 196 storage::FileSystemOperationRunner::OperationID operation_id) { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 196 | 198 |
| 197 file_system_context->operation_runner()->Cancel( | 199 file_system_context->operation_runner()->Cancel( |
| 198 operation_id, base::Bind(&OnCopyCancelled)); | 200 operation_id, base::Bind(&OnCopyCancelled)); |
| 199 } | 201 } |
| 200 | 202 |
| 201 } // namespace | 203 } // namespace |
| 202 | 204 |
| 203 void FileBrowserPrivateRequestFileSystemFunction::DidFail( | 205 void FileBrowserPrivateRequestFileSystemFunction::DidFail( |
| 204 base::File::Error error_code) { | 206 base::File::Error error_code) { |
| 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 | 208 |
| 207 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); | 209 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); |
| 208 SendResponse(false); | 210 SendResponse(false); |
| 209 } | 211 } |
| 210 | 212 |
| 211 bool FileBrowserPrivateRequestFileSystemFunction:: | 213 bool |
| 212 SetupFileSystemAccessPermissions( | 214 FileBrowserPrivateRequestFileSystemFunction::SetupFileSystemAccessPermissions( |
| 213 scoped_refptr<fileapi::FileSystemContext> file_system_context, | 215 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 214 int child_id, | 216 int child_id, |
| 215 Profile* profile, | 217 Profile* profile, |
| 216 scoped_refptr<const extensions::Extension> extension) { | 218 scoped_refptr<const extensions::Extension> extension) { |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 218 | 220 |
| 219 if (!extension.get()) | 221 if (!extension.get()) |
| 220 return false; | 222 return false; |
| 221 | 223 |
| 222 // Make sure that only component extension can access the entire | 224 // Make sure that only component extension can access the entire |
| 223 // local file system. | 225 // local file system. |
| 224 if (extension_->location() != extensions::Manifest::COMPONENT) { | 226 if (extension_->location() != extensions::Manifest::COMPONENT) { |
| 225 NOTREACHED() << "Private method access by non-component extension " | 227 NOTREACHED() << "Private method access by non-component extension " |
| 226 << extension->id(); | 228 << extension->id(); |
| 227 return false; | 229 return false; |
| 228 } | 230 } |
| 229 | 231 |
| 230 fileapi::ExternalFileSystemBackend* backend = | 232 storage::ExternalFileSystemBackend* backend = |
| 231 file_system_context->external_backend(); | 233 file_system_context->external_backend(); |
| 232 if (!backend) | 234 if (!backend) |
| 233 return false; | 235 return false; |
| 234 | 236 |
| 235 // Grant full access to File API from this component extension. | 237 // Grant full access to File API from this component extension. |
| 236 backend->GrantFullAccessToExtension(extension_->id()); | 238 backend->GrantFullAccessToExtension(extension_->id()); |
| 237 | 239 |
| 238 // Grant R/W file permissions to the renderer hosting component | 240 // Grant R/W file permissions to the renderer hosting component |
| 239 // extension for all paths exposed by our local file system backend. | 241 // extension for all paths exposed by our local file system backend. |
| 240 std::vector<base::FilePath> root_dirs = backend->GetRootDirectories(); | 242 std::vector<base::FilePath> root_dirs = backend->GetRootDirectories(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); | 277 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); |
| 276 if (!volume_manager) | 278 if (!volume_manager) |
| 277 return false; | 279 return false; |
| 278 | 280 |
| 279 VolumeInfo volume_info; | 281 VolumeInfo volume_info; |
| 280 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) { | 282 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) { |
| 281 DidFail(base::File::FILE_ERROR_NOT_FOUND); | 283 DidFail(base::File::FILE_ERROR_NOT_FOUND); |
| 282 return false; | 284 return false; |
| 283 } | 285 } |
| 284 | 286 |
| 285 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 287 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 286 file_manager::util::GetFileSystemContextForRenderViewHost( | 288 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 287 GetProfile(), render_view_host()); | 289 GetProfile(), render_view_host()); |
| 288 | 290 |
| 289 // Set up file permission access. | 291 // Set up file permission access. |
| 290 const int child_id = render_view_host()->GetProcess()->GetID(); | 292 const int child_id = render_view_host()->GetProcess()->GetID(); |
| 291 if (!SetupFileSystemAccessPermissions( | 293 if (!SetupFileSystemAccessPermissions( |
| 292 file_system_context, child_id, GetProfile(), extension())) { | 294 file_system_context, child_id, GetProfile(), extension())) { |
| 293 DidFail(base::File::FILE_ERROR_SECURITY); | 295 DidFail(base::File::FILE_ERROR_SECURITY); |
| 294 return false; | 296 return false; |
| 295 } | 297 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 349 | 351 |
| 350 if (!render_view_host() || !render_view_host()->GetProcess()) | 352 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 351 return false; | 353 return false; |
| 352 | 354 |
| 353 // First param is url of a file to watch. | 355 // First param is url of a file to watch. |
| 354 std::string url; | 356 std::string url; |
| 355 if (!args_->GetString(0, &url) || url.empty()) | 357 if (!args_->GetString(0, &url) || url.empty()) |
| 356 return false; | 358 return false; |
| 357 | 359 |
| 358 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 360 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 359 file_manager::util::GetFileSystemContextForRenderViewHost( | 361 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 360 GetProfile(), render_view_host()); | 362 GetProfile(), render_view_host()); |
| 361 | 363 |
| 362 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); | 364 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); |
| 363 base::FilePath local_path = file_watch_url.path(); | 365 base::FilePath local_path = file_watch_url.path(); |
| 364 base::FilePath virtual_path = file_watch_url.virtual_path(); | 366 base::FilePath virtual_path = file_watch_url.virtual_path(); |
| 365 if (local_path.empty()) { | 367 if (local_path.empty()) { |
| 366 Respond(false); | 368 Respond(false); |
| 367 return true; | 369 return true; |
| 368 } | 370 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); | 473 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); |
| 472 | 474 |
| 473 SendResponse(true); | 475 SendResponse(true); |
| 474 } | 476 } |
| 475 | 477 |
| 476 bool FileBrowserPrivateValidatePathNameLengthFunction::RunAsync() { | 478 bool FileBrowserPrivateValidatePathNameLengthFunction::RunAsync() { |
| 477 using extensions::api::file_browser_private::ValidatePathNameLength::Params; | 479 using extensions::api::file_browser_private::ValidatePathNameLength::Params; |
| 478 const scoped_ptr<Params> params(Params::Create(*args_)); | 480 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 479 EXTENSION_FUNCTION_VALIDATE(params); | 481 EXTENSION_FUNCTION_VALIDATE(params); |
| 480 | 482 |
| 481 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 483 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 482 file_manager::util::GetFileSystemContextForRenderViewHost( | 484 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 483 GetProfile(), render_view_host()); | 485 GetProfile(), render_view_host()); |
| 484 | 486 |
| 485 fileapi::FileSystemURL filesystem_url( | 487 storage::FileSystemURL filesystem_url( |
| 486 file_system_context->CrackURL(GURL(params->parent_directory_url))); | 488 file_system_context->CrackURL(GURL(params->parent_directory_url))); |
| 487 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) | 489 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) |
| 488 return false; | 490 return false; |
| 489 | 491 |
| 490 // No explicit limit on the length of Drive file names. | 492 // No explicit limit on the length of Drive file names. |
| 491 if (filesystem_url.type() == fileapi::kFileSystemTypeDrive) { | 493 if (filesystem_url.type() == storage::kFileSystemTypeDrive) { |
| 492 SetResult(new base::FundamentalValue(true)); | 494 SetResult(new base::FundamentalValue(true)); |
| 493 SendResponse(true); | 495 SendResponse(true); |
| 494 return true; | 496 return true; |
| 495 } | 497 } |
| 496 | 498 |
| 497 base::PostTaskAndReplyWithResult( | 499 base::PostTaskAndReplyWithResult( |
| 498 BrowserThread::GetBlockingPool(), | 500 BrowserThread::GetBlockingPool(), |
| 499 FROM_HERE, | 501 FROM_HERE, |
| 500 base::Bind(&GetFileNameMaxLengthOnBlockingPool, | 502 base::Bind(&GetFileNameMaxLengthOnBlockingPool, |
| 501 filesystem_url.path().AsUTF8Unsafe()), | 503 filesystem_url.path().AsUTF8Unsafe()), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 const scoped_ptr<Params> params(Params::Create(*args_)); | 542 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 541 EXTENSION_FUNCTION_VALIDATE(params); | 543 EXTENSION_FUNCTION_VALIDATE(params); |
| 542 | 544 |
| 543 if (params->source_url.empty() || params->parent.empty() || | 545 if (params->source_url.empty() || params->parent.empty() || |
| 544 params->new_name.empty()) { | 546 params->new_name.empty()) { |
| 545 // Error code in format of DOMError.name. | 547 // Error code in format of DOMError.name. |
| 546 SetError("EncodingError"); | 548 SetError("EncodingError"); |
| 547 return false; | 549 return false; |
| 548 } | 550 } |
| 549 | 551 |
| 550 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 552 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 551 file_manager::util::GetFileSystemContextForRenderViewHost( | 553 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 552 GetProfile(), render_view_host()); | 554 GetProfile(), render_view_host()); |
| 553 | 555 |
| 554 // |parent| may have a trailing slash if it is a root directory. | 556 // |parent| may have a trailing slash if it is a root directory. |
| 555 std::string destination_url_string = params->parent; | 557 std::string destination_url_string = params->parent; |
| 556 if (destination_url_string[destination_url_string.size() - 1] != '/') | 558 if (destination_url_string[destination_url_string.size() - 1] != '/') |
| 557 destination_url_string += '/'; | 559 destination_url_string += '/'; |
| 558 destination_url_string += net::EscapePath(params->new_name); | 560 destination_url_string += net::EscapePath(params->new_name); |
| 559 | 561 |
| 560 fileapi::FileSystemURL source_url( | 562 storage::FileSystemURL source_url( |
| 561 file_system_context->CrackURL(GURL(params->source_url))); | 563 file_system_context->CrackURL(GURL(params->source_url))); |
| 562 fileapi::FileSystemURL destination_url( | 564 storage::FileSystemURL destination_url( |
| 563 file_system_context->CrackURL(GURL(destination_url_string))); | 565 file_system_context->CrackURL(GURL(destination_url_string))); |
| 564 | 566 |
| 565 if (!source_url.is_valid() || !destination_url.is_valid()) { | 567 if (!source_url.is_valid() || !destination_url.is_valid()) { |
| 566 // Error code in format of DOMError.name. | 568 // Error code in format of DOMError.name. |
| 567 SetError("EncodingError"); | 569 SetError("EncodingError"); |
| 568 return false; | 570 return false; |
| 569 } | 571 } |
| 570 | 572 |
| 571 return BrowserThread::PostTaskAndReplyWithResult( | 573 return BrowserThread::PostTaskAndReplyWithResult( |
| 572 BrowserThread::IO, | 574 BrowserThread::IO, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 588 SendResponse(true); | 590 SendResponse(true); |
| 589 } | 591 } |
| 590 | 592 |
| 591 bool FileBrowserPrivateCancelCopyFunction::RunAsync() { | 593 bool FileBrowserPrivateCancelCopyFunction::RunAsync() { |
| 592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 593 | 595 |
| 594 using extensions::api::file_browser_private::CancelCopy::Params; | 596 using extensions::api::file_browser_private::CancelCopy::Params; |
| 595 const scoped_ptr<Params> params(Params::Create(*args_)); | 597 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 596 EXTENSION_FUNCTION_VALIDATE(params); | 598 EXTENSION_FUNCTION_VALIDATE(params); |
| 597 | 599 |
| 598 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 600 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 599 file_manager::util::GetFileSystemContextForRenderViewHost( | 601 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 600 GetProfile(), render_view_host()); | 602 GetProfile(), render_view_host()); |
| 601 | 603 |
| 602 // We don't much take care about the result of cancellation. | 604 // We don't much take care about the result of cancellation. |
| 603 BrowserThread::PostTask( | 605 BrowserThread::PostTask( |
| 604 BrowserThread::IO, | 606 BrowserThread::IO, |
| 605 FROM_HERE, | 607 FROM_HERE, |
| 606 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); | 608 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); |
| 607 SendResponse(true); | 609 SendResponse(true); |
| 608 return true; | 610 return true; |
| 609 } | 611 } |
| 610 | 612 |
| 611 bool FileBrowserPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { | 613 bool FileBrowserPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { |
| 612 using extensions::api::file_browser_private_internal::ResolveIsolatedEntries:: | 614 using extensions::api::file_browser_private_internal::ResolveIsolatedEntries:: |
| 613 Params; | 615 Params; |
| 614 const scoped_ptr<Params> params(Params::Create(*args_)); | 616 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 615 EXTENSION_FUNCTION_VALIDATE(params); | 617 EXTENSION_FUNCTION_VALIDATE(params); |
| 616 | 618 |
| 617 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 619 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 618 file_manager::util::GetFileSystemContextForRenderViewHost( | 620 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 619 GetProfile(), render_view_host()); | 621 GetProfile(), render_view_host()); |
| 620 DCHECK(file_system_context); | 622 DCHECK(file_system_context); |
| 621 | 623 |
| 622 const fileapi::ExternalFileSystemBackend* external_backend = | 624 const storage::ExternalFileSystemBackend* external_backend = |
| 623 file_system_context->external_backend(); | 625 file_system_context->external_backend(); |
| 624 DCHECK(external_backend); | 626 DCHECK(external_backend); |
| 625 | 627 |
| 626 file_manager::util::FileDefinitionList file_definition_list; | 628 file_manager::util::FileDefinitionList file_definition_list; |
| 627 for (size_t i = 0; i < params->urls.size(); ++i) { | 629 for (size_t i = 0; i < params->urls.size(); ++i) { |
| 628 FileSystemURL fileSystemUrl = | 630 FileSystemURL fileSystemUrl = |
| 629 file_system_context->CrackURL(GURL(params->urls[i])); | 631 file_system_context->CrackURL(GURL(params->urls[i])); |
| 630 DCHECK(external_backend->CanHandleType(fileSystemUrl.type())); | 632 DCHECK(external_backend->CanHandleType(fileSystemUrl.type())); |
| 631 | 633 |
| 632 FileDefinition file_definition; | 634 FileDefinition file_definition; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); | 672 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); |
| 671 entry->file_is_directory = entry_definition_list->at(i).is_directory; | 673 entry->file_is_directory = entry_definition_list->at(i).is_directory; |
| 672 entries.push_back(entry); | 674 entries.push_back(entry); |
| 673 } | 675 } |
| 674 | 676 |
| 675 results_ = extensions::api::file_browser_private_internal:: | 677 results_ = extensions::api::file_browser_private_internal:: |
| 676 ResolveIsolatedEntries::Results::Create(entries); | 678 ResolveIsolatedEntries::Results::Create(entries); |
| 677 SendResponse(true); | 679 SendResponse(true); |
| 678 } | 680 } |
| 679 } // namespace extensions | 681 } // namespace extensions |
| OLD | NEW |