Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc

Issue 550863003: Rename fileBrowserPrivate to fileManagerPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
(...skipping 16 matching lines...) Expand all
27 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "google_apis/drive/auth_service.h" 28 #include "google_apis/drive/auth_service.h"
29 #include "storage/common/fileapi/file_system_info.h" 29 #include "storage/common/fileapi/file_system_info.h"
30 #include "storage/common/fileapi/file_system_util.h" 30 #include "storage/common/fileapi/file_system_util.h"
31 31
32 using content::BrowserThread; 32 using content::BrowserThread;
33 33
34 using chromeos::file_system_provider::EntryMetadata; 34 using chromeos::file_system_provider::EntryMetadata;
35 using chromeos::file_system_provider::ProvidedFileSystemInterface; 35 using chromeos::file_system_provider::ProvidedFileSystemInterface;
36 using chromeos::file_system_provider::util::FileSystemURLParser; 36 using chromeos::file_system_provider::util::FileSystemURLParser;
37 using extensions::api::file_browser_private::EntryProperties; 37 using extensions::api::file_manager_private::EntryProperties;
38 using file_manager::util::EntryDefinition; 38 using file_manager::util::EntryDefinition;
39 using file_manager::util::EntryDefinitionCallback; 39 using file_manager::util::EntryDefinitionCallback;
40 using file_manager::util::EntryDefinitionList; 40 using file_manager::util::EntryDefinitionList;
41 using file_manager::util::EntryDefinitionListCallback; 41 using file_manager::util::EntryDefinitionListCallback;
42 using file_manager::util::FileDefinition; 42 using file_manager::util::FileDefinition;
43 using file_manager::util::FileDefinitionList; 43 using file_manager::util::FileDefinitionList;
44 44
45 namespace extensions { 45 namespace extensions {
46 namespace { 46 namespace {
47 47
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 438
439 // Values used in the process. 439 // Values used in the process.
440 scoped_ptr<EntryProperties> properties_; 440 scoped_ptr<EntryProperties> properties_;
441 441
442 base::WeakPtrFactory<SingleEntryPropertiesGetterForFileSystemProvider> 442 base::WeakPtrFactory<SingleEntryPropertiesGetterForFileSystemProvider>
443 weak_ptr_factory_; 443 weak_ptr_factory_;
444 }; // class SingleEntryPropertiesGetterForDrive 444 }; // class SingleEntryPropertiesGetterForDrive
445 445
446 } // namespace 446 } // namespace
447 447
448 FileBrowserPrivateGetEntryPropertiesFunction:: 448 FileManagerPrivateGetEntryPropertiesFunction::
449 FileBrowserPrivateGetEntryPropertiesFunction() 449 FileManagerPrivateGetEntryPropertiesFunction()
450 : processed_count_(0) { 450 : processed_count_(0) {
451 } 451 }
452 452
453 FileBrowserPrivateGetEntryPropertiesFunction:: 453 FileManagerPrivateGetEntryPropertiesFunction::
454 ~FileBrowserPrivateGetEntryPropertiesFunction() { 454 ~FileManagerPrivateGetEntryPropertiesFunction() {
455 } 455 }
456 456
457 bool FileBrowserPrivateGetEntryPropertiesFunction::RunAsync() { 457 bool FileManagerPrivateGetEntryPropertiesFunction::RunAsync() {
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
459 459
460 using api::file_browser_private::GetEntryProperties::Params; 460 using api::file_manager_private::GetEntryProperties::Params;
461 const scoped_ptr<Params> params(Params::Create(*args_)); 461 const scoped_ptr<Params> params(Params::Create(*args_));
462 EXTENSION_FUNCTION_VALIDATE(params); 462 EXTENSION_FUNCTION_VALIDATE(params);
463 463
464 scoped_refptr<storage::FileSystemContext> file_system_context = 464 scoped_refptr<storage::FileSystemContext> file_system_context =
465 file_manager::util::GetFileSystemContextForRenderViewHost( 465 file_manager::util::GetFileSystemContextForRenderViewHost(
466 GetProfile(), render_view_host()); 466 GetProfile(), render_view_host());
467 467
468 properties_list_.resize(params->file_urls.size()); 468 properties_list_.resize(params->file_urls.size());
469 for (size_t i = 0; i < params->file_urls.size(); i++) { 469 for (size_t i = 0; i < params->file_urls.size(); i++) {
470 const GURL url = GURL(params->file_urls[i]); 470 const GURL url = GURL(params->file_urls[i]);
471 const storage::FileSystemURL file_system_url = 471 const storage::FileSystemURL file_system_url =
472 file_system_context->CrackURL(url); 472 file_system_context->CrackURL(url);
473 switch (file_system_url.type()) { 473 switch (file_system_url.type()) {
474 case storage::kFileSystemTypeDrive: 474 case storage::kFileSystemTypeDrive:
475 SingleEntryPropertiesGetterForDrive::Start( 475 SingleEntryPropertiesGetterForDrive::Start(
476 file_system_url.path(), 476 file_system_url.path(),
477 GetProfile(), 477 GetProfile(),
478 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: 478 base::Bind(&FileManagerPrivateGetEntryPropertiesFunction::
479 CompleteGetEntryProperties, 479 CompleteGetEntryProperties,
480 this, 480 this,
481 i)); 481 i));
482 break; 482 break;
483 case storage::kFileSystemTypeProvided: 483 case storage::kFileSystemTypeProvided:
484 SingleEntryPropertiesGetterForFileSystemProvider::Start( 484 SingleEntryPropertiesGetterForFileSystemProvider::Start(
485 file_system_url, 485 file_system_url,
486 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: 486 base::Bind(&FileManagerPrivateGetEntryPropertiesFunction::
487 CompleteGetEntryProperties, 487 CompleteGetEntryProperties,
488 this, 488 this,
489 i)); 489 i));
490 break; 490 break;
491 default: 491 default:
492 LOG(ERROR) << "Not supported file system type."; 492 LOG(ERROR) << "Not supported file system type.";
493 CompleteGetEntryProperties(i, 493 CompleteGetEntryProperties(i,
494 make_scoped_ptr(new EntryProperties), 494 make_scoped_ptr(new EntryProperties),
495 base::File::FILE_ERROR_INVALID_OPERATION); 495 base::File::FILE_ERROR_INVALID_OPERATION);
496 } 496 }
497 } 497 }
498 498
499 return true; 499 return true;
500 } 500 }
501 501
502 void FileBrowserPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties( 502 void FileManagerPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties(
503 size_t index, 503 size_t index,
504 scoped_ptr<EntryProperties> properties, 504 scoped_ptr<EntryProperties> properties,
505 base::File::Error error) { 505 base::File::Error error) {
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
507 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size()); 507 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size());
508 508
509 properties_list_[index] = make_linked_ptr(properties.release()); 509 properties_list_[index] = make_linked_ptr(properties.release());
510 510
511 processed_count_++; 511 processed_count_++;
512 if (processed_count_ < properties_list_.size()) 512 if (processed_count_ < properties_list_.size())
513 return; 513 return;
514 514
515 results_ = extensions::api::file_browser_private::GetEntryProperties:: 515 results_ = extensions::api::file_manager_private::GetEntryProperties::
516 Results::Create(properties_list_); 516 Results::Create(properties_list_);
517 SendResponse(true); 517 SendResponse(true);
518 } 518 }
519 519
520 bool FileBrowserPrivatePinDriveFileFunction::RunAsync() { 520 bool FileManagerPrivatePinDriveFileFunction::RunAsync() {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
522 522
523 using extensions::api::file_browser_private::PinDriveFile::Params; 523 using extensions::api::file_manager_private::PinDriveFile::Params;
524 const scoped_ptr<Params> params(Params::Create(*args_)); 524 const scoped_ptr<Params> params(Params::Create(*args_));
525 EXTENSION_FUNCTION_VALIDATE(params); 525 EXTENSION_FUNCTION_VALIDATE(params);
526 526
527 drive::FileSystemInterface* const file_system = 527 drive::FileSystemInterface* const file_system =
528 drive::util::GetFileSystemByProfile(GetProfile()); 528 drive::util::GetFileSystemByProfile(GetProfile());
529 if (!file_system) // |file_system| is NULL if Drive is disabled. 529 if (!file_system) // |file_system| is NULL if Drive is disabled.
530 return false; 530 return false;
531 531
532 const base::FilePath drive_path = 532 const base::FilePath drive_path =
533 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( 533 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL(
534 render_view_host(), GetProfile(), GURL(params->file_url))); 534 render_view_host(), GetProfile(), GURL(params->file_url)));
535 if (params->pin) { 535 if (params->pin) {
536 file_system->Pin(drive_path, 536 file_system->Pin(drive_path,
537 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: 537 base::Bind(&FileManagerPrivatePinDriveFileFunction::
538 OnPinStateSet, this)); 538 OnPinStateSet, this));
539 } else { 539 } else {
540 file_system->Unpin(drive_path, 540 file_system->Unpin(drive_path,
541 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: 541 base::Bind(&FileManagerPrivatePinDriveFileFunction::
542 OnPinStateSet, this)); 542 OnPinStateSet, this));
543 } 543 }
544 return true; 544 return true;
545 } 545 }
546 546
547 void FileBrowserPrivatePinDriveFileFunction:: 547 void FileManagerPrivatePinDriveFileFunction::
548 OnPinStateSet(drive::FileError error) { 548 OnPinStateSet(drive::FileError error) {
549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
550 550
551 if (error == drive::FILE_ERROR_OK) { 551 if (error == drive::FILE_ERROR_OK) {
552 SendResponse(true); 552 SendResponse(true);
553 } else { 553 } else {
554 SetError(drive::FileErrorToString(error)); 554 SetError(drive::FileErrorToString(error));
555 SendResponse(false); 555 SendResponse(false);
556 } 556 }
557 } 557 }
558 558
559 FileBrowserPrivateGetDriveFilesFunction:: 559 FileManagerPrivateGetDriveFilesFunction::
560 FileBrowserPrivateGetDriveFilesFunction() { 560 FileManagerPrivateGetDriveFilesFunction() {
561 } 561 }
562 562
563 FileBrowserPrivateGetDriveFilesFunction:: 563 FileManagerPrivateGetDriveFilesFunction::
564 ~FileBrowserPrivateGetDriveFilesFunction() { 564 ~FileManagerPrivateGetDriveFilesFunction() {
565 } 565 }
566 566
567 bool FileBrowserPrivateGetDriveFilesFunction::RunAsync() { 567 bool FileManagerPrivateGetDriveFilesFunction::RunAsync() {
568 using extensions::api::file_browser_private::GetDriveFiles::Params; 568 using extensions::api::file_manager_private::GetDriveFiles::Params;
569 const scoped_ptr<Params> params(Params::Create(*args_)); 569 const scoped_ptr<Params> params(Params::Create(*args_));
570 EXTENSION_FUNCTION_VALIDATE(params); 570 EXTENSION_FUNCTION_VALIDATE(params);
571 571
572 // Convert the list of strings to a list of GURLs. 572 // Convert the list of strings to a list of GURLs.
573 for (size_t i = 0; i < params->file_urls.size(); ++i) { 573 for (size_t i = 0; i < params->file_urls.size(); ++i) {
574 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 574 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
575 render_view_host(), GetProfile(), GURL(params->file_urls[i])); 575 render_view_host(), GetProfile(), GURL(params->file_urls[i]));
576 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 576 DCHECK(drive::util::IsUnderDriveMountPoint(path));
577 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 577 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
578 remaining_drive_paths_.push(drive_path); 578 remaining_drive_paths_.push(drive_path);
579 } 579 }
580 580
581 GetFileOrSendResponse(); 581 GetFileOrSendResponse();
582 return true; 582 return true;
583 } 583 }
584 584
585 void FileBrowserPrivateGetDriveFilesFunction::GetFileOrSendResponse() { 585 void FileManagerPrivateGetDriveFilesFunction::GetFileOrSendResponse() {
586 // Send the response if all files are obtained. 586 // Send the response if all files are obtained.
587 if (remaining_drive_paths_.empty()) { 587 if (remaining_drive_paths_.empty()) {
588 results_ = extensions::api::file_browser_private:: 588 results_ = extensions::api::file_manager_private::
589 GetDriveFiles::Results::Create(local_paths_); 589 GetDriveFiles::Results::Create(local_paths_);
590 SendResponse(true); 590 SendResponse(true);
591 return; 591 return;
592 } 592 }
593 593
594 // Get the file on the top of the queue. 594 // Get the file on the top of the queue.
595 base::FilePath drive_path = remaining_drive_paths_.front(); 595 base::FilePath drive_path = remaining_drive_paths_.front();
596 596
597 drive::FileSystemInterface* file_system = 597 drive::FileSystemInterface* file_system =
598 drive::util::GetFileSystemByProfile(GetProfile()); 598 drive::util::GetFileSystemByProfile(GetProfile());
599 if (!file_system) { 599 if (!file_system) {
600 // |file_system| is NULL if Drive is disabled or not mounted. 600 // |file_system| is NULL if Drive is disabled or not mounted.
601 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, 601 OnFileReady(drive::FILE_ERROR_FAILED, drive_path,
602 scoped_ptr<drive::ResourceEntry>()); 602 scoped_ptr<drive::ResourceEntry>());
603 return; 603 return;
604 } 604 }
605 605
606 file_system->GetFile( 606 file_system->GetFile(
607 drive_path, 607 drive_path,
608 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this)); 608 base::Bind(&FileManagerPrivateGetDriveFilesFunction::OnFileReady, this));
609 } 609 }
610 610
611 611
612 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady( 612 void FileManagerPrivateGetDriveFilesFunction::OnFileReady(
613 drive::FileError error, 613 drive::FileError error,
614 const base::FilePath& local_path, 614 const base::FilePath& local_path,
615 scoped_ptr<drive::ResourceEntry> entry) { 615 scoped_ptr<drive::ResourceEntry> entry) {
616 base::FilePath drive_path = remaining_drive_paths_.front(); 616 base::FilePath drive_path = remaining_drive_paths_.front();
617 617
618 if (error == drive::FILE_ERROR_OK) { 618 if (error == drive::FILE_ERROR_OK) {
619 local_paths_.push_back(local_path.AsUTF8Unsafe()); 619 local_paths_.push_back(local_path.AsUTF8Unsafe());
620 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); 620 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value();
621 } else { 621 } else {
622 local_paths_.push_back(""); 622 local_paths_.push_back("");
623 DVLOG(1) << "Failed to get " << drive_path.value() 623 DVLOG(1) << "Failed to get " << drive_path.value()
624 << " with error code: " << error; 624 << " with error code: " << error;
625 } 625 }
626 626
627 remaining_drive_paths_.pop(); 627 remaining_drive_paths_.pop();
628 628
629 // Start getting the next file. 629 // Start getting the next file.
630 GetFileOrSendResponse(); 630 GetFileOrSendResponse();
631 } 631 }
632 632
633 bool FileBrowserPrivateCancelFileTransfersFunction::RunAsync() { 633 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() {
634 using extensions::api::file_browser_private::CancelFileTransfers::Params; 634 using extensions::api::file_manager_private::CancelFileTransfers::Params;
635 const scoped_ptr<Params> params(Params::Create(*args_)); 635 const scoped_ptr<Params> params(Params::Create(*args_));
636 EXTENSION_FUNCTION_VALIDATE(params); 636 EXTENSION_FUNCTION_VALIDATE(params);
637 637
638 drive::DriveIntegrationService* integration_service = 638 drive::DriveIntegrationService* integration_service =
639 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); 639 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile());
640 if (!integration_service || !integration_service->IsMounted()) 640 if (!integration_service || !integration_service->IsMounted())
641 return false; 641 return false;
642 642
643 // Create the mapping from file path to job ID. 643 // Create the mapping from file path to job ID.
644 drive::JobListInterface* job_list = integration_service->job_list(); 644 drive::JobListInterface* job_list = integration_service->job_list();
645 DCHECK(job_list); 645 DCHECK(job_list);
646 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); 646 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList();
647 647
648 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; 648 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap;
649 PathToIdMap path_to_id_map; 649 PathToIdMap path_to_id_map;
650 for (size_t i = 0; i < jobs.size(); ++i) { 650 for (size_t i = 0; i < jobs.size(); ++i) {
651 if (drive::IsActiveFileTransferJobInfo(jobs[i])) 651 if (drive::IsActiveFileTransferJobInfo(jobs[i]))
652 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); 652 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id);
653 } 653 }
654 654
655 // Cancel by Job ID. 655 // Cancel by Job ID.
656 std::vector<linked_ptr<api::file_browser_private:: 656 std::vector<linked_ptr<api::file_manager_private::
657 FileTransferCancelStatus> > responses; 657 FileTransferCancelStatus> > responses;
658 for (size_t i = 0; i < params->file_urls.size(); ++i) { 658 for (size_t i = 0; i < params->file_urls.size(); ++i) {
659 base::FilePath file_path = file_manager::util::GetLocalPathFromURL( 659 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
660 render_view_host(), GetProfile(), GURL(params->file_urls[i])); 660 render_view_host(), GetProfile(), GURL(params->file_urls[i]));
661 if (file_path.empty()) 661 if (file_path.empty())
662 continue; 662 continue;
663 663
664 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); 664 DCHECK(drive::util::IsUnderDriveMountPoint(file_path));
665 file_path = drive::util::ExtractDrivePath(file_path); 665 file_path = drive::util::ExtractDrivePath(file_path);
666 666
667 // Cancel all the jobs for the file. 667 // Cancel all the jobs for the file.
668 PathToIdMap::iterator it = path_to_id_map.find(file_path); 668 PathToIdMap::iterator it = path_to_id_map.find(file_path);
669 if (it != path_to_id_map.end()) { 669 if (it != path_to_id_map.end()) {
670 for (size_t i = 0; i < it->second.size(); ++i) 670 for (size_t i = 0; i < it->second.size(); ++i)
671 job_list->CancelJob(it->second[i]); 671 job_list->CancelJob(it->second[i]);
672 } 672 }
673 linked_ptr<api::file_browser_private::FileTransferCancelStatus> result( 673 linked_ptr<api::file_manager_private::FileTransferCancelStatus> result(
674 new api::file_browser_private::FileTransferCancelStatus); 674 new api::file_manager_private::FileTransferCancelStatus);
675 result->canceled = it != path_to_id_map.end(); 675 result->canceled = it != path_to_id_map.end();
676 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, 676 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time,
677 // and eliminate this field; it is just returning a copy of the argument. 677 // and eliminate this field; it is just returning a copy of the argument.
678 result->file_url = params->file_urls[i]; 678 result->file_url = params->file_urls[i];
679 responses.push_back(result); 679 responses.push_back(result);
680 } 680 }
681 results_ = api::file_browser_private::CancelFileTransfers::Results::Create( 681 results_ = api::file_manager_private::CancelFileTransfers::Results::Create(
682 responses); 682 responses);
683 SendResponse(true); 683 SendResponse(true);
684 return true; 684 return true;
685 } 685 }
686 686
687 bool FileBrowserPrivateSearchDriveFunction::RunAsync() { 687 bool FileManagerPrivateSearchDriveFunction::RunAsync() {
688 using extensions::api::file_browser_private::SearchDrive::Params; 688 using extensions::api::file_manager_private::SearchDrive::Params;
689 const scoped_ptr<Params> params(Params::Create(*args_)); 689 const scoped_ptr<Params> params(Params::Create(*args_));
690 EXTENSION_FUNCTION_VALIDATE(params); 690 EXTENSION_FUNCTION_VALIDATE(params);
691 691
692 drive::FileSystemInterface* const file_system = 692 drive::FileSystemInterface* const file_system =
693 drive::util::GetFileSystemByProfile(GetProfile()); 693 drive::util::GetFileSystemByProfile(GetProfile());
694 if (!file_system) { 694 if (!file_system) {
695 // |file_system| is NULL if Drive is disabled. 695 // |file_system| is NULL if Drive is disabled.
696 return false; 696 return false;
697 } 697 }
698 698
699 file_system->Search( 699 file_system->Search(
700 params->search_params.query, GURL(params->search_params.next_feed), 700 params->search_params.query, GURL(params->search_params.next_feed),
701 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this)); 701 base::Bind(&FileManagerPrivateSearchDriveFunction::OnSearch, this));
702 return true; 702 return true;
703 } 703 }
704 704
705 void FileBrowserPrivateSearchDriveFunction::OnSearch( 705 void FileManagerPrivateSearchDriveFunction::OnSearch(
706 drive::FileError error, 706 drive::FileError error,
707 const GURL& next_link, 707 const GURL& next_link,
708 scoped_ptr<SearchResultInfoList> results) { 708 scoped_ptr<SearchResultInfoList> results) {
709 if (error != drive::FILE_ERROR_OK) { 709 if (error != drive::FILE_ERROR_OK) {
710 SendResponse(false); 710 SendResponse(false);
711 return; 711 return;
712 } 712 }
713 713
714 // Outlives the following conversion, since the pointer is bound to the 714 // Outlives the following conversion, since the pointer is bound to the
715 // callback. 715 // callback.
716 DCHECK(results.get()); 716 DCHECK(results.get());
717 const SearchResultInfoList& results_ref = *results.get(); 717 const SearchResultInfoList& results_ref = *results.get();
718 718
719 ConvertSearchResultInfoListToEntryDefinitionList( 719 ConvertSearchResultInfoListToEntryDefinitionList(
720 GetProfile(), 720 GetProfile(),
721 extension_->id(), 721 extension_->id(),
722 results_ref, 722 results_ref,
723 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnEntryDefinitionList, 723 base::Bind(&FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList,
724 this, 724 this,
725 next_link, 725 next_link,
726 base::Passed(&results))); 726 base::Passed(&results)));
727 } 727 }
728 728
729 void FileBrowserPrivateSearchDriveFunction::OnEntryDefinitionList( 729 void FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList(
730 const GURL& next_link, 730 const GURL& next_link,
731 scoped_ptr<SearchResultInfoList> search_result_info_list, 731 scoped_ptr<SearchResultInfoList> search_result_info_list,
732 scoped_ptr<EntryDefinitionList> entry_definition_list) { 732 scoped_ptr<EntryDefinitionList> entry_definition_list) {
733 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); 733 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size());
734 base::ListValue* entries = new base::ListValue(); 734 base::ListValue* entries = new base::ListValue();
735 735
736 // Convert Drive files to something File API stack can understand. 736 // Convert Drive files to something File API stack can understand.
737 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin(); 737 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin();
738 it != entry_definition_list->end(); 738 it != entry_definition_list->end();
739 ++it) { 739 ++it) {
740 base::DictionaryValue* entry = new base::DictionaryValue(); 740 base::DictionaryValue* entry = new base::DictionaryValue();
741 entry->SetString("fileSystemName", it->file_system_name); 741 entry->SetString("fileSystemName", it->file_system_name);
742 entry->SetString("fileSystemRoot", it->file_system_root_url); 742 entry->SetString("fileSystemRoot", it->file_system_root_url);
743 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); 743 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe());
744 entry->SetBoolean("fileIsDirectory", it->is_directory); 744 entry->SetBoolean("fileIsDirectory", it->is_directory);
745 entries->Append(entry); 745 entries->Append(entry);
746 } 746 }
747 747
748 base::DictionaryValue* result = new base::DictionaryValue(); 748 base::DictionaryValue* result = new base::DictionaryValue();
749 result->Set("entries", entries); 749 result->Set("entries", entries);
750 result->SetString("nextFeed", next_link.spec()); 750 result->SetString("nextFeed", next_link.spec());
751 751
752 SetResult(result); 752 SetResult(result);
753 SendResponse(true); 753 SendResponse(true);
754 } 754 }
755 755
756 bool FileBrowserPrivateSearchDriveMetadataFunction::RunAsync() { 756 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() {
757 using api::file_browser_private::SearchDriveMetadata::Params; 757 using api::file_manager_private::SearchDriveMetadata::Params;
758 const scoped_ptr<Params> params(Params::Create(*args_)); 758 const scoped_ptr<Params> params(Params::Create(*args_));
759 EXTENSION_FUNCTION_VALIDATE(params); 759 EXTENSION_FUNCTION_VALIDATE(params);
760 760
761 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 761 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
762 if (logger) { 762 if (logger) {
763 logger->Log(logging::LOG_INFO, 763 logger->Log(logging::LOG_INFO,
764 "%s[%d] called. (types: '%s', maxResults: '%d')", 764 "%s[%d] called. (types: '%s', maxResults: '%d')",
765 name().c_str(), 765 name().c_str(),
766 request_id(), 766 request_id(),
767 api::file_browser_private::ToString( 767 api::file_manager_private::ToString(
768 params->search_params.types).c_str(), 768 params->search_params.types).c_str(),
769 params->search_params.max_results); 769 params->search_params.max_results);
770 } 770 }
771 set_log_on_completion(true); 771 set_log_on_completion(true);
772 772
773 drive::FileSystemInterface* const file_system = 773 drive::FileSystemInterface* const file_system =
774 drive::util::GetFileSystemByProfile(GetProfile()); 774 drive::util::GetFileSystemByProfile(GetProfile());
775 if (!file_system) { 775 if (!file_system) {
776 // |file_system| is NULL if Drive is disabled. 776 // |file_system| is NULL if Drive is disabled.
777 return false; 777 return false;
778 } 778 }
779 779
780 int options = -1; 780 int options = -1;
781 switch (params->search_params.types) { 781 switch (params->search_params.types) {
782 case api::file_browser_private::SEARCH_TYPE_EXCLUDE_DIRECTORIES: 782 case api::file_manager_private::SEARCH_TYPE_EXCLUDE_DIRECTORIES:
783 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; 783 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES;
784 break; 784 break;
785 case api::file_browser_private::SEARCH_TYPE_SHARED_WITH_ME: 785 case api::file_manager_private::SEARCH_TYPE_SHARED_WITH_ME:
786 options = drive::SEARCH_METADATA_SHARED_WITH_ME; 786 options = drive::SEARCH_METADATA_SHARED_WITH_ME;
787 break; 787 break;
788 case api::file_browser_private::SEARCH_TYPE_OFFLINE: 788 case api::file_manager_private::SEARCH_TYPE_OFFLINE:
789 options = drive::SEARCH_METADATA_OFFLINE; 789 options = drive::SEARCH_METADATA_OFFLINE;
790 break; 790 break;
791 case api::file_browser_private::SEARCH_TYPE_ALL: 791 case api::file_manager_private::SEARCH_TYPE_ALL:
792 options = drive::SEARCH_METADATA_ALL; 792 options = drive::SEARCH_METADATA_ALL;
793 break; 793 break;
794 case api::file_browser_private::SEARCH_TYPE_NONE: 794 case api::file_manager_private::SEARCH_TYPE_NONE:
795 break; 795 break;
796 } 796 }
797 DCHECK_NE(options, -1); 797 DCHECK_NE(options, -1);
798 798
799 file_system->SearchMetadata( 799 file_system->SearchMetadata(
800 params->search_params.query, 800 params->search_params.query,
801 options, 801 options,
802 params->search_params.max_results, 802 params->search_params.max_results,
803 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction:: 803 base::Bind(&FileManagerPrivateSearchDriveMetadataFunction::
804 OnSearchMetadata, this)); 804 OnSearchMetadata, this));
805 return true; 805 return true;
806 } 806 }
807 807
808 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( 808 void FileManagerPrivateSearchDriveMetadataFunction::OnSearchMetadata(
809 drive::FileError error, 809 drive::FileError error,
810 scoped_ptr<drive::MetadataSearchResultVector> results) { 810 scoped_ptr<drive::MetadataSearchResultVector> results) {
811 if (error != drive::FILE_ERROR_OK) { 811 if (error != drive::FILE_ERROR_OK) {
812 SendResponse(false); 812 SendResponse(false);
813 return; 813 return;
814 } 814 }
815 815
816 // Outlives the following conversion, since the pointer is bound to the 816 // Outlives the following conversion, since the pointer is bound to the
817 // callback. 817 // callback.
818 DCHECK(results.get()); 818 DCHECK(results.get());
819 const drive::MetadataSearchResultVector& results_ref = *results.get(); 819 const drive::MetadataSearchResultVector& results_ref = *results.get();
820 820
821 ConvertSearchResultInfoListToEntryDefinitionList( 821 ConvertSearchResultInfoListToEntryDefinitionList(
822 GetProfile(), 822 GetProfile(),
823 extension_->id(), 823 extension_->id(),
824 results_ref, 824 results_ref,
825 base::Bind( 825 base::Bind(
826 &FileBrowserPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, 826 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList,
827 this, 827 this,
828 base::Passed(&results))); 828 base::Passed(&results)));
829 } 829 }
830 830
831 void FileBrowserPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( 831 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList(
832 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list, 832 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
833 scoped_ptr<EntryDefinitionList> entry_definition_list) { 833 scoped_ptr<EntryDefinitionList> entry_definition_list) {
834 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); 834 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size());
835 base::ListValue* results_list = new base::ListValue(); 835 base::ListValue* results_list = new base::ListValue();
836 836
837 // Convert Drive files to something File API stack can understand. See 837 // Convert Drive files to something File API stack can understand. See
838 // file_browser_handler_custom_bindings.cc and 838 // file_browser_handler_custom_bindings.cc and
839 // file_browser_private_custom_bindings.js for how this is magically 839 // file_manager_private_custom_bindings.js for how this is magically
840 // converted to a FileEntry. 840 // converted to a FileEntry.
841 for (size_t i = 0; i < entry_definition_list->size(); ++i) { 841 for (size_t i = 0; i < entry_definition_list->size(); ++i) {
842 base::DictionaryValue* result_dict = new base::DictionaryValue(); 842 base::DictionaryValue* result_dict = new base::DictionaryValue();
843 843
844 // FileEntry fields. 844 // FileEntry fields.
845 base::DictionaryValue* entry = new base::DictionaryValue(); 845 base::DictionaryValue* entry = new base::DictionaryValue();
846 entry->SetString( 846 entry->SetString(
847 "fileSystemName", entry_definition_list->at(i).file_system_name); 847 "fileSystemName", entry_definition_list->at(i).file_system_name);
848 entry->SetString( 848 entry->SetString(
849 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url); 849 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url);
850 entry->SetString( 850 entry->SetString(
851 "fileFullPath", 851 "fileFullPath",
852 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe()); 852 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe());
853 entry->SetBoolean("fileIsDirectory", 853 entry->SetBoolean("fileIsDirectory",
854 entry_definition_list->at(i).is_directory); 854 entry_definition_list->at(i).is_directory);
855 855
856 result_dict->Set("entry", entry); 856 result_dict->Set("entry", entry);
857 result_dict->SetString( 857 result_dict->SetString(
858 "highlightedBaseName", 858 "highlightedBaseName",
859 search_result_info_list->at(i).highlighted_base_name); 859 search_result_info_list->at(i).highlighted_base_name);
860 results_list->Append(result_dict); 860 results_list->Append(result_dict);
861 } 861 }
862 862
863 SetResult(results_list); 863 SetResult(results_list);
864 SendResponse(true); 864 SendResponse(true);
865 } 865 }
866 866
867 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunSync() { 867 bool FileManagerPrivateGetDriveConnectionStateFunction::RunSync() {
868 api::file_browser_private::DriveConnectionState result; 868 api::file_manager_private::DriveConnectionState result;
869 869
870 switch (drive::util::GetDriveConnectionStatus(GetProfile())) { 870 switch (drive::util::GetDriveConnectionStatus(GetProfile())) {
871 case drive::util::DRIVE_DISCONNECTED_NOSERVICE: 871 case drive::util::DRIVE_DISCONNECTED_NOSERVICE:
872 result.type = kDriveConnectionTypeOffline; 872 result.type = kDriveConnectionTypeOffline;
873 result.reason.reset(new std::string(kDriveConnectionReasonNoService)); 873 result.reason.reset(new std::string(kDriveConnectionReasonNoService));
874 break; 874 break;
875 case drive::util::DRIVE_DISCONNECTED_NONETWORK: 875 case drive::util::DRIVE_DISCONNECTED_NONETWORK:
876 result.type = kDriveConnectionTypeOffline; 876 result.type = kDriveConnectionTypeOffline;
877 result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork)); 877 result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork));
878 break; 878 break;
879 case drive::util::DRIVE_DISCONNECTED_NOTREADY: 879 case drive::util::DRIVE_DISCONNECTED_NOTREADY:
880 result.type = kDriveConnectionTypeOffline; 880 result.type = kDriveConnectionTypeOffline;
881 result.reason.reset(new std::string(kDriveConnectionReasonNotReady)); 881 result.reason.reset(new std::string(kDriveConnectionReasonNotReady));
882 break; 882 break;
883 case drive::util::DRIVE_CONNECTED_METERED: 883 case drive::util::DRIVE_CONNECTED_METERED:
884 result.type = kDriveConnectionTypeMetered; 884 result.type = kDriveConnectionTypeMetered;
885 break; 885 break;
886 case drive::util::DRIVE_CONNECTED: 886 case drive::util::DRIVE_CONNECTED:
887 result.type = kDriveConnectionTypeOnline; 887 result.type = kDriveConnectionTypeOnline;
888 break; 888 break;
889 } 889 }
890 890
891 results_ = api::file_browser_private::GetDriveConnectionState::Results:: 891 results_ = api::file_manager_private::GetDriveConnectionState::Results::
892 Create(result); 892 Create(result);
893 893
894 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 894 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
895 if (logger) 895 if (logger)
896 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); 896 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str());
897 return true; 897 return true;
898 } 898 }
899 899
900 bool FileBrowserPrivateRequestAccessTokenFunction::RunAsync() { 900 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() {
901 using extensions::api::file_browser_private::RequestAccessToken::Params; 901 using extensions::api::file_manager_private::RequestAccessToken::Params;
902 const scoped_ptr<Params> params(Params::Create(*args_)); 902 const scoped_ptr<Params> params(Params::Create(*args_));
903 EXTENSION_FUNCTION_VALIDATE(params); 903 EXTENSION_FUNCTION_VALIDATE(params);
904 904
905 drive::DriveServiceInterface* const drive_service = 905 drive::DriveServiceInterface* const drive_service =
906 drive::util::GetDriveServiceByProfile(GetProfile()); 906 drive::util::GetDriveServiceByProfile(GetProfile());
907 907
908 if (!drive_service) { 908 if (!drive_service) {
909 // DriveService is not available. 909 // DriveService is not available.
910 SetResult(new base::StringValue("")); 910 SetResult(new base::StringValue(""));
911 SendResponse(true); 911 SendResponse(true);
912 return true; 912 return true;
913 } 913 }
914 914
915 // If refreshing is requested, then clear the token to refetch it. 915 // If refreshing is requested, then clear the token to refetch it.
916 if (params->refresh) 916 if (params->refresh)
917 drive_service->ClearAccessToken(); 917 drive_service->ClearAccessToken();
918 918
919 // Retrieve the cached auth token (if available), otherwise the AuthService 919 // Retrieve the cached auth token (if available), otherwise the AuthService
920 // instance will try to refetch it. 920 // instance will try to refetch it.
921 drive_service->RequestAccessToken( 921 drive_service->RequestAccessToken(
922 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction:: 922 base::Bind(&FileManagerPrivateRequestAccessTokenFunction::
923 OnAccessTokenFetched, this)); 923 OnAccessTokenFetched, this));
924 return true; 924 return true;
925 } 925 }
926 926
927 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched( 927 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched(
928 google_apis::GDataErrorCode code, 928 google_apis::GDataErrorCode code,
929 const std::string& access_token) { 929 const std::string& access_token) {
930 SetResult(new base::StringValue(access_token)); 930 SetResult(new base::StringValue(access_token));
931 SendResponse(true); 931 SendResponse(true);
932 } 932 }
933 933
934 bool FileBrowserPrivateGetShareUrlFunction::RunAsync() { 934 bool FileManagerPrivateGetShareUrlFunction::RunAsync() {
935 using extensions::api::file_browser_private::GetShareUrl::Params; 935 using extensions::api::file_manager_private::GetShareUrl::Params;
936 const scoped_ptr<Params> params(Params::Create(*args_)); 936 const scoped_ptr<Params> params(Params::Create(*args_));
937 EXTENSION_FUNCTION_VALIDATE(params); 937 EXTENSION_FUNCTION_VALIDATE(params);
938 938
939 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 939 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
940 render_view_host(), GetProfile(), GURL(params->url)); 940 render_view_host(), GetProfile(), GURL(params->url));
941 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 941 DCHECK(drive::util::IsUnderDriveMountPoint(path));
942 942
943 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); 943 const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
944 944
945 drive::FileSystemInterface* const file_system = 945 drive::FileSystemInterface* const file_system =
946 drive::util::GetFileSystemByProfile(GetProfile()); 946 drive::util::GetFileSystemByProfile(GetProfile());
947 if (!file_system) { 947 if (!file_system) {
948 // |file_system| is NULL if Drive is disabled. 948 // |file_system| is NULL if Drive is disabled.
949 return false; 949 return false;
950 } 950 }
951 951
952 file_system->GetShareUrl( 952 file_system->GetShareUrl(
953 drive_path, 953 drive_path,
954 GURL("chrome-extension://" + extension_id()), // embed origin 954 GURL("chrome-extension://" + extension_id()), // embed origin
955 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this)); 955 base::Bind(&FileManagerPrivateGetShareUrlFunction::OnGetShareUrl, this));
956 return true; 956 return true;
957 } 957 }
958 958
959 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl( 959 void FileManagerPrivateGetShareUrlFunction::OnGetShareUrl(
960 drive::FileError error, 960 drive::FileError error,
961 const GURL& share_url) { 961 const GURL& share_url) {
962 if (error != drive::FILE_ERROR_OK) { 962 if (error != drive::FILE_ERROR_OK) {
963 SetError("Share Url for this item is not available."); 963 SetError("Share Url for this item is not available.");
964 SendResponse(false); 964 SendResponse(false);
965 return; 965 return;
966 } 966 }
967 967
968 SetResult(new base::StringValue(share_url.spec())); 968 SetResult(new base::StringValue(share_url.spec()));
969 SendResponse(true); 969 SendResponse(true);
970 } 970 }
971 971
972 bool FileBrowserPrivateRequestDriveShareFunction::RunAsync() { 972 bool FileManagerPrivateRequestDriveShareFunction::RunAsync() {
973 using extensions::api::file_browser_private::RequestDriveShare::Params; 973 using extensions::api::file_manager_private::RequestDriveShare::Params;
974 const scoped_ptr<Params> params(Params::Create(*args_)); 974 const scoped_ptr<Params> params(Params::Create(*args_));
975 EXTENSION_FUNCTION_VALIDATE(params); 975 EXTENSION_FUNCTION_VALIDATE(params);
976 976
977 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 977 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
978 render_view_host(), GetProfile(), GURL(params->url)); 978 render_view_host(), GetProfile(), GURL(params->url));
979 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); 979 const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
980 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path); 980 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path);
981 981
982 if (!owner_profile) 982 if (!owner_profile)
983 return false; 983 return false;
984 984
985 drive::FileSystemInterface* const owner_file_system = 985 drive::FileSystemInterface* const owner_file_system =
986 drive::util::GetFileSystemByProfile(owner_profile); 986 drive::util::GetFileSystemByProfile(owner_profile);
987 if (!owner_file_system) 987 if (!owner_file_system)
988 return false; 988 return false;
989 989
990 const user_manager::User* const user = 990 const user_manager::User* const user =
991 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); 991 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile());
992 if (!user || !user->is_logged_in()) 992 if (!user || !user->is_logged_in())
993 return false; 993 return false;
994 994
995 google_apis::drive::PermissionRole role = 995 google_apis::drive::PermissionRole role =
996 google_apis::drive::PERMISSION_ROLE_READER; 996 google_apis::drive::PERMISSION_ROLE_READER;
997 switch (params->share_type) { 997 switch (params->share_type) {
998 case api::file_browser_private::DRIVE_SHARE_TYPE_NONE: 998 case api::file_manager_private::DRIVE_SHARE_TYPE_NONE:
999 NOTREACHED(); 999 NOTREACHED();
1000 return false; 1000 return false;
1001 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_EDIT: 1001 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_EDIT:
1002 role = google_apis::drive::PERMISSION_ROLE_WRITER; 1002 role = google_apis::drive::PERMISSION_ROLE_WRITER;
1003 break; 1003 break;
1004 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_COMMENT: 1004 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_COMMENT:
1005 role = google_apis::drive::PERMISSION_ROLE_COMMENTER; 1005 role = google_apis::drive::PERMISSION_ROLE_COMMENTER;
1006 break; 1006 break;
1007 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_VIEW: 1007 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_VIEW:
1008 role = google_apis::drive::PERMISSION_ROLE_READER; 1008 role = google_apis::drive::PERMISSION_ROLE_READER;
1009 break; 1009 break;
1010 } 1010 }
1011 1011
1012 // Share |drive_path| in |owner_file_system| to |user->email()|. 1012 // Share |drive_path| in |owner_file_system| to |user->email()|.
1013 owner_file_system->AddPermission( 1013 owner_file_system->AddPermission(
1014 drive_path, 1014 drive_path,
1015 user->email(), 1015 user->email(),
1016 role, 1016 role,
1017 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission, 1017 base::Bind(&FileManagerPrivateRequestDriveShareFunction::OnAddPermission,
1018 this)); 1018 this));
1019 return true; 1019 return true;
1020 } 1020 }
1021 1021
1022 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( 1022 void FileManagerPrivateRequestDriveShareFunction::OnAddPermission(
1023 drive::FileError error) { 1023 drive::FileError error) {
1024 SendResponse(error == drive::FILE_ERROR_OK); 1024 SendResponse(error == drive::FILE_ERROR_OK);
1025 } 1025 }
1026 1026
1027 FileBrowserPrivateGetDownloadUrlFunction:: 1027 FileManagerPrivateGetDownloadUrlFunction::
1028 FileBrowserPrivateGetDownloadUrlFunction() { 1028 FileManagerPrivateGetDownloadUrlFunction() {
1029 } 1029 }
1030 1030
1031 FileBrowserPrivateGetDownloadUrlFunction:: 1031 FileManagerPrivateGetDownloadUrlFunction::
1032 ~FileBrowserPrivateGetDownloadUrlFunction() { 1032 ~FileManagerPrivateGetDownloadUrlFunction() {
1033 } 1033 }
1034 1034
1035 bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() { 1035 bool FileManagerPrivateGetDownloadUrlFunction::RunAsync() {
1036 using extensions::api::file_browser_private::GetShareUrl::Params; 1036 using extensions::api::file_manager_private::GetShareUrl::Params;
1037 const scoped_ptr<Params> params(Params::Create(*args_)); 1037 const scoped_ptr<Params> params(Params::Create(*args_));
1038 EXTENSION_FUNCTION_VALIDATE(params); 1038 EXTENSION_FUNCTION_VALIDATE(params);
1039 1039
1040 // Start getting the file info. 1040 // Start getting the file info.
1041 drive::FileSystemInterface* const file_system = 1041 drive::FileSystemInterface* const file_system =
1042 drive::util::GetFileSystemByProfile(GetProfile()); 1042 drive::util::GetFileSystemByProfile(GetProfile());
1043 if (!file_system) { 1043 if (!file_system) {
1044 // |file_system| is NULL if Drive is disabled or not mounted. 1044 // |file_system| is NULL if Drive is disabled or not mounted.
1045 SetError("Drive is disabled or not mounted."); 1045 SetError("Drive is disabled or not mounted.");
1046 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1046 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1047 return false; 1047 return false;
1048 } 1048 }
1049 1049
1050 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 1050 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
1051 render_view_host(), GetProfile(), GURL(params->url)); 1051 render_view_host(), GetProfile(), GURL(params->url));
1052 if (!drive::util::IsUnderDriveMountPoint(path)) { 1052 if (!drive::util::IsUnderDriveMountPoint(path)) {
1053 SetError("The given file is not in Drive."); 1053 SetError("The given file is not in Drive.");
1054 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1054 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1055 return false; 1055 return false;
1056 } 1056 }
1057 base::FilePath file_path = drive::util::ExtractDrivePath(path); 1057 base::FilePath file_path = drive::util::ExtractDrivePath(path);
1058 1058
1059 file_system->GetResourceEntry( 1059 file_system->GetResourceEntry(
1060 file_path, 1060 file_path,
1061 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry, 1061 base::Bind(&FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry,
1062 this)); 1062 this));
1063 return true; 1063 return true;
1064 } 1064 }
1065 1065
1066 void FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry( 1066 void FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry(
1067 drive::FileError error, 1067 drive::FileError error,
1068 scoped_ptr<drive::ResourceEntry> entry) { 1068 scoped_ptr<drive::ResourceEntry> entry) {
1069 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1069 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1070 1070
1071 if (error != drive::FILE_ERROR_OK) { 1071 if (error != drive::FILE_ERROR_OK) {
1072 SetError("Download Url for this item is not available."); 1072 SetError("Download Url for this item is not available.");
1073 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1073 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1074 SendResponse(false); 1074 SendResponse(false);
1075 return; 1075 return;
1076 } 1076 }
1077 1077
1078 download_url_ = 1078 download_url_ =
1079 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction + 1079 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction +
1080 entry->resource_id(); 1080 entry->resource_id();
1081 1081
1082 ProfileOAuth2TokenService* oauth2_token_service = 1082 ProfileOAuth2TokenService* oauth2_token_service =
1083 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); 1083 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
1084 SigninManagerBase* signin_manager = 1084 SigninManagerBase* signin_manager =
1085 SigninManagerFactory::GetForProfile(GetProfile()); 1085 SigninManagerFactory::GetForProfile(GetProfile());
1086 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); 1086 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
1087 std::vector<std::string> scopes; 1087 std::vector<std::string> scopes;
1088 scopes.push_back("https://www.googleapis.com/auth/drive.readonly"); 1088 scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
1089 1089
1090 auth_service_.reset( 1090 auth_service_.reset(
1091 new google_apis::AuthService(oauth2_token_service, 1091 new google_apis::AuthService(oauth2_token_service,
1092 account_id, 1092 account_id,
1093 GetProfile()->GetRequestContext(), 1093 GetProfile()->GetRequestContext(),
1094 scopes)); 1094 scopes));
1095 auth_service_->StartAuthentication(base::Bind( 1095 auth_service_->StartAuthentication(base::Bind(
1096 &FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, this)); 1096 &FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched, this));
1097 } 1097 }
1098 1098
1099 void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched( 1099 void FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched(
1100 google_apis::GDataErrorCode code, 1100 google_apis::GDataErrorCode code,
1101 const std::string& access_token) { 1101 const std::string& access_token) {
1102 if (code != google_apis::HTTP_SUCCESS) { 1102 if (code != google_apis::HTTP_SUCCESS) {
1103 SetError("Not able to fetch the token."); 1103 SetError("Not able to fetch the token.");
1104 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1104 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1105 SendResponse(false); 1105 SendResponse(false);
1106 return; 1106 return;
1107 } 1107 }
1108 1108
1109 const std::string url = download_url_ + "?access_token=" + access_token; 1109 const std::string url = download_url_ + "?access_token=" + access_token;
1110 SetResult(new base::StringValue(url)); 1110 SetResult(new base::StringValue(url));
1111 1111
1112 SendResponse(true); 1112 SendResponse(true);
1113 } 1113 }
1114 1114
1115 } // namespace extensions 1115 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698