| 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_drive.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 14 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 14 #include "chrome/browser/chromeos/drive/file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 15 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 16 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 16 #include "chrome/browser/chromeos/file_manager/file_tasks.h" | 17 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| 17 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 18 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 18 #include "chrome/browser/chromeos/file_manager/url_util.h" | 19 #include "chrome/browser/chromeos/file_manager/url_util.h" |
| 19 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 20 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 20 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 21 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" | 22 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 173 |
| 173 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( | 174 file_manager::util::ConvertFileDefinitionListToEntryDefinitionList( |
| 174 profile, | 175 profile, |
| 175 extension_id, | 176 extension_id, |
| 176 file_definition_list, // Safe, since copied internally. | 177 file_definition_list, // Safe, since copied internally. |
| 177 callback); | 178 callback); |
| 178 } | 179 } |
| 179 | 180 |
| 180 class SingleEntryPropertiesGetterForDrive { | 181 class SingleEntryPropertiesGetterForDrive { |
| 181 public: | 182 public: |
| 182 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, | 183 typedef base::Callback<void(std::unique_ptr<EntryProperties> properties, |
| 183 base::File::Error error)> ResultCallback; | 184 base::File::Error error)> |
| 185 ResultCallback; |
| 184 | 186 |
| 185 // Creates an instance and starts the process. | 187 // Creates an instance and starts the process. |
| 186 static void Start(const base::FilePath local_path, | 188 static void Start(const base::FilePath local_path, |
| 187 const std::set<EntryPropertyName>& names, | 189 const std::set<EntryPropertyName>& names, |
| 188 Profile* const profile, | 190 Profile* const profile, |
| 189 const ResultCallback& callback) { | 191 const ResultCallback& callback) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 192 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 | 193 |
| 192 SingleEntryPropertiesGetterForDrive* instance = | 194 SingleEntryPropertiesGetterForDrive* instance = |
| 193 new SingleEntryPropertiesGetterForDrive(local_path, names, profile, | 195 new SingleEntryPropertiesGetterForDrive(local_path, names, profile, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 return; | 239 return; |
| 238 } | 240 } |
| 239 | 241 |
| 240 file_system->GetResourceEntry( | 242 file_system->GetResourceEntry( |
| 241 file_path_, | 243 file_path_, |
| 242 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo, | 244 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo, |
| 243 weak_ptr_factory_.GetWeakPtr())); | 245 weak_ptr_factory_.GetWeakPtr())); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void OnGetFileInfo(drive::FileError error, | 248 void OnGetFileInfo(drive::FileError error, |
| 247 scoped_ptr<drive::ResourceEntry> entry) { | 249 std::unique_ptr<drive::ResourceEntry> entry) { |
| 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 249 | 251 |
| 250 if (error != drive::FILE_ERROR_OK) { | 252 if (error != drive::FILE_ERROR_OK) { |
| 251 CompleteGetEntryProperties(error); | 253 CompleteGetEntryProperties(error); |
| 252 return; | 254 return; |
| 253 } | 255 } |
| 254 | 256 |
| 255 DCHECK(entry); | 257 DCHECK(entry); |
| 256 owner_resource_entry_.swap(entry); | 258 owner_resource_entry_.swap(entry); |
| 257 | 259 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return; | 294 return; |
| 293 } | 295 } |
| 294 | 296 |
| 295 file_system->GetResourceEntry( | 297 file_system->GetResourceEntry( |
| 296 file_path, | 298 file_path, |
| 297 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo, | 299 base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo, |
| 298 weak_ptr_factory_.GetWeakPtr())); | 300 weak_ptr_factory_.GetWeakPtr())); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void OnGetShareInfo(drive::FileError error, | 303 void OnGetShareInfo(drive::FileError error, |
| 302 scoped_ptr<drive::ResourceEntry> entry) { | 304 std::unique_ptr<drive::ResourceEntry> entry) { |
| 303 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 305 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 304 | 306 |
| 305 if (error != drive::FILE_ERROR_OK) { | 307 if (error != drive::FILE_ERROR_OK) { |
| 306 CompleteGetEntryProperties(error); | 308 CompleteGetEntryProperties(error); |
| 307 return; | 309 return; |
| 308 } | 310 } |
| 309 | 311 |
| 310 DCHECK(entry.get()); | 312 DCHECK(entry.get()); |
| 311 StartParseFileInfo(entry->shared_with_me()); | 313 StartParseFileInfo(entry->shared_with_me()); |
| 312 } | 314 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 drive::FileErrorToBaseFileError(error)); | 376 drive::FileErrorToBaseFileError(error)); |
| 375 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 377 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 376 } | 378 } |
| 377 | 379 |
| 378 // Given parameters. | 380 // Given parameters. |
| 379 const ResultCallback callback_; | 381 const ResultCallback callback_; |
| 380 const base::FilePath local_path_; | 382 const base::FilePath local_path_; |
| 381 Profile* const running_profile_; | 383 Profile* const running_profile_; |
| 382 | 384 |
| 383 // Values used in the process. | 385 // Values used in the process. |
| 384 scoped_ptr<EntryProperties> properties_; | 386 std::unique_ptr<EntryProperties> properties_; |
| 385 Profile* file_owner_profile_; | 387 Profile* file_owner_profile_; |
| 386 base::FilePath file_path_; | 388 base::FilePath file_path_; |
| 387 scoped_ptr<drive::ResourceEntry> owner_resource_entry_; | 389 std::unique_ptr<drive::ResourceEntry> owner_resource_entry_; |
| 388 | 390 |
| 389 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_; | 391 base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_; |
| 390 }; // class SingleEntryPropertiesGetterForDrive | 392 }; // class SingleEntryPropertiesGetterForDrive |
| 391 | 393 |
| 392 class SingleEntryPropertiesGetterForFileSystemProvider { | 394 class SingleEntryPropertiesGetterForFileSystemProvider { |
| 393 public: | 395 public: |
| 394 typedef base::Callback<void(scoped_ptr<EntryProperties> properties, | 396 typedef base::Callback<void(std::unique_ptr<EntryProperties> properties, |
| 395 base::File::Error error)> ResultCallback; | 397 base::File::Error error)> |
| 398 ResultCallback; |
| 396 | 399 |
| 397 // Creates an instance and starts the process. | 400 // Creates an instance and starts the process. |
| 398 static void Start(const storage::FileSystemURL file_system_url, | 401 static void Start(const storage::FileSystemURL file_system_url, |
| 399 const std::set<EntryPropertyName>& names, | 402 const std::set<EntryPropertyName>& names, |
| 400 const ResultCallback& callback) { | 403 const ResultCallback& callback) { |
| 401 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 404 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 402 | 405 |
| 403 SingleEntryPropertiesGetterForFileSystemProvider* instance = | 406 SingleEntryPropertiesGetterForFileSystemProvider* instance = |
| 404 new SingleEntryPropertiesGetterForFileSystemProvider(file_system_url, | 407 new SingleEntryPropertiesGetterForFileSystemProvider(file_system_url, |
| 405 names, callback); | 408 names, callback); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 field_mask |= ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL; | 458 field_mask |= ProvidedFileSystemInterface::METADATA_FIELD_THUMBNAIL; |
| 456 } | 459 } |
| 457 | 460 |
| 458 parser.file_system()->GetMetadata( | 461 parser.file_system()->GetMetadata( |
| 459 parser.file_path(), field_mask, | 462 parser.file_path(), field_mask, |
| 460 base::Bind(&SingleEntryPropertiesGetterForFileSystemProvider:: | 463 base::Bind(&SingleEntryPropertiesGetterForFileSystemProvider:: |
| 461 OnGetMetadataCompleted, | 464 OnGetMetadataCompleted, |
| 462 weak_ptr_factory_.GetWeakPtr())); | 465 weak_ptr_factory_.GetWeakPtr())); |
| 463 } | 466 } |
| 464 | 467 |
| 465 void OnGetMetadataCompleted(scoped_ptr<EntryMetadata> metadata, | 468 void OnGetMetadataCompleted(std::unique_ptr<EntryMetadata> metadata, |
| 466 base::File::Error result) { | 469 base::File::Error result) { |
| 467 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 470 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 468 | 471 |
| 469 if (result != base::File::FILE_OK) { | 472 if (result != base::File::FILE_OK) { |
| 470 CompleteGetEntryProperties(result); | 473 CompleteGetEntryProperties(result); |
| 471 return; | 474 return; |
| 472 } | 475 } |
| 473 | 476 |
| 474 if (names_.find(api::file_manager_private::ENTRY_PROPERTY_NAME_SIZE) != | 477 if (names_.find(api::file_manager_private::ENTRY_PROPERTY_NAME_SIZE) != |
| 475 names_.end()) { | 478 names_.end()) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 callback_.Run(std::move(properties_), result); | 511 callback_.Run(std::move(properties_), result); |
| 509 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); | 512 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this); |
| 510 } | 513 } |
| 511 | 514 |
| 512 // Given parameters. | 515 // Given parameters. |
| 513 const ResultCallback callback_; | 516 const ResultCallback callback_; |
| 514 const storage::FileSystemURL file_system_url_; | 517 const storage::FileSystemURL file_system_url_; |
| 515 const std::set<EntryPropertyName> names_; | 518 const std::set<EntryPropertyName> names_; |
| 516 | 519 |
| 517 // Values used in the process. | 520 // Values used in the process. |
| 518 scoped_ptr<EntryProperties> properties_; | 521 std::unique_ptr<EntryProperties> properties_; |
| 519 | 522 |
| 520 base::WeakPtrFactory<SingleEntryPropertiesGetterForFileSystemProvider> | 523 base::WeakPtrFactory<SingleEntryPropertiesGetterForFileSystemProvider> |
| 521 weak_ptr_factory_; | 524 weak_ptr_factory_; |
| 522 }; // class SingleEntryPropertiesGetterForDrive | 525 }; // class SingleEntryPropertiesGetterForDrive |
| 523 | 526 |
| 524 } // namespace | 527 } // namespace |
| 525 | 528 |
| 526 FileManagerPrivateInternalGetEntryPropertiesFunction:: | 529 FileManagerPrivateInternalGetEntryPropertiesFunction:: |
| 527 FileManagerPrivateInternalGetEntryPropertiesFunction() | 530 FileManagerPrivateInternalGetEntryPropertiesFunction() |
| 528 : processed_count_(0) { | 531 : processed_count_(0) { |
| 529 } | 532 } |
| 530 | 533 |
| 531 FileManagerPrivateInternalGetEntryPropertiesFunction:: | 534 FileManagerPrivateInternalGetEntryPropertiesFunction:: |
| 532 ~FileManagerPrivateInternalGetEntryPropertiesFunction() { | 535 ~FileManagerPrivateInternalGetEntryPropertiesFunction() { |
| 533 } | 536 } |
| 534 | 537 |
| 535 bool FileManagerPrivateInternalGetEntryPropertiesFunction::RunAsync() { | 538 bool FileManagerPrivateInternalGetEntryPropertiesFunction::RunAsync() { |
| 536 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 539 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 537 | 540 |
| 538 using api::file_manager_private_internal::GetEntryProperties::Params; | 541 using api::file_manager_private_internal::GetEntryProperties::Params; |
| 539 const scoped_ptr<Params> params(Params::Create(*args_)); | 542 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 540 EXTENSION_FUNCTION_VALIDATE(params); | 543 EXTENSION_FUNCTION_VALIDATE(params); |
| 541 | 544 |
| 542 scoped_refptr<storage::FileSystemContext> file_system_context = | 545 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 543 file_manager::util::GetFileSystemContextForRenderFrameHost( | 546 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 544 GetProfile(), render_frame_host()); | 547 GetProfile(), render_frame_host()); |
| 545 | 548 |
| 546 properties_list_.resize(params->urls.size()); | 549 properties_list_.resize(params->urls.size()); |
| 547 const std::set<EntryPropertyName> names_as_set(params->names.begin(), | 550 const std::set<EntryPropertyName> names_as_set(params->names.begin(), |
| 548 params->names.end()); | 551 params->names.end()); |
| 549 for (size_t i = 0; i < params->urls.size(); i++) { | 552 for (size_t i = 0; i < params->urls.size(); i++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 563 file_system_url, names_as_set, | 566 file_system_url, names_as_set, |
| 564 base::Bind(&FileManagerPrivateInternalGetEntryPropertiesFunction:: | 567 base::Bind(&FileManagerPrivateInternalGetEntryPropertiesFunction:: |
| 565 CompleteGetEntryProperties, | 568 CompleteGetEntryProperties, |
| 566 this, i, file_system_url)); | 569 this, i, file_system_url)); |
| 567 break; | 570 break; |
| 568 default: | 571 default: |
| 569 // TODO(yawano) Change this to support other voluems (e.g. local) ,and | 572 // TODO(yawano) Change this to support other voluems (e.g. local) ,and |
| 570 // integrate fileManagerPrivate.getMimeType to this method. | 573 // integrate fileManagerPrivate.getMimeType to this method. |
| 571 LOG(ERROR) << "Not supported file system type."; | 574 LOG(ERROR) << "Not supported file system type."; |
| 572 CompleteGetEntryProperties(i, file_system_url, | 575 CompleteGetEntryProperties(i, file_system_url, |
| 573 make_scoped_ptr(new EntryProperties), | 576 base::WrapUnique(new EntryProperties), |
| 574 base::File::FILE_ERROR_INVALID_OPERATION); | 577 base::File::FILE_ERROR_INVALID_OPERATION); |
| 575 } | 578 } |
| 576 } | 579 } |
| 577 | 580 |
| 578 return true; | 581 return true; |
| 579 } | 582 } |
| 580 | 583 |
| 581 void FileManagerPrivateInternalGetEntryPropertiesFunction:: | 584 void FileManagerPrivateInternalGetEntryPropertiesFunction:: |
| 582 CompleteGetEntryProperties(size_t index, | 585 CompleteGetEntryProperties(size_t index, |
| 583 const storage::FileSystemURL& url, | 586 const storage::FileSystemURL& url, |
| 584 scoped_ptr<EntryProperties> properties, | 587 std::unique_ptr<EntryProperties> properties, |
| 585 base::File::Error error) { | 588 base::File::Error error) { |
| 586 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 589 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 587 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size()); | 590 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size()); |
| 588 | 591 |
| 589 if (error == base::File::FILE_OK) { | 592 if (error == base::File::FILE_OK) { |
| 590 properties->external_file_url.reset( | 593 properties->external_file_url.reset( |
| 591 new std::string(chromeos::FileSystemURLToExternalFileURL(url).spec())); | 594 new std::string(chromeos::FileSystemURLToExternalFileURL(url).spec())); |
| 592 } | 595 } |
| 593 properties_list_[index] = std::move(*properties); | 596 properties_list_[index] = std::move(*properties); |
| 594 | 597 |
| 595 processed_count_++; | 598 processed_count_++; |
| 596 if (processed_count_ < properties_list_.size()) | 599 if (processed_count_ < properties_list_.size()) |
| 597 return; | 600 return; |
| 598 | 601 |
| 599 results_ = extensions::api::file_manager_private_internal:: | 602 results_ = extensions::api::file_manager_private_internal:: |
| 600 GetEntryProperties::Results::Create(properties_list_); | 603 GetEntryProperties::Results::Create(properties_list_); |
| 601 SendResponse(true); | 604 SendResponse(true); |
| 602 } | 605 } |
| 603 | 606 |
| 604 bool FileManagerPrivateInternalPinDriveFileFunction::RunAsync() { | 607 bool FileManagerPrivateInternalPinDriveFileFunction::RunAsync() { |
| 605 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 608 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 606 | 609 |
| 607 using extensions::api::file_manager_private_internal::PinDriveFile::Params; | 610 using extensions::api::file_manager_private_internal::PinDriveFile::Params; |
| 608 const scoped_ptr<Params> params(Params::Create(*args_)); | 611 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 609 EXTENSION_FUNCTION_VALIDATE(params); | 612 EXTENSION_FUNCTION_VALIDATE(params); |
| 610 | 613 |
| 611 drive::FileSystemInterface* const file_system = | 614 drive::FileSystemInterface* const file_system = |
| 612 drive::util::GetFileSystemByProfile(GetProfile()); | 615 drive::util::GetFileSystemByProfile(GetProfile()); |
| 613 if (!file_system) // |file_system| is NULL if Drive is disabled. | 616 if (!file_system) // |file_system| is NULL if Drive is disabled. |
| 614 return false; | 617 return false; |
| 615 | 618 |
| 616 const base::FilePath drive_path = | 619 const base::FilePath drive_path = |
| 617 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( | 620 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( |
| 618 render_frame_host(), GetProfile(), GURL(params->url))); | 621 render_frame_host(), GetProfile(), GURL(params->url))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 640 SendResponse(true); | 643 SendResponse(true); |
| 641 } else { | 644 } else { |
| 642 SetError(drive::FileErrorToString(error)); | 645 SetError(drive::FileErrorToString(error)); |
| 643 SendResponse(false); | 646 SendResponse(false); |
| 644 } | 647 } |
| 645 } | 648 } |
| 646 | 649 |
| 647 bool FileManagerPrivateInternalCancelFileTransfersFunction::RunAsync() { | 650 bool FileManagerPrivateInternalCancelFileTransfersFunction::RunAsync() { |
| 648 using extensions::api::file_manager_private_internal::CancelFileTransfers:: | 651 using extensions::api::file_manager_private_internal::CancelFileTransfers:: |
| 649 Params; | 652 Params; |
| 650 const scoped_ptr<Params> params(Params::Create(*args_)); | 653 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 651 EXTENSION_FUNCTION_VALIDATE(params); | 654 EXTENSION_FUNCTION_VALIDATE(params); |
| 652 | 655 |
| 653 drive::DriveIntegrationService* integration_service = | 656 drive::DriveIntegrationService* integration_service = |
| 654 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); | 657 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); |
| 655 if (!integration_service || !integration_service->IsMounted()) | 658 if (!integration_service || !integration_service->IsMounted()) |
| 656 return false; | 659 return false; |
| 657 | 660 |
| 658 drive::JobListInterface* const job_list = integration_service->job_list(); | 661 drive::JobListInterface* const job_list = integration_service->job_list(); |
| 659 DCHECK(job_list); | 662 DCHECK(job_list); |
| 660 const std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); | 663 const std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 if (drive::IsActiveFileTransferJobInfo(jobs[i])) | 705 if (drive::IsActiveFileTransferJobInfo(jobs[i])) |
| 703 job_list->CancelJob(jobs[i].job_id); | 706 job_list->CancelJob(jobs[i].job_id); |
| 704 } | 707 } |
| 705 | 708 |
| 706 SendResponse(true); | 709 SendResponse(true); |
| 707 return true; | 710 return true; |
| 708 } | 711 } |
| 709 | 712 |
| 710 bool FileManagerPrivateSearchDriveFunction::RunAsync() { | 713 bool FileManagerPrivateSearchDriveFunction::RunAsync() { |
| 711 using extensions::api::file_manager_private::SearchDrive::Params; | 714 using extensions::api::file_manager_private::SearchDrive::Params; |
| 712 const scoped_ptr<Params> params(Params::Create(*args_)); | 715 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 713 EXTENSION_FUNCTION_VALIDATE(params); | 716 EXTENSION_FUNCTION_VALIDATE(params); |
| 714 | 717 |
| 715 drive::FileSystemInterface* const file_system = | 718 drive::FileSystemInterface* const file_system = |
| 716 drive::util::GetFileSystemByProfile(GetProfile()); | 719 drive::util::GetFileSystemByProfile(GetProfile()); |
| 717 if (!file_system) { | 720 if (!file_system) { |
| 718 // |file_system| is NULL if Drive is disabled. | 721 // |file_system| is NULL if Drive is disabled. |
| 719 return false; | 722 return false; |
| 720 } | 723 } |
| 721 | 724 |
| 722 file_system->Search( | 725 file_system->Search( |
| 723 params->search_params.query, GURL(params->search_params.next_feed), | 726 params->search_params.query, GURL(params->search_params.next_feed), |
| 724 base::Bind(&FileManagerPrivateSearchDriveFunction::OnSearch, this)); | 727 base::Bind(&FileManagerPrivateSearchDriveFunction::OnSearch, this)); |
| 725 return true; | 728 return true; |
| 726 } | 729 } |
| 727 | 730 |
| 728 void FileManagerPrivateSearchDriveFunction::OnSearch( | 731 void FileManagerPrivateSearchDriveFunction::OnSearch( |
| 729 drive::FileError error, | 732 drive::FileError error, |
| 730 const GURL& next_link, | 733 const GURL& next_link, |
| 731 scoped_ptr<SearchResultInfoList> results) { | 734 std::unique_ptr<SearchResultInfoList> results) { |
| 732 if (error != drive::FILE_ERROR_OK) { | 735 if (error != drive::FILE_ERROR_OK) { |
| 733 SendResponse(false); | 736 SendResponse(false); |
| 734 return; | 737 return; |
| 735 } | 738 } |
| 736 | 739 |
| 737 // Outlives the following conversion, since the pointer is bound to the | 740 // Outlives the following conversion, since the pointer is bound to the |
| 738 // callback. | 741 // callback. |
| 739 DCHECK(results.get()); | 742 DCHECK(results.get()); |
| 740 const SearchResultInfoList& results_ref = *results.get(); | 743 const SearchResultInfoList& results_ref = *results.get(); |
| 741 | 744 |
| 742 ConvertSearchResultInfoListToEntryDefinitionList( | 745 ConvertSearchResultInfoListToEntryDefinitionList( |
| 743 GetProfile(), | 746 GetProfile(), |
| 744 extension_->id(), | 747 extension_->id(), |
| 745 results_ref, | 748 results_ref, |
| 746 base::Bind(&FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList, | 749 base::Bind(&FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList, |
| 747 this, | 750 this, |
| 748 next_link, | 751 next_link, |
| 749 base::Passed(&results))); | 752 base::Passed(&results))); |
| 750 } | 753 } |
| 751 | 754 |
| 752 void FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList( | 755 void FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList( |
| 753 const GURL& next_link, | 756 const GURL& next_link, |
| 754 scoped_ptr<SearchResultInfoList> search_result_info_list, | 757 std::unique_ptr<SearchResultInfoList> search_result_info_list, |
| 755 scoped_ptr<EntryDefinitionList> entry_definition_list) { | 758 std::unique_ptr<EntryDefinitionList> entry_definition_list) { |
| 756 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); | 759 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); |
| 757 base::ListValue* entries = new base::ListValue(); | 760 base::ListValue* entries = new base::ListValue(); |
| 758 | 761 |
| 759 // Convert Drive files to something File API stack can understand. | 762 // Convert Drive files to something File API stack can understand. |
| 760 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin(); | 763 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin(); |
| 761 it != entry_definition_list->end(); | 764 it != entry_definition_list->end(); |
| 762 ++it) { | 765 ++it) { |
| 763 base::DictionaryValue* entry = new base::DictionaryValue(); | 766 base::DictionaryValue* entry = new base::DictionaryValue(); |
| 764 entry->SetString("fileSystemName", it->file_system_name); | 767 entry->SetString("fileSystemName", it->file_system_name); |
| 765 entry->SetString("fileSystemRoot", it->file_system_root_url); | 768 entry->SetString("fileSystemRoot", it->file_system_root_url); |
| 766 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); | 769 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); |
| 767 entry->SetBoolean("fileIsDirectory", it->is_directory); | 770 entry->SetBoolean("fileIsDirectory", it->is_directory); |
| 768 entries->Append(entry); | 771 entries->Append(entry); |
| 769 } | 772 } |
| 770 | 773 |
| 771 base::DictionaryValue* result = new base::DictionaryValue(); | 774 base::DictionaryValue* result = new base::DictionaryValue(); |
| 772 result->Set("entries", entries); | 775 result->Set("entries", entries); |
| 773 result->SetString("nextFeed", next_link.spec()); | 776 result->SetString("nextFeed", next_link.spec()); |
| 774 | 777 |
| 775 SetResult(result); | 778 SetResult(result); |
| 776 SendResponse(true); | 779 SendResponse(true); |
| 777 } | 780 } |
| 778 | 781 |
| 779 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() { | 782 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() { |
| 780 using api::file_manager_private::SearchDriveMetadata::Params; | 783 using api::file_manager_private::SearchDriveMetadata::Params; |
| 781 const scoped_ptr<Params> params(Params::Create(*args_)); | 784 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 782 EXTENSION_FUNCTION_VALIDATE(params); | 785 EXTENSION_FUNCTION_VALIDATE(params); |
| 783 | 786 |
| 784 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 787 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 785 if (logger) { | 788 if (logger) { |
| 786 logger->Log(logging::LOG_INFO, | 789 logger->Log(logging::LOG_INFO, |
| 787 "%s[%d] called. (types: '%s', maxResults: '%d')", name(), | 790 "%s[%d] called. (types: '%s', maxResults: '%d')", name(), |
| 788 request_id(), api::file_manager_private::ToString( | 791 request_id(), api::file_manager_private::ToString( |
| 789 params->search_params.types).c_str(), | 792 params->search_params.types).c_str(), |
| 790 params->search_params.max_results); | 793 params->search_params.max_results); |
| 791 } | 794 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 821 params->search_params.query, | 824 params->search_params.query, |
| 822 options, | 825 options, |
| 823 params->search_params.max_results, | 826 params->search_params.max_results, |
| 824 base::Bind(&FileManagerPrivateSearchDriveMetadataFunction:: | 827 base::Bind(&FileManagerPrivateSearchDriveMetadataFunction:: |
| 825 OnSearchMetadata, this)); | 828 OnSearchMetadata, this)); |
| 826 return true; | 829 return true; |
| 827 } | 830 } |
| 828 | 831 |
| 829 void FileManagerPrivateSearchDriveMetadataFunction::OnSearchMetadata( | 832 void FileManagerPrivateSearchDriveMetadataFunction::OnSearchMetadata( |
| 830 drive::FileError error, | 833 drive::FileError error, |
| 831 scoped_ptr<drive::MetadataSearchResultVector> results) { | 834 std::unique_ptr<drive::MetadataSearchResultVector> results) { |
| 832 if (error != drive::FILE_ERROR_OK) { | 835 if (error != drive::FILE_ERROR_OK) { |
| 833 SendResponse(false); | 836 SendResponse(false); |
| 834 return; | 837 return; |
| 835 } | 838 } |
| 836 | 839 |
| 837 // Outlives the following conversion, since the pointer is bound to the | 840 // Outlives the following conversion, since the pointer is bound to the |
| 838 // callback. | 841 // callback. |
| 839 DCHECK(results.get()); | 842 DCHECK(results.get()); |
| 840 const drive::MetadataSearchResultVector& results_ref = *results.get(); | 843 const drive::MetadataSearchResultVector& results_ref = *results.get(); |
| 841 | 844 |
| 842 ConvertSearchResultInfoListToEntryDefinitionList( | 845 ConvertSearchResultInfoListToEntryDefinitionList( |
| 843 GetProfile(), | 846 GetProfile(), |
| 844 extension_->id(), | 847 extension_->id(), |
| 845 results_ref, | 848 results_ref, |
| 846 base::Bind( | 849 base::Bind( |
| 847 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, | 850 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, |
| 848 this, | 851 this, |
| 849 base::Passed(&results))); | 852 base::Passed(&results))); |
| 850 } | 853 } |
| 851 | 854 |
| 852 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( | 855 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( |
| 853 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list, | 856 std::unique_ptr<drive::MetadataSearchResultVector> search_result_info_list, |
| 854 scoped_ptr<EntryDefinitionList> entry_definition_list) { | 857 std::unique_ptr<EntryDefinitionList> entry_definition_list) { |
| 855 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); | 858 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); |
| 856 base::ListValue* results_list = new base::ListValue(); | 859 base::ListValue* results_list = new base::ListValue(); |
| 857 | 860 |
| 858 // Convert Drive files to something File API stack can understand. See | 861 // Convert Drive files to something File API stack can understand. See |
| 859 // file_browser_handler_custom_bindings.cc and | 862 // file_browser_handler_custom_bindings.cc and |
| 860 // file_manager_private_custom_bindings.js for how this is magically | 863 // file_manager_private_custom_bindings.js for how this is magically |
| 861 // converted to a FileEntry. | 864 // converted to a FileEntry. |
| 862 for (size_t i = 0; i < entry_definition_list->size(); ++i) { | 865 for (size_t i = 0; i < entry_definition_list->size(); ++i) { |
| 863 base::DictionaryValue* result_dict = new base::DictionaryValue(); | 866 base::DictionaryValue* result_dict = new base::DictionaryValue(); |
| 864 | 867 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 Create(result); | 920 Create(result); |
| 918 | 921 |
| 919 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); | 922 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); |
| 920 if (logger) | 923 if (logger) |
| 921 logger->Log(logging::LOG_INFO, "%s succeeded.", name()); | 924 logger->Log(logging::LOG_INFO, "%s succeeded.", name()); |
| 922 return true; | 925 return true; |
| 923 } | 926 } |
| 924 | 927 |
| 925 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { | 928 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() { |
| 926 using extensions::api::file_manager_private::RequestAccessToken::Params; | 929 using extensions::api::file_manager_private::RequestAccessToken::Params; |
| 927 const scoped_ptr<Params> params(Params::Create(*args_)); | 930 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 928 EXTENSION_FUNCTION_VALIDATE(params); | 931 EXTENSION_FUNCTION_VALIDATE(params); |
| 929 | 932 |
| 930 drive::DriveServiceInterface* const drive_service = | 933 drive::DriveServiceInterface* const drive_service = |
| 931 drive::util::GetDriveServiceByProfile(GetProfile()); | 934 drive::util::GetDriveServiceByProfile(GetProfile()); |
| 932 | 935 |
| 933 if (!drive_service) { | 936 if (!drive_service) { |
| 934 // DriveService is not available. | 937 // DriveService is not available. |
| 935 SetResult(new base::StringValue("")); | 938 SetResult(new base::StringValue("")); |
| 936 SendResponse(true); | 939 SendResponse(true); |
| 937 return true; | 940 return true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 951 | 954 |
| 952 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( | 955 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched( |
| 953 google_apis::DriveApiErrorCode code, | 956 google_apis::DriveApiErrorCode code, |
| 954 const std::string& access_token) { | 957 const std::string& access_token) { |
| 955 SetResult(new base::StringValue(access_token)); | 958 SetResult(new base::StringValue(access_token)); |
| 956 SendResponse(true); | 959 SendResponse(true); |
| 957 } | 960 } |
| 958 | 961 |
| 959 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { | 962 bool FileManagerPrivateInternalGetShareUrlFunction::RunAsync() { |
| 960 using extensions::api::file_manager_private_internal::GetShareUrl::Params; | 963 using extensions::api::file_manager_private_internal::GetShareUrl::Params; |
| 961 const scoped_ptr<Params> params(Params::Create(*args_)); | 964 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 962 EXTENSION_FUNCTION_VALIDATE(params); | 965 EXTENSION_FUNCTION_VALIDATE(params); |
| 963 | 966 |
| 964 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 967 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 965 render_frame_host(), GetProfile(), GURL(params->url)); | 968 render_frame_host(), GetProfile(), GURL(params->url)); |
| 966 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 969 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
| 967 | 970 |
| 968 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 971 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
| 969 | 972 |
| 970 drive::FileSystemInterface* const file_system = | 973 drive::FileSystemInterface* const file_system = |
| 971 drive::util::GetFileSystemByProfile(GetProfile()); | 974 drive::util::GetFileSystemByProfile(GetProfile()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 991 return; | 994 return; |
| 992 } | 995 } |
| 993 | 996 |
| 994 SetResult(new base::StringValue(share_url.spec())); | 997 SetResult(new base::StringValue(share_url.spec())); |
| 995 SendResponse(true); | 998 SendResponse(true); |
| 996 } | 999 } |
| 997 | 1000 |
| 998 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { | 1001 bool FileManagerPrivateInternalRequestDriveShareFunction::RunAsync() { |
| 999 using extensions::api::file_manager_private_internal::RequestDriveShare:: | 1002 using extensions::api::file_manager_private_internal::RequestDriveShare:: |
| 1000 Params; | 1003 Params; |
| 1001 const scoped_ptr<Params> params(Params::Create(*args_)); | 1004 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 1002 EXTENSION_FUNCTION_VALIDATE(params); | 1005 EXTENSION_FUNCTION_VALIDATE(params); |
| 1003 | 1006 |
| 1004 const base::FilePath path = file_manager::util::GetLocalPathFromURL( | 1007 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 1005 render_frame_host(), GetProfile(), GURL(params->url)); | 1008 render_frame_host(), GetProfile(), GURL(params->url)); |
| 1006 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 1009 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
| 1007 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path); | 1010 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path); |
| 1008 | 1011 |
| 1009 if (!owner_profile) | 1012 if (!owner_profile) |
| 1010 return false; | 1013 return false; |
| 1011 | 1014 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 } | 1054 } |
| 1052 | 1055 |
| 1053 FileManagerPrivateInternalGetDownloadUrlFunction:: | 1056 FileManagerPrivateInternalGetDownloadUrlFunction:: |
| 1054 FileManagerPrivateInternalGetDownloadUrlFunction() {} | 1057 FileManagerPrivateInternalGetDownloadUrlFunction() {} |
| 1055 | 1058 |
| 1056 FileManagerPrivateInternalGetDownloadUrlFunction:: | 1059 FileManagerPrivateInternalGetDownloadUrlFunction:: |
| 1057 ~FileManagerPrivateInternalGetDownloadUrlFunction() {} | 1060 ~FileManagerPrivateInternalGetDownloadUrlFunction() {} |
| 1058 | 1061 |
| 1059 bool FileManagerPrivateInternalGetDownloadUrlFunction::RunAsync() { | 1062 bool FileManagerPrivateInternalGetDownloadUrlFunction::RunAsync() { |
| 1060 using extensions::api::file_manager_private_internal::GetShareUrl::Params; | 1063 using extensions::api::file_manager_private_internal::GetShareUrl::Params; |
| 1061 const scoped_ptr<Params> params(Params::Create(*args_)); | 1064 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 1062 EXTENSION_FUNCTION_VALIDATE(params); | 1065 EXTENSION_FUNCTION_VALIDATE(params); |
| 1063 | 1066 |
| 1064 // Start getting the file info. | 1067 // Start getting the file info. |
| 1065 drive::FileSystemInterface* const file_system = | 1068 drive::FileSystemInterface* const file_system = |
| 1066 drive::util::GetFileSystemByProfile(GetProfile()); | 1069 drive::util::GetFileSystemByProfile(GetProfile()); |
| 1067 if (!file_system) { | 1070 if (!file_system) { |
| 1068 // |file_system| is NULL if Drive is disabled or not mounted. | 1071 // |file_system| is NULL if Drive is disabled or not mounted. |
| 1069 SetError("Drive is disabled or not mounted."); | 1072 SetError("Drive is disabled or not mounted."); |
| 1070 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1073 SetResult(new base::StringValue("")); // Intentionally returns a blank. |
| 1071 return false; | 1074 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1083 file_system->GetResourceEntry( | 1086 file_system->GetResourceEntry( |
| 1084 file_path, | 1087 file_path, |
| 1085 base::Bind( | 1088 base::Bind( |
| 1086 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, | 1089 &FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry, |
| 1087 this)); | 1090 this)); |
| 1088 return true; | 1091 return true; |
| 1089 } | 1092 } |
| 1090 | 1093 |
| 1091 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( | 1094 void FileManagerPrivateInternalGetDownloadUrlFunction::OnGetResourceEntry( |
| 1092 drive::FileError error, | 1095 drive::FileError error, |
| 1093 scoped_ptr<drive::ResourceEntry> entry) { | 1096 std::unique_ptr<drive::ResourceEntry> entry) { |
| 1094 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1097 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1095 | 1098 |
| 1096 if (error != drive::FILE_ERROR_OK) { | 1099 if (error != drive::FILE_ERROR_OK) { |
| 1097 SetError("Download Url for this item is not available."); | 1100 SetError("Download Url for this item is not available."); |
| 1098 SetResult(new base::StringValue("")); // Intentionally returns a blank. | 1101 SetResult(new base::StringValue("")); // Intentionally returns a blank. |
| 1099 SendResponse(false); | 1102 SendResponse(false); |
| 1100 return; | 1103 return; |
| 1101 } | 1104 } |
| 1102 | 1105 |
| 1103 DriveApiUrlGenerator url_generator( | 1106 DriveApiUrlGenerator url_generator( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1138 } |
| 1136 | 1139 |
| 1137 const std::string url = | 1140 const std::string url = |
| 1138 download_url_.Resolve("?access_token=" + access_token).spec(); | 1141 download_url_.Resolve("?access_token=" + access_token).spec(); |
| 1139 SetResult(new base::StringValue(url)); | 1142 SetResult(new base::StringValue(url)); |
| 1140 | 1143 |
| 1141 SendResponse(true); | 1144 SendResponse(true); |
| 1142 } | 1145 } |
| 1143 | 1146 |
| 1144 } // namespace extensions | 1147 } // namespace extensions |
| OLD | NEW |