| 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_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <utime.h> | 10 #include <utime.h> |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 RequestLocalFileSystemFunction* function_; | 558 RequestLocalFileSystemFunction* function_; |
| 559 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 559 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
| 560 // Renderer process id. | 560 // Renderer process id. |
| 561 int child_id_; | 561 int child_id_; |
| 562 // Extension source URL. | 562 // Extension source URL. |
| 563 scoped_refptr<const Extension> extension_; | 563 scoped_refptr<const Extension> extension_; |
| 564 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); | 564 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher); |
| 565 }; | 565 }; |
| 566 | 566 |
| 567 FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile) | 567 FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile) |
| 568 : event_router_(make_scoped_refptr(new FileBrowserEventRouter(profile))) { | 568 : event_router_(new FileBrowserEventRouter(profile)) { |
| 569 (new FileBrowserHandlerParser)->Register(); | 569 (new FileBrowserHandlerParser)->Register(); |
| 570 | 570 |
| 571 ExtensionFunctionRegistry* registry = | 571 ExtensionFunctionRegistry* registry = |
| 572 ExtensionFunctionRegistry::GetInstance(); | 572 ExtensionFunctionRegistry::GetInstance(); |
| 573 registry->RegisterFunction<LogoutUserFunction>(); | 573 registry->RegisterFunction<LogoutUserFunction>(); |
| 574 registry->RegisterFunction<CancelFileDialogFunction>(); | 574 registry->RegisterFunction<CancelFileDialogFunction>(); |
| 575 registry->RegisterFunction<ExecuteTasksFileBrowserFunction>(); | 575 registry->RegisterFunction<ExecuteTasksFileBrowserFunction>(); |
| 576 registry->RegisterFunction<SetDefaultTaskFileBrowserFunction>(); | 576 registry->RegisterFunction<SetDefaultTaskFileBrowserFunction>(); |
| 577 registry->RegisterFunction<FileDialogStringsFunction>(); | 577 registry->RegisterFunction<FileDialogStringsFunction>(); |
| 578 registry->RegisterFunction<GetFileTasksFileBrowserFunction>(); | 578 registry->RegisterFunction<GetFileTasksFileBrowserFunction>(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 SendResponse(true); | 680 SendResponse(true); |
| 681 } | 681 } |
| 682 | 682 |
| 683 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( | 683 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( |
| 684 base::PlatformFileError error_code) { | 684 base::PlatformFileError error_code) { |
| 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 686 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); | 686 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); |
| 687 SendResponse(false); | 687 SendResponse(false); |
| 688 } | 688 } |
| 689 | 689 |
| 690 void FileWatchBrowserFunctionBase::RespondOnUIThread(bool success) { | 690 void FileWatchBrowserFunctionBase::Respond(bool success) { |
| 691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 692 |
| 691 SetResult(Value::CreateBooleanValue(success)); | 693 SetResult(Value::CreateBooleanValue(success)); |
| 692 SendResponse(success); | 694 SendResponse(success); |
| 693 } | 695 } |
| 694 | 696 |
| 695 bool FileWatchBrowserFunctionBase::RunImpl() { | 697 bool FileWatchBrowserFunctionBase::RunImpl() { |
| 698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 699 |
| 696 if (!render_view_host() || !render_view_host()->GetProcess()) | 700 if (!render_view_host() || !render_view_host()->GetProcess()) |
| 697 return false; | 701 return false; |
| 698 | 702 |
| 699 // First param is url of a file to watch. | 703 // First param is url of a file to watch. |
| 700 std::string url; | 704 std::string url; |
| 701 if (!args_->GetString(0, &url) || url.empty()) | 705 if (!args_->GetString(0, &url) || url.empty()) |
| 702 return false; | 706 return false; |
| 703 | 707 |
| 704 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); | 708 content::SiteInstance* site_instance = render_view_host()->GetSiteInstance(); |
| 705 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 709 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 706 BrowserContext::GetStoragePartition(profile(), site_instance)-> | 710 BrowserContext::GetStoragePartition(profile(), site_instance)-> |
| 707 GetFileSystemContext(); | 711 GetFileSystemContext(); |
| 708 | 712 |
| 709 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); | 713 FileSystemURL file_watch_url = file_system_context->CrackURL(GURL(url)); |
| 710 BrowserThread::PostTask( | 714 base::FilePath local_path = file_watch_url.path(); |
| 711 BrowserThread::FILE, FROM_HERE, | 715 base::FilePath virtual_path = file_watch_url.virtual_path(); |
| 712 base::Bind( | 716 if (local_path.empty()) { |
| 713 &FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread, | 717 Respond(false); |
| 714 this, | 718 return true; |
| 715 FileBrowserPrivateAPI::Get(profile_)->event_router(), | 719 } |
| 716 file_watch_url, | 720 PerformFileWatchOperation(local_path, virtual_path, extension_id()); |
| 717 extension_id())); | |
| 718 | 721 |
| 719 return true; | 722 return true; |
| 720 } | 723 } |
| 721 | 724 |
| 722 void FileWatchBrowserFunctionBase::RunFileWatchOperationOnFileThread( | 725 void AddFileWatchBrowserFunction::PerformFileWatchOperation( |
| 723 scoped_refptr<FileBrowserEventRouter> event_router, | 726 const base::FilePath& local_path, |
| 724 const FileSystemURL& file_url, const std::string& extension_id) { | 727 const base::FilePath& virtual_path, |
| 725 base::FilePath local_path = file_url.path(); | 728 const std::string& extension_id) { |
| 726 base::FilePath virtual_path = file_url.virtual_path(); | 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 727 bool result = !local_path.empty() && PerformFileWatchOperation( | |
| 728 event_router, local_path, virtual_path, extension_id); | |
| 729 | 730 |
| 730 BrowserThread::PostTask( | 731 FileBrowserEventRouter* event_router = |
| 731 BrowserThread::UI, FROM_HERE, | 732 FileBrowserPrivateAPI::Get(profile_)->event_router(); |
| 732 base::Bind( | 733 event_router->AddFileWatch( |
| 733 &FileWatchBrowserFunctionBase::RespondOnUIThread, this, result)); | 734 local_path, |
| 735 virtual_path, |
| 736 extension_id, |
| 737 base::Bind(&AddFileWatchBrowserFunction::Respond, this)); |
| 734 } | 738 } |
| 735 | 739 |
| 736 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 740 void RemoveFileWatchBrowserFunction::PerformFileWatchOperation( |
| 737 scoped_refptr<FileBrowserEventRouter> event_router, | 741 const base::FilePath& local_path, |
| 738 const base::FilePath& local_path, const base::FilePath& virtual_path, | 742 const base::FilePath& unused, |
| 739 const std::string& extension_id) { | 743 const std::string& extension_id) { |
| 740 return event_router->AddFileWatch(local_path, virtual_path, extension_id); | 744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 741 } | |
| 742 | 745 |
| 743 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( | 746 FileBrowserEventRouter* event_router = |
| 744 scoped_refptr<FileBrowserEventRouter> event_router, | 747 FileBrowserPrivateAPI::Get(profile_)->event_router(); |
| 745 const base::FilePath& local_path, const base::FilePath& unused, | |
| 746 const std::string& extension_id) { | |
| 747 event_router->RemoveFileWatch(local_path, extension_id); | 748 event_router->RemoveFileWatch(local_path, extension_id); |
| 748 return true; | 749 Respond(true); |
| 749 } | 750 } |
| 750 | 751 |
| 751 // static | 752 // static |
| 752 void GetFileTasksFileBrowserFunction::IntersectAvailableDriveTasks( | 753 void GetFileTasksFileBrowserFunction::IntersectAvailableDriveTasks( |
| 753 drive::DriveWebAppsRegistry* registry, | 754 drive::DriveWebAppsRegistry* registry, |
| 754 const FileInfoList& file_info_list, | 755 const FileInfoList& file_info_list, |
| 755 WebAppInfoMap* app_info, | 756 WebAppInfoMap* app_info, |
| 756 std::set<std::string>* available_tasks) { | 757 std::set<std::string>* available_tasks) { |
| 757 for (FileInfoList::const_iterator file_iter = file_info_list.begin(); | 758 for (FileInfoList::const_iterator file_iter = file_info_list.begin(); |
| 758 file_iter != file_info_list.end(); ++file_iter) { | 759 file_iter != file_info_list.end(); ++file_iter) { |
| (...skipping 2556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3315 OpenNewWindowFunction::OpenNewWindowFunction() {} | 3316 OpenNewWindowFunction::OpenNewWindowFunction() {} |
| 3316 | 3317 |
| 3317 OpenNewWindowFunction::~OpenNewWindowFunction() {} | 3318 OpenNewWindowFunction::~OpenNewWindowFunction() {} |
| 3318 | 3319 |
| 3319 bool OpenNewWindowFunction::RunImpl() { | 3320 bool OpenNewWindowFunction::RunImpl() { |
| 3320 std::string url; | 3321 std::string url; |
| 3321 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); | 3322 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url)); |
| 3322 file_manager_util::OpenNewWindow(profile_, GURL(url)); | 3323 file_manager_util::OpenNewWindow(profile_, GURL(url)); |
| 3323 return true; | 3324 return true; |
| 3324 } | 3325 } |
| OLD | NEW |