| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 16 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 16 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 18 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" | 18 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
| 19 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.h" | 19 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_private_a
pi.h" |
| 20 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 20 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 21 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 21 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 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_manager_private.h" |
| 27 #include "chrome/common/extensions/api/file_browser_private_internal.h" | 27 #include "chrome/common/extensions/api/file_manager_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 "net/base/escape.h" | 32 #include "net/base/escape.h" |
| 33 #include "webkit/browser/fileapi/file_system_context.h" | 33 #include "webkit/browser/fileapi/file_system_context.h" |
| 34 #include "webkit/browser/fileapi/file_system_file_util.h" | 34 #include "webkit/browser/fileapi/file_system_file_util.h" |
| 35 #include "webkit/browser/fileapi/file_system_operation_context.h" | 35 #include "webkit/browser/fileapi/file_system_operation_context.h" |
| 36 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 36 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 37 #include "webkit/browser/fileapi/file_system_url.h" | 37 #include "webkit/browser/fileapi/file_system_url.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Returns EventRouter for the |profile_id| if available. | 76 // Returns EventRouter for the |profile_id| if available. |
| 77 file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) { | 77 file_manager::EventRouter* GetEventRouterByProfileId(void* profile_id) { |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 79 | 79 |
| 80 // |profile_id| needs to be checked with ProfileManager::IsValidProfile | 80 // |profile_id| needs to be checked with ProfileManager::IsValidProfile |
| 81 // before using it. | 81 // before using it. |
| 82 Profile* profile = reinterpret_cast<Profile*>(profile_id); | 82 Profile* profile = reinterpret_cast<Profile*>(profile_id); |
| 83 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | 83 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 84 return NULL; | 84 return NULL; |
| 85 | 85 |
| 86 return file_manager::FileBrowserPrivateAPI::Get(profile)->event_router(); | 86 return file_manager::FileManagerPrivateAPI::Get(profile)->event_router(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Notifies the copy progress to extensions via event router. | 89 // Notifies the copy progress to extensions via event router. |
| 90 void NotifyCopyProgress( | 90 void NotifyCopyProgress( |
| 91 void* profile_id, | 91 void* profile_id, |
| 92 storage::FileSystemOperationRunner::OperationID operation_id, | 92 storage::FileSystemOperationRunner::OperationID operation_id, |
| 93 storage::FileSystemOperation::CopyProgressType type, | 93 storage::FileSystemOperation::CopyProgressType type, |
| 94 const FileSystemURL& source_url, | 94 const FileSystemURL& source_url, |
| 95 const FileSystemURL& destination_url, | 95 const FileSystemURL& destination_url, |
| 96 int64 size) { | 96 int64 size) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 scoped_refptr<storage::FileSystemContext> file_system_context, | 196 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 197 storage::FileSystemOperationRunner::OperationID operation_id) { | 197 storage::FileSystemOperationRunner::OperationID operation_id) { |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 199 | 199 |
| 200 file_system_context->operation_runner()->Cancel( | 200 file_system_context->operation_runner()->Cancel( |
| 201 operation_id, base::Bind(&OnCopyCancelled)); | 201 operation_id, base::Bind(&OnCopyCancelled)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace | 204 } // namespace |
| 205 | 205 |
| 206 void FileBrowserPrivateRequestFileSystemFunction::DidFail( | 206 void FileManagerPrivateRequestFileSystemFunction::DidFail( |
| 207 base::File::Error error_code) { | 207 base::File::Error error_code) { |
| 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 209 | 209 |
| 210 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); | 210 SetError(base::StringPrintf("File error %d", static_cast<int>(error_code))); |
| 211 SendResponse(false); | 211 SendResponse(false); |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool | 214 bool |
| 215 FileBrowserPrivateRequestFileSystemFunction::SetupFileSystemAccessPermissions( | 215 FileManagerPrivateRequestFileSystemFunction::SetupFileSystemAccessPermissions( |
| 216 scoped_refptr<storage::FileSystemContext> file_system_context, | 216 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 217 int child_id, | 217 int child_id, |
| 218 Profile* profile, | 218 Profile* profile, |
| 219 scoped_refptr<const extensions::Extension> extension) { | 219 scoped_refptr<const extensions::Extension> extension) { |
| 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 221 | 221 |
| 222 if (!extension.get()) | 222 if (!extension.get()) |
| 223 return false; | 223 return false; |
| 224 | 224 |
| 225 // Make sure that only component extension can access the entire | 225 // Make sure that only component extension can access the entire |
| (...skipping 29 matching lines...) Expand all Loading... |
| 255 for (size_t i = 0; i < profiles.size(); ++i) { | 255 for (size_t i = 0; i < profiles.size(); ++i) { |
| 256 if (!profiles[i]->IsOffTheRecord()) { | 256 if (!profiles[i]->IsOffTheRecord()) { |
| 257 file_manager::util::SetupProfileFileAccessPermissions(child_id, | 257 file_manager::util::SetupProfileFileAccessPermissions(child_id, |
| 258 profiles[i]); | 258 profiles[i]); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 return true; | 262 return true; |
| 263 } | 263 } |
| 264 | 264 |
| 265 bool FileBrowserPrivateRequestFileSystemFunction::RunAsync() { | 265 bool FileManagerPrivateRequestFileSystemFunction::RunAsync() { |
| 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 267 using extensions::api::file_browser_private::RequestFileSystem::Params; | 267 using extensions::api::file_manager_private::RequestFileSystem::Params; |
| 268 const scoped_ptr<Params> params(Params::Create(*args_)); | 268 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 269 EXTENSION_FUNCTION_VALIDATE(params); | 269 EXTENSION_FUNCTION_VALIDATE(params); |
| 270 | 270 |
| 271 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) | 271 if (!dispatcher() || !render_view_host() || !render_view_host()->GetProcess()) |
| 272 return false; | 272 return false; |
| 273 | 273 |
| 274 set_log_on_completion(true); | 274 set_log_on_completion(true); |
| 275 | 275 |
| 276 using file_manager::VolumeManager; | 276 using file_manager::VolumeManager; |
| 277 using file_manager::VolumeInfo; | 277 using file_manager::VolumeInfo; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 306 DidFail(base::File::FILE_ERROR_INVALID_OPERATION); | 306 DidFail(base::File::FILE_ERROR_INVALID_OPERATION); |
| 307 return false; | 307 return false; |
| 308 } | 308 } |
| 309 file_definition.is_directory = true; | 309 file_definition.is_directory = true; |
| 310 | 310 |
| 311 file_manager::util::ConvertFileDefinitionToEntryDefinition( | 311 file_manager::util::ConvertFileDefinitionToEntryDefinition( |
| 312 GetProfile(), | 312 GetProfile(), |
| 313 extension_id(), | 313 extension_id(), |
| 314 file_definition, | 314 file_definition, |
| 315 base::Bind( | 315 base::Bind( |
| 316 &FileBrowserPrivateRequestFileSystemFunction::OnEntryDefinition, | 316 &FileManagerPrivateRequestFileSystemFunction::OnEntryDefinition, |
| 317 this)); | 317 this)); |
| 318 return true; | 318 return true; |
| 319 } | 319 } |
| 320 | 320 |
| 321 void FileBrowserPrivateRequestFileSystemFunction::OnEntryDefinition( | 321 void FileManagerPrivateRequestFileSystemFunction::OnEntryDefinition( |
| 322 const EntryDefinition& entry_definition) { | 322 const EntryDefinition& entry_definition) { |
| 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 324 | 324 |
| 325 if (entry_definition.error != base::File::FILE_OK) { | 325 if (entry_definition.error != base::File::FILE_OK) { |
| 326 DidFail(entry_definition.error); | 326 DidFail(entry_definition.error); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 if (!entry_definition.is_directory) { | 330 if (!entry_definition.is_directory) { |
| 331 DidFail(base::File::FILE_ERROR_NOT_A_DIRECTORY); | 331 DidFail(base::File::FILE_ERROR_NOT_A_DIRECTORY); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 base::FilePath virtual_path = file_watch_url.virtual_path(); | 367 base::FilePath virtual_path = file_watch_url.virtual_path(); |
| 368 if (local_path.empty()) { | 368 if (local_path.empty()) { |
| 369 Respond(false); | 369 Respond(false); |
| 370 return true; | 370 return true; |
| 371 } | 371 } |
| 372 PerformFileWatchOperation(local_path, virtual_path, extension_id()); | 372 PerformFileWatchOperation(local_path, virtual_path, extension_id()); |
| 373 | 373 |
| 374 return true; | 374 return true; |
| 375 } | 375 } |
| 376 | 376 |
| 377 void FileBrowserPrivateAddFileWatchFunction::PerformFileWatchOperation( | 377 void FileManagerPrivateAddFileWatchFunction::PerformFileWatchOperation( |
| 378 const base::FilePath& local_path, | 378 const base::FilePath& local_path, |
| 379 const base::FilePath& virtual_path, | 379 const base::FilePath& virtual_path, |
| 380 const std::string& extension_id) { | 380 const std::string& extension_id) { |
| 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 382 | 382 |
| 383 file_manager::EventRouter* event_router = | 383 file_manager::EventRouter* event_router = |
| 384 file_manager::FileBrowserPrivateAPI::Get(GetProfile())->event_router(); | 384 file_manager::FileManagerPrivateAPI::Get(GetProfile())->event_router(); |
| 385 event_router->AddFileWatch( | 385 event_router->AddFileWatch( |
| 386 local_path, | 386 local_path, |
| 387 virtual_path, | 387 virtual_path, |
| 388 extension_id, | 388 extension_id, |
| 389 base::Bind(&FileBrowserPrivateAddFileWatchFunction::Respond, this)); | 389 base::Bind(&FileManagerPrivateAddFileWatchFunction::Respond, this)); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void FileBrowserPrivateRemoveFileWatchFunction::PerformFileWatchOperation( | 392 void FileManagerPrivateRemoveFileWatchFunction::PerformFileWatchOperation( |
| 393 const base::FilePath& local_path, | 393 const base::FilePath& local_path, |
| 394 const base::FilePath& unused, | 394 const base::FilePath& unused, |
| 395 const std::string& extension_id) { | 395 const std::string& extension_id) { |
| 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 397 | 397 |
| 398 file_manager::EventRouter* event_router = | 398 file_manager::EventRouter* event_router = |
| 399 file_manager::FileBrowserPrivateAPI::Get(GetProfile())->event_router(); | 399 file_manager::FileManagerPrivateAPI::Get(GetProfile())->event_router(); |
| 400 event_router->RemoveFileWatch(local_path, extension_id); | 400 event_router->RemoveFileWatch(local_path, extension_id); |
| 401 Respond(true); | 401 Respond(true); |
| 402 } | 402 } |
| 403 | 403 |
| 404 bool FileBrowserPrivateGetSizeStatsFunction::RunAsync() { | 404 bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { |
| 405 using extensions::api::file_browser_private::GetSizeStats::Params; | 405 using extensions::api::file_manager_private::GetSizeStats::Params; |
| 406 const scoped_ptr<Params> params(Params::Create(*args_)); | 406 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 407 EXTENSION_FUNCTION_VALIDATE(params); | 407 EXTENSION_FUNCTION_VALIDATE(params); |
| 408 | 408 |
| 409 using file_manager::VolumeManager; | 409 using file_manager::VolumeManager; |
| 410 using file_manager::VolumeInfo; | 410 using file_manager::VolumeInfo; |
| 411 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); | 411 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); |
| 412 if (!volume_manager) | 412 if (!volume_manager) |
| 413 return false; | 413 return false; |
| 414 | 414 |
| 415 VolumeInfo volume_info; | 415 VolumeInfo volume_info; |
| 416 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) | 416 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) |
| 417 return false; | 417 return false; |
| 418 | 418 |
| 419 if (volume_info.type == file_manager::VOLUME_TYPE_GOOGLE_DRIVE) { | 419 if (volume_info.type == file_manager::VOLUME_TYPE_GOOGLE_DRIVE) { |
| 420 drive::FileSystemInterface* file_system = | 420 drive::FileSystemInterface* file_system = |
| 421 drive::util::GetFileSystemByProfile(GetProfile()); | 421 drive::util::GetFileSystemByProfile(GetProfile()); |
| 422 if (!file_system) { | 422 if (!file_system) { |
| 423 // |file_system| is NULL if Drive is disabled. | 423 // |file_system| is NULL if Drive is disabled. |
| 424 // If stats couldn't be gotten for drive, result should be left | 424 // If stats couldn't be gotten for drive, result should be left |
| 425 // undefined. See comments in GetDriveAvailableSpaceCallback(). | 425 // undefined. See comments in GetDriveAvailableSpaceCallback(). |
| 426 SendResponse(true); | 426 SendResponse(true); |
| 427 return true; | 427 return true; |
| 428 } | 428 } |
| 429 | 429 |
| 430 file_system->GetAvailableSpace( | 430 file_system->GetAvailableSpace( |
| 431 base::Bind(&FileBrowserPrivateGetSizeStatsFunction:: | 431 base::Bind(&FileManagerPrivateGetSizeStatsFunction:: |
| 432 GetDriveAvailableSpaceCallback, | 432 GetDriveAvailableSpaceCallback, |
| 433 this)); | 433 this)); |
| 434 } else { | 434 } else { |
| 435 uint64* total_size = new uint64(0); | 435 uint64* total_size = new uint64(0); |
| 436 uint64* remaining_size = new uint64(0); | 436 uint64* remaining_size = new uint64(0); |
| 437 BrowserThread::PostBlockingPoolTaskAndReply( | 437 BrowserThread::PostBlockingPoolTaskAndReply( |
| 438 FROM_HERE, | 438 FROM_HERE, |
| 439 base::Bind(&GetSizeStatsOnBlockingPool, | 439 base::Bind(&GetSizeStatsOnBlockingPool, |
| 440 volume_info.mount_path.value(), | 440 volume_info.mount_path.value(), |
| 441 total_size, | 441 total_size, |
| 442 remaining_size), | 442 remaining_size), |
| 443 base::Bind(&FileBrowserPrivateGetSizeStatsFunction:: | 443 base::Bind(&FileManagerPrivateGetSizeStatsFunction:: |
| 444 GetSizeStatsCallback, | 444 GetSizeStatsCallback, |
| 445 this, | 445 this, |
| 446 base::Owned(total_size), | 446 base::Owned(total_size), |
| 447 base::Owned(remaining_size))); | 447 base::Owned(remaining_size))); |
| 448 } | 448 } |
| 449 return true; | 449 return true; |
| 450 } | 450 } |
| 451 | 451 |
| 452 void FileBrowserPrivateGetSizeStatsFunction::GetDriveAvailableSpaceCallback( | 452 void FileManagerPrivateGetSizeStatsFunction::GetDriveAvailableSpaceCallback( |
| 453 drive::FileError error, | 453 drive::FileError error, |
| 454 int64 bytes_total, | 454 int64 bytes_total, |
| 455 int64 bytes_used) { | 455 int64 bytes_used) { |
| 456 if (error == drive::FILE_ERROR_OK) { | 456 if (error == drive::FILE_ERROR_OK) { |
| 457 const uint64 bytes_total_unsigned = bytes_total; | 457 const uint64 bytes_total_unsigned = bytes_total; |
| 458 const uint64 bytes_remaining_unsigned = bytes_total - bytes_used; | 458 const uint64 bytes_remaining_unsigned = bytes_total - bytes_used; |
| 459 GetSizeStatsCallback(&bytes_total_unsigned, | 459 GetSizeStatsCallback(&bytes_total_unsigned, |
| 460 &bytes_remaining_unsigned); | 460 &bytes_remaining_unsigned); |
| 461 } else { | 461 } else { |
| 462 // If stats couldn't be gotten for drive, result should be left undefined. | 462 // If stats couldn't be gotten for drive, result should be left undefined. |
| 463 SendResponse(true); | 463 SendResponse(true); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 | 466 |
| 467 void FileBrowserPrivateGetSizeStatsFunction::GetSizeStatsCallback( | 467 void FileManagerPrivateGetSizeStatsFunction::GetSizeStatsCallback( |
| 468 const uint64* total_size, | 468 const uint64* total_size, |
| 469 const uint64* remaining_size) { | 469 const uint64* remaining_size) { |
| 470 base::DictionaryValue* sizes = new base::DictionaryValue(); | 470 base::DictionaryValue* sizes = new base::DictionaryValue(); |
| 471 SetResult(sizes); | 471 SetResult(sizes); |
| 472 | 472 |
| 473 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); | 473 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); |
| 474 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); | 474 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); |
| 475 | 475 |
| 476 SendResponse(true); | 476 SendResponse(true); |
| 477 } | 477 } |
| 478 | 478 |
| 479 bool FileBrowserPrivateValidatePathNameLengthFunction::RunAsync() { | 479 bool FileManagerPrivateValidatePathNameLengthFunction::RunAsync() { |
| 480 using extensions::api::file_browser_private::ValidatePathNameLength::Params; | 480 using extensions::api::file_manager_private::ValidatePathNameLength::Params; |
| 481 const scoped_ptr<Params> params(Params::Create(*args_)); | 481 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 482 EXTENSION_FUNCTION_VALIDATE(params); | 482 EXTENSION_FUNCTION_VALIDATE(params); |
| 483 | 483 |
| 484 scoped_refptr<storage::FileSystemContext> file_system_context = | 484 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 485 file_manager::util::GetFileSystemContextForRenderViewHost( | 485 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 486 GetProfile(), render_view_host()); | 486 GetProfile(), render_view_host()); |
| 487 | 487 |
| 488 storage::FileSystemURL filesystem_url( | 488 storage::FileSystemURL filesystem_url( |
| 489 file_system_context->CrackURL(GURL(params->parent_directory_url))); | 489 file_system_context->CrackURL(GURL(params->parent_directory_url))); |
| 490 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) | 490 if (!chromeos::FileSystemBackend::CanHandleURL(filesystem_url)) |
| 491 return false; | 491 return false; |
| 492 | 492 |
| 493 // No explicit limit on the length of Drive file names. | 493 // No explicit limit on the length of Drive file names. |
| 494 if (filesystem_url.type() == storage::kFileSystemTypeDrive) { | 494 if (filesystem_url.type() == storage::kFileSystemTypeDrive) { |
| 495 SetResult(new base::FundamentalValue(true)); | 495 SetResult(new base::FundamentalValue(true)); |
| 496 SendResponse(true); | 496 SendResponse(true); |
| 497 return true; | 497 return true; |
| 498 } | 498 } |
| 499 | 499 |
| 500 base::PostTaskAndReplyWithResult( | 500 base::PostTaskAndReplyWithResult( |
| 501 BrowserThread::GetBlockingPool(), | 501 BrowserThread::GetBlockingPool(), |
| 502 FROM_HERE, | 502 FROM_HERE, |
| 503 base::Bind(&GetFileNameMaxLengthOnBlockingPool, | 503 base::Bind(&GetFileNameMaxLengthOnBlockingPool, |
| 504 filesystem_url.path().AsUTF8Unsafe()), | 504 filesystem_url.path().AsUTF8Unsafe()), |
| 505 base::Bind(&FileBrowserPrivateValidatePathNameLengthFunction:: | 505 base::Bind(&FileManagerPrivateValidatePathNameLengthFunction:: |
| 506 OnFilePathLimitRetrieved, | 506 OnFilePathLimitRetrieved, |
| 507 this, params->name.size())); | 507 this, params->name.size())); |
| 508 return true; | 508 return true; |
| 509 } | 509 } |
| 510 | 510 |
| 511 void FileBrowserPrivateValidatePathNameLengthFunction::OnFilePathLimitRetrieved( | 511 void FileManagerPrivateValidatePathNameLengthFunction::OnFilePathLimitRetrieved( |
| 512 size_t current_length, | 512 size_t current_length, |
| 513 size_t max_length) { | 513 size_t max_length) { |
| 514 SetResult(new base::FundamentalValue(current_length <= max_length)); | 514 SetResult(new base::FundamentalValue(current_length <= max_length)); |
| 515 SendResponse(true); | 515 SendResponse(true); |
| 516 } | 516 } |
| 517 | 517 |
| 518 bool FileBrowserPrivateFormatVolumeFunction::RunAsync() { | 518 bool FileManagerPrivateFormatVolumeFunction::RunAsync() { |
| 519 using extensions::api::file_browser_private::FormatVolume::Params; | 519 using extensions::api::file_manager_private::FormatVolume::Params; |
| 520 const scoped_ptr<Params> params(Params::Create(*args_)); | 520 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 521 EXTENSION_FUNCTION_VALIDATE(params); | 521 EXTENSION_FUNCTION_VALIDATE(params); |
| 522 | 522 |
| 523 using file_manager::VolumeManager; | 523 using file_manager::VolumeManager; |
| 524 using file_manager::VolumeInfo; | 524 using file_manager::VolumeInfo; |
| 525 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); | 525 VolumeManager* volume_manager = VolumeManager::Get(GetProfile()); |
| 526 if (!volume_manager) | 526 if (!volume_manager) |
| 527 return false; | 527 return false; |
| 528 | 528 |
| 529 VolumeInfo volume_info; | 529 VolumeInfo volume_info; |
| 530 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) | 530 if (!volume_manager->FindVolumeInfoById(params->volume_id, &volume_info)) |
| 531 return false; | 531 return false; |
| 532 | 532 |
| 533 DiskMountManager::GetInstance()->FormatMountedDevice( | 533 DiskMountManager::GetInstance()->FormatMountedDevice( |
| 534 volume_info.mount_path.AsUTF8Unsafe()); | 534 volume_info.mount_path.AsUTF8Unsafe()); |
| 535 SendResponse(true); | 535 SendResponse(true); |
| 536 return true; | 536 return true; |
| 537 } | 537 } |
| 538 | 538 |
| 539 bool FileBrowserPrivateStartCopyFunction::RunAsync() { | 539 bool FileManagerPrivateStartCopyFunction::RunAsync() { |
| 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 541 | 541 |
| 542 using extensions::api::file_browser_private::StartCopy::Params; | 542 using extensions::api::file_manager_private::StartCopy::Params; |
| 543 const scoped_ptr<Params> params(Params::Create(*args_)); | 543 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 544 EXTENSION_FUNCTION_VALIDATE(params); | 544 EXTENSION_FUNCTION_VALIDATE(params); |
| 545 | 545 |
| 546 if (params->source_url.empty() || params->parent.empty() || | 546 if (params->source_url.empty() || params->parent.empty() || |
| 547 params->new_name.empty()) { | 547 params->new_name.empty()) { |
| 548 // Error code in format of DOMError.name. | 548 // Error code in format of DOMError.name. |
| 549 SetError("EncodingError"); | 549 SetError("EncodingError"); |
| 550 return false; | 550 return false; |
| 551 } | 551 } |
| 552 | 552 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 572 } | 572 } |
| 573 | 573 |
| 574 return BrowserThread::PostTaskAndReplyWithResult( | 574 return BrowserThread::PostTaskAndReplyWithResult( |
| 575 BrowserThread::IO, | 575 BrowserThread::IO, |
| 576 FROM_HERE, | 576 FROM_HERE, |
| 577 base::Bind(&StartCopyOnIOThread, | 577 base::Bind(&StartCopyOnIOThread, |
| 578 GetProfile(), | 578 GetProfile(), |
| 579 file_system_context, | 579 file_system_context, |
| 580 source_url, | 580 source_url, |
| 581 destination_url), | 581 destination_url), |
| 582 base::Bind(&FileBrowserPrivateStartCopyFunction::RunAfterStartCopy, | 582 base::Bind(&FileManagerPrivateStartCopyFunction::RunAfterStartCopy, |
| 583 this)); | 583 this)); |
| 584 } | 584 } |
| 585 | 585 |
| 586 void FileBrowserPrivateStartCopyFunction::RunAfterStartCopy( | 586 void FileManagerPrivateStartCopyFunction::RunAfterStartCopy( |
| 587 int operation_id) { | 587 int operation_id) { |
| 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 589 | 589 |
| 590 SetResult(new base::FundamentalValue(operation_id)); | 590 SetResult(new base::FundamentalValue(operation_id)); |
| 591 SendResponse(true); | 591 SendResponse(true); |
| 592 } | 592 } |
| 593 | 593 |
| 594 bool FileBrowserPrivateCancelCopyFunction::RunAsync() { | 594 bool FileManagerPrivateCancelCopyFunction::RunAsync() { |
| 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 596 | 596 |
| 597 using extensions::api::file_browser_private::CancelCopy::Params; | 597 using extensions::api::file_manager_private::CancelCopy::Params; |
| 598 const scoped_ptr<Params> params(Params::Create(*args_)); | 598 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 599 EXTENSION_FUNCTION_VALIDATE(params); | 599 EXTENSION_FUNCTION_VALIDATE(params); |
| 600 | 600 |
| 601 scoped_refptr<storage::FileSystemContext> file_system_context = | 601 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 602 file_manager::util::GetFileSystemContextForRenderViewHost( | 602 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 603 GetProfile(), render_view_host()); | 603 GetProfile(), render_view_host()); |
| 604 | 604 |
| 605 // We don't much take care about the result of cancellation. | 605 // We don't much take care about the result of cancellation. |
| 606 BrowserThread::PostTask( | 606 BrowserThread::PostTask( |
| 607 BrowserThread::IO, | 607 BrowserThread::IO, |
| 608 FROM_HERE, | 608 FROM_HERE, |
| 609 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); | 609 base::Bind(&CancelCopyOnIOThread, file_system_context, params->copy_id)); |
| 610 SendResponse(true); | 610 SendResponse(true); |
| 611 return true; | 611 return true; |
| 612 } | 612 } |
| 613 | 613 |
| 614 bool FileBrowserPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { | 614 bool FileManagerPrivateInternalResolveIsolatedEntriesFunction::RunAsync() { |
| 615 using extensions::api::file_browser_private_internal::ResolveIsolatedEntries:: | 615 using extensions::api::file_manager_private_internal::ResolveIsolatedEntries:: |
| 616 Params; | 616 Params; |
| 617 const scoped_ptr<Params> params(Params::Create(*args_)); | 617 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 618 EXTENSION_FUNCTION_VALIDATE(params); | 618 EXTENSION_FUNCTION_VALIDATE(params); |
| 619 | 619 |
| 620 scoped_refptr<storage::FileSystemContext> file_system_context = | 620 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 621 file_manager::util::GetFileSystemContextForRenderViewHost( | 621 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 622 GetProfile(), render_view_host()); | 622 GetProfile(), render_view_host()); |
| 623 DCHECK(file_system_context); | 623 DCHECK(file_system_context); |
| 624 | 624 |
| 625 const storage::ExternalFileSystemBackend* external_backend = | 625 const storage::ExternalFileSystemBackend* external_backend = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 644 // The API only supports isolated files. | 644 // The API only supports isolated files. |
| 645 file_definition.is_directory = false; | 645 file_definition.is_directory = false; |
| 646 file_definition_list.push_back(file_definition); | 646 file_definition_list.push_back(file_definition); |
| 647 } | 647 } |
| 648 | 648 |
| 649 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( | 649 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( |
| 650 GetProfile(), | 650 GetProfile(), |
| 651 extension_->id(), | 651 extension_->id(), |
| 652 file_definition_list, // Safe, since copied internally. | 652 file_definition_list, // Safe, since copied internally. |
| 653 base::Bind( | 653 base::Bind( |
| 654 &FileBrowserPrivateInternalResolveIsolatedEntriesFunction:: | 654 &FileManagerPrivateInternalResolveIsolatedEntriesFunction:: |
| 655 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList, | 655 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList, |
| 656 this)); | 656 this)); |
| 657 return true; | 657 return true; |
| 658 } | 658 } |
| 659 | 659 |
| 660 void FileBrowserPrivateInternalResolveIsolatedEntriesFunction:: | 660 void FileManagerPrivateInternalResolveIsolatedEntriesFunction:: |
| 661 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr< | 661 RunAsyncAfterConvertFileDefinitionListToEntryDefinitionList(scoped_ptr< |
| 662 file_manager::util::EntryDefinitionList> entry_definition_list) { | 662 file_manager::util::EntryDefinitionList> entry_definition_list) { |
| 663 using extensions::api::file_browser_private_internal::EntryDescription; | 663 using extensions::api::file_manager_private_internal::EntryDescription; |
| 664 std::vector<linked_ptr<EntryDescription> > entries; | 664 std::vector<linked_ptr<EntryDescription> > entries; |
| 665 | 665 |
| 666 for (size_t i = 0; i < entry_definition_list->size(); ++i) { | 666 for (size_t i = 0; i < entry_definition_list->size(); ++i) { |
| 667 if (entry_definition_list->at(i).error != base::File::FILE_OK) | 667 if (entry_definition_list->at(i).error != base::File::FILE_OK) |
| 668 continue; | 668 continue; |
| 669 linked_ptr<EntryDescription> entry(new EntryDescription); | 669 linked_ptr<EntryDescription> entry(new EntryDescription); |
| 670 entry->file_system_name = entry_definition_list->at(i).file_system_name; | 670 entry->file_system_name = entry_definition_list->at(i).file_system_name; |
| 671 entry->file_system_root = entry_definition_list->at(i).file_system_root_url; | 671 entry->file_system_root = entry_definition_list->at(i).file_system_root_url; |
| 672 entry->file_full_path = | 672 entry->file_full_path = |
| 673 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); | 673 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe(); |
| 674 entry->file_is_directory = entry_definition_list->at(i).is_directory; | 674 entry->file_is_directory = entry_definition_list->at(i).is_directory; |
| 675 entries.push_back(entry); | 675 entries.push_back(entry); |
| 676 } | 676 } |
| 677 | 677 |
| 678 results_ = extensions::api::file_browser_private_internal:: | 678 results_ = extensions::api::file_manager_private_internal:: |
| 679 ResolveIsolatedEntries::Results::Create(entries); | 679 ResolveIsolatedEntries::Results::Create(entries); |
| 680 SendResponse(true); | 680 SendResponse(true); |
| 681 } | 681 } |
| 682 } // namespace extensions | 682 } // namespace extensions |
| OLD | NEW |