| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_handler_util.h" | 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 &FileTaskExecutor::ExecuteFailedOnUIThread, | 352 &FileTaskExecutor::ExecuteFailedOnUIThread, |
| 353 executor_)); | 353 executor_)); |
| 354 return; | 354 return; |
| 355 } | 355 } |
| 356 | 356 |
| 357 BrowserThread::PostTask( | 357 BrowserThread::PostTask( |
| 358 BrowserThread::UI, FROM_HERE, | 358 BrowserThread::UI, FROM_HERE, |
| 359 base::Bind( | 359 base::Bind( |
| 360 &FileTaskExecutor::ExecuteFileActionsOnUIThread, | 360 &FileTaskExecutor::ExecuteFileActionsOnUIThread, |
| 361 executor_, | 361 executor_, |
| 362 file_system_name, | |
| 363 file_system_root, | |
| 364 file_list, | 362 file_list, |
| 365 handler_pid_)); | 363 base::Bind( |
| 364 &FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, |
| 365 executor_, |
| 366 file_system_name, |
| 367 file_system_root, |
| 368 file_list, |
| 369 handler_pid_))); |
| 366 } | 370 } |
| 367 | 371 |
| 368 void DidFail(base::PlatformFileError error_code) { | 372 void DidFail(base::PlatformFileError error_code) { |
| 369 BrowserThread::PostTask( | 373 BrowserThread::PostTask( |
| 370 BrowserThread::UI, FROM_HERE, | 374 BrowserThread::UI, FROM_HERE, |
| 371 base::Bind( | 375 base::Bind( |
| 372 &FileTaskExecutor::ExecuteFailedOnUIThread, | 376 &FileTaskExecutor::ExecuteFailedOnUIThread, |
| 373 executor_)); | 377 executor_)); |
| 374 } | 378 } |
| 375 | 379 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 handler_pid, | 545 handler_pid, |
| 542 action_id_, | 546 action_id_, |
| 543 file_urls)); | 547 file_urls)); |
| 544 } | 548 } |
| 545 | 549 |
| 546 void FileTaskExecutor::ExecuteFailedOnUIThread() { | 550 void FileTaskExecutor::ExecuteFailedOnUIThread() { |
| 547 Done(false); | 551 Done(false); |
| 548 } | 552 } |
| 549 | 553 |
| 550 void FileTaskExecutor::ExecuteFileActionsOnUIThread( | 554 void FileTaskExecutor::ExecuteFileActionsOnUIThread( |
| 555 const FileDefinitionList& file_list, |
| 556 const base::Closure& callback) { |
| 557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 558 |
| 559 ExtensionService* service = profile_->GetExtensionService(); |
| 560 if (!service) { |
| 561 Done(false); |
| 562 return; |
| 563 } |
| 564 |
| 565 const Extension* extension = service->GetExtensionById(extension_id_, false); |
| 566 if (!extension) { |
| 567 Done(false); |
| 568 return; |
| 569 } |
| 570 |
| 571 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_, |
| 572 callback); |
| 573 } |
| 574 |
| 575 void FileTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( |
| 551 const std::string& file_system_name, | 576 const std::string& file_system_name, |
| 552 const GURL& file_system_root, | 577 const GURL& file_system_root, |
| 553 const FileDefinitionList& file_list, | 578 const FileDefinitionList& file_list, |
| 554 int handler_pid) { | 579 int handler_pid) { |
| 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 556 | 581 |
| 557 ExtensionService* service = profile_->GetExtensionService(); | 582 ExtensionService* service = profile_->GetExtensionService(); |
| 558 if (!service) { | 583 if (!service) { |
| 559 Done(false); | 584 Done(false); |
| 560 return; | 585 return; |
| 561 } | 586 } |
| 562 | 587 |
| 563 const Extension* extension = service->GetExtensionById(extension_id_, false); | 588 const Extension* extension = service->GetExtensionById(extension_id_, false); |
| 564 if (!extension) { | 589 if (!extension) { |
| 565 Done(false); | 590 Done(false); |
| 566 return; | 591 return; |
| 567 } | 592 } |
| 568 | 593 |
| 569 InitHandlerHostFileAccessPermissions(file_list, extension, action_id_); | |
| 570 | |
| 571 if (handler_pid > 0) { | 594 if (handler_pid > 0) { |
| 572 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, | 595 SetupPermissionsAndDispatchEvent(file_system_name, file_system_root, |
| 573 file_list, handler_pid, NULL); | 596 file_list, handler_pid, NULL); |
| 574 } else { | 597 } else { |
| 575 // We have to wake the handler background page before we proceed. | 598 // We have to wake the handler background page before we proceed. |
| 576 extensions::LazyBackgroundTaskQueue* queue = | 599 extensions::LazyBackgroundTaskQueue* queue = |
| 577 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | 600 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); |
| 578 if (!queue->ShouldEnqueueTask(profile_, extension)) { | 601 if (!queue->ShouldEnqueueTask(profile_, extension)) { |
| 579 Done(false); | 602 Done(false); |
| 580 return; | 603 return; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 extension_id_, std::string("fileBrowserHandler.onExecute"), | 665 extension_id_, std::string("fileBrowserHandler.onExecute"), |
| 643 json_args, profile_, | 666 json_args, profile_, |
| 644 GURL()); | 667 GURL()); |
| 645 | 668 |
| 646 Done(true); | 669 Done(true); |
| 647 } | 670 } |
| 648 | 671 |
| 649 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( | 672 void FileTaskExecutor::InitHandlerHostFileAccessPermissions( |
| 650 const FileDefinitionList& file_list, | 673 const FileDefinitionList& file_list, |
| 651 const Extension* handler_extension, | 674 const Extension* handler_extension, |
| 652 const std::string& action_id) { | 675 const std::string& action_id, |
| 676 const base::Closure& callback) { |
| 653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 654 | 678 |
| 679 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); |
| 655 for (FileDefinitionList::const_iterator iter = file_list.begin(); | 680 for (FileDefinitionList::const_iterator iter = file_list.begin(); |
| 656 iter != file_list.end(); | 681 iter != file_list.end(); |
| 657 ++iter) { | 682 ++iter) { |
| 658 // Setup permission for file's absolute file. | 683 // Setup permission for file's absolute file. |
| 659 handler_host_permissions_.push_back(std::make_pair( | 684 handler_host_permissions_.push_back(std::make_pair( |
| 660 iter->absolute_path, | 685 iter->absolute_path, |
| 661 GetAccessPermissionsForHandler(handler_extension, action_id))); | 686 GetAccessPermissionsForHandler(handler_extension, action_id))); |
| 662 | 687 |
| 663 if (!gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) | 688 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) |
| 664 continue; | 689 gdata_paths->push_back(iter->virtual_path); |
| 690 } |
| 665 | 691 |
| 666 // If the file is on gdata mount point, we'll have to give handler host | 692 if (gdata_paths->empty()) { |
| 667 // permissions for file's gdata cache paths. | 693 // Invoke callback if none of the files are on gdata mount point. |
| 668 // This has to be called on UI thread. | 694 callback.Run(); |
| 669 gdata::util::InsertGDataCachePathsPermissions(profile_, iter->virtual_path, | 695 return; |
| 670 &handler_host_permissions_); | |
| 671 } | 696 } |
| 697 |
| 698 // For files on gdata mount point, we'll have to give handler host permissions |
| 699 // for their cache paths. This has to be called on UI thread. |
| 700 gdata::util::InsertGDataCachePathsPermissions(profile_, |
| 701 gdata_paths.Pass(), |
| 702 &handler_host_permissions_, |
| 703 callback); |
| 672 } | 704 } |
| 673 | 705 |
| 674 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { | 706 void FileTaskExecutor::SetupHandlerHostFileAccessPermissions(int handler_pid) { |
| 675 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { | 707 for (size_t i = 0; i < handler_host_permissions_.size(); i++) { |
| 676 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( | 708 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
| 677 handler_pid, | 709 handler_pid, |
| 678 handler_host_permissions_[i].first, | 710 handler_host_permissions_[i].first, |
| 679 handler_host_permissions_[i].second); | 711 handler_host_permissions_[i].second); |
| 680 } | 712 } |
| 681 | 713 |
| 682 // We don't need this anymore. | 714 // We don't need this anymore. |
| 683 handler_host_permissions_.clear(); | 715 handler_host_permissions_.clear(); |
| 684 } | 716 } |
| 685 | 717 |
| 686 } // namespace file_handler_util | 718 } // namespace file_handler_util |
| 687 | 719 |
| OLD | NEW |