| 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 <set> | 9 #include <set> |
| 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 17 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 18 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 ->GrantCreateReadWriteFile(render_frame_host()->GetProcess()->GetID(), | 322 ->GrantCreateReadWriteFile(render_frame_host()->GetProcess()->GetID(), |
| 322 file_system_url.path()); | 323 file_system_url.path()); |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 return RespondNow(NoArguments()); | 326 return RespondNow(NoArguments()); |
| 326 } | 327 } |
| 327 | 328 |
| 328 void FileWatchFunctionBase::Respond(bool success) { | 329 void FileWatchFunctionBase::Respond(bool success) { |
| 329 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 330 | 331 |
| 331 SetResult(new base::FundamentalValue(success)); | 332 SetResult(base::MakeUnique<base::FundamentalValue>(success)); |
| 332 SendResponse(success); | 333 SendResponse(success); |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool FileWatchFunctionBase::RunAsync() { | 336 bool FileWatchFunctionBase::RunAsync() { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 337 | 338 |
| 338 if (!render_frame_host() || !render_frame_host()->GetProcess()) | 339 if (!render_frame_host() || !render_frame_host()->GetProcess()) |
| 339 return false; | 340 return false; |
| 340 | 341 |
| 341 // First param is url of a file to watch. | 342 // First param is url of a file to watch. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 525 } |
| 525 | 526 |
| 526 const uint64_t max_capacity = mtp_storage_info.max_capacity(); | 527 const uint64_t max_capacity = mtp_storage_info.max_capacity(); |
| 527 const uint64_t free_space_in_bytes = mtp_storage_info.free_space_in_bytes(); | 528 const uint64_t free_space_in_bytes = mtp_storage_info.free_space_in_bytes(); |
| 528 OnGetSizeStats(&max_capacity, &free_space_in_bytes); | 529 OnGetSizeStats(&max_capacity, &free_space_in_bytes); |
| 529 } | 530 } |
| 530 | 531 |
| 531 void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( | 532 void FileManagerPrivateGetSizeStatsFunction::OnGetSizeStats( |
| 532 const uint64_t* total_size, | 533 const uint64_t* total_size, |
| 533 const uint64_t* remaining_size) { | 534 const uint64_t* remaining_size) { |
| 534 base::DictionaryValue* sizes = new base::DictionaryValue(); | 535 std::unique_ptr<base::DictionaryValue> sizes(new base::DictionaryValue()); |
| 535 SetResult(sizes); | |
| 536 | 536 |
| 537 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); | 537 sizes->SetDouble("totalSize", static_cast<double>(*total_size)); |
| 538 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); | 538 sizes->SetDouble("remainingSize", static_cast<double>(*remaining_size)); |
| 539 | 539 |
| 540 SetResult(std::move(sizes)); |
| 540 SendResponse(true); | 541 SendResponse(true); |
| 541 } | 542 } |
| 542 | 543 |
| 543 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { | 544 bool FileManagerPrivateInternalValidatePathNameLengthFunction::RunAsync() { |
| 544 using extensions::api::file_manager_private_internal::ValidatePathNameLength:: | 545 using extensions::api::file_manager_private_internal::ValidatePathNameLength:: |
| 545 Params; | 546 Params; |
| 546 const std::unique_ptr<Params> params(Params::Create(*args_)); | 547 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 547 EXTENSION_FUNCTION_VALIDATE(params); | 548 EXTENSION_FUNCTION_VALIDATE(params); |
| 548 | 549 |
| 549 scoped_refptr<storage::FileSystemContext> file_system_context = | 550 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 550 file_manager::util::GetFileSystemContextForRenderFrameHost( | 551 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 551 GetProfile(), render_frame_host()); | 552 GetProfile(), render_frame_host()); |
| 552 | 553 |
| 553 const storage::FileSystemURL file_system_url( | 554 const storage::FileSystemURL file_system_url( |
| 554 file_system_context->CrackURL(GURL(params->parent_url))); | 555 file_system_context->CrackURL(GURL(params->parent_url))); |
| 555 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) | 556 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) |
| 556 return false; | 557 return false; |
| 557 | 558 |
| 558 // No explicit limit on the length of Drive file names. | 559 // No explicit limit on the length of Drive file names. |
| 559 if (file_system_url.type() == storage::kFileSystemTypeDrive) { | 560 if (file_system_url.type() == storage::kFileSystemTypeDrive) { |
| 560 SetResult(new base::FundamentalValue(true)); | 561 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
| 561 SendResponse(true); | 562 SendResponse(true); |
| 562 return true; | 563 return true; |
| 563 } | 564 } |
| 564 | 565 |
| 565 base::PostTaskAndReplyWithResult( | 566 base::PostTaskAndReplyWithResult( |
| 566 BrowserThread::GetBlockingPool(), FROM_HERE, | 567 BrowserThread::GetBlockingPool(), FROM_HERE, |
| 567 base::Bind(&GetFileNameMaxLengthOnBlockingPool, | 568 base::Bind(&GetFileNameMaxLengthOnBlockingPool, |
| 568 file_system_url.path().AsUTF8Unsafe()), | 569 file_system_url.path().AsUTF8Unsafe()), |
| 569 base::Bind(&FileManagerPrivateInternalValidatePathNameLengthFunction:: | 570 base::Bind(&FileManagerPrivateInternalValidatePathNameLengthFunction:: |
| 570 OnFilePathLimitRetrieved, | 571 OnFilePathLimitRetrieved, |
| 571 this, params->name.size())); | 572 this, params->name.size())); |
| 572 return true; | 573 return true; |
| 573 } | 574 } |
| 574 | 575 |
| 575 void FileManagerPrivateInternalValidatePathNameLengthFunction:: | 576 void FileManagerPrivateInternalValidatePathNameLengthFunction:: |
| 576 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { | 577 OnFilePathLimitRetrieved(size_t current_length, size_t max_length) { |
| 577 SetResult(new base::FundamentalValue(current_length <= max_length)); | 578 SetResult( |
| 579 base::MakeUnique<base::FundamentalValue>(current_length <= max_length)); |
| 578 SendResponse(true); | 580 SendResponse(true); |
| 579 } | 581 } |
| 580 | 582 |
| 581 bool FileManagerPrivateFormatVolumeFunction::RunAsync() { | 583 bool FileManagerPrivateFormatVolumeFunction::RunAsync() { |
| 582 using extensions::api::file_manager_private::FormatVolume::Params; | 584 using extensions::api::file_manager_private::FormatVolume::Params; |
| 583 const std::unique_ptr<Params> params(Params::Create(*args_)); | 585 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 584 EXTENSION_FUNCTION_VALIDATE(params); | 586 EXTENSION_FUNCTION_VALIDATE(params); |
| 585 | 587 |
| 586 using file_manager::VolumeManager; | 588 using file_manager::VolumeManager; |
| 587 using file_manager::Volume; | 589 using file_manager::Volume; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 &FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy, | 729 &FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy, |
| 728 this)); | 730 this)); |
| 729 if (!result) | 731 if (!result) |
| 730 SendResponse(false); | 732 SendResponse(false); |
| 731 } | 733 } |
| 732 | 734 |
| 733 void FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy( | 735 void FileManagerPrivateInternalStartCopyFunction::RunAfterStartCopy( |
| 734 int operation_id) { | 736 int operation_id) { |
| 735 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 737 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 736 | 738 |
| 737 SetResult(new base::FundamentalValue(operation_id)); | 739 SetResult(base::MakeUnique<base::FundamentalValue>(operation_id)); |
| 738 SendResponse(true); | 740 SendResponse(true); |
| 739 } | 741 } |
| 740 | 742 |
| 741 bool FileManagerPrivateCancelCopyFunction::RunAsync() { | 743 bool FileManagerPrivateCancelCopyFunction::RunAsync() { |
| 742 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 744 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 743 | 745 |
| 744 using extensions::api::file_manager_private::CancelCopy::Params; | 746 using extensions::api::file_manager_private::CancelCopy::Params; |
| 745 const std::unique_ptr<Params> params(Params::Create(*args_)); | 747 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 746 EXTENSION_FUNCTION_VALIDATE(params); | 748 EXTENSION_FUNCTION_VALIDATE(params); |
| 747 | 749 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 base::Bind(&FileStreamMd5Digester::GetMd5Digest, | 870 base::Bind(&FileStreamMd5Digester::GetMd5Digest, |
| 869 base::Unretained(digester_.get()), | 871 base::Unretained(digester_.get()), |
| 870 base::Passed(&reader), result_callback)); | 872 base::Passed(&reader), result_callback)); |
| 871 | 873 |
| 872 return true; | 874 return true; |
| 873 } | 875 } |
| 874 | 876 |
| 875 void FileManagerPrivateInternalComputeChecksumFunction::Respond( | 877 void FileManagerPrivateInternalComputeChecksumFunction::Respond( |
| 876 const std::string& hash) { | 878 const std::string& hash) { |
| 877 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 879 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 878 SetResult(new base::StringValue(hash)); | 880 SetResult(base::MakeUnique<base::StringValue>(hash)); |
| 879 SendResponse(true); | 881 SendResponse(true); |
| 880 } | 882 } |
| 881 | 883 |
| 882 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { | 884 bool FileManagerPrivateSearchFilesByHashesFunction::RunAsync() { |
| 883 using api::file_manager_private::SearchFilesByHashes::Params; | 885 using api::file_manager_private::SearchFilesByHashes::Params; |
| 884 const std::unique_ptr<Params> params(Params::Create(*args_)); | 886 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 885 EXTENSION_FUNCTION_VALIDATE(params); | 887 EXTENSION_FUNCTION_VALIDATE(params); |
| 886 | 888 |
| 887 // TODO(hirono): Check the volume ID and fail the function for volumes other | 889 // TODO(hirono): Check the volume ID and fail the function for volumes other |
| 888 // than Drive. | 890 // than Drive. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 } | 932 } |
| 931 | 933 |
| 932 for (const auto& hashAndPath : search_results) { | 934 for (const auto& hashAndPath : search_results) { |
| 933 DCHECK(result->HasKey(hashAndPath.hash)); | 935 DCHECK(result->HasKey(hashAndPath.hash)); |
| 934 base::ListValue* list; | 936 base::ListValue* list; |
| 935 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); | 937 result->GetListWithoutPathExpansion(hashAndPath.hash, &list); |
| 936 list->AppendString( | 938 list->AppendString( |
| 937 file_manager::util::ConvertDrivePathToFileSystemUrl( | 939 file_manager::util::ConvertDrivePathToFileSystemUrl( |
| 938 GetProfile(), hashAndPath.path, extension_id()).spec()); | 940 GetProfile(), hashAndPath.path, extension_id()).spec()); |
| 939 } | 941 } |
| 940 SetResult(result.release()); | 942 SetResult(std::move(result)); |
| 941 SendResponse(true); | 943 SendResponse(true); |
| 942 } | 944 } |
| 943 | 945 |
| 944 ExtensionFunction::ResponseAction | 946 ExtensionFunction::ResponseAction |
| 945 FileManagerPrivateIsUMAEnabledFunction::Run() { | 947 FileManagerPrivateIsUMAEnabledFunction::Run() { |
| 946 return RespondNow(OneArgument(new base::FundamentalValue( | 948 return RespondNow(OneArgument(new base::FundamentalValue( |
| 947 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); | 949 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()))); |
| 948 } | 950 } |
| 949 | 951 |
| 950 FileManagerPrivateInternalSetEntryTagFunction:: | 952 FileManagerPrivateInternalSetEntryTagFunction:: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 return RespondLater(); | 993 return RespondLater(); |
| 992 } | 994 } |
| 993 | 995 |
| 994 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( | 996 void FileManagerPrivateInternalSetEntryTagFunction::OnSetEntryPropertyCompleted( |
| 995 drive::FileError result) { | 997 drive::FileError result) { |
| 996 Respond(result == drive::FILE_ERROR_OK ? NoArguments() | 998 Respond(result == drive::FILE_ERROR_OK ? NoArguments() |
| 997 : Error("Failed to set a tag.")); | 999 : Error("Failed to set a tag.")); |
| 998 } | 1000 } |
| 999 | 1001 |
| 1000 } // namespace extensions | 1002 } // namespace extensions |
| OLD | NEW |