Chromium Code Reviews| Index: chrome/browser/extensions/api/file_system/file_system_api.cc |
| diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc |
| index a2b27a3cd126549ffdb5aaef5041d6d6ee9ab395..0cdb0e6ef8689d23ee1efa3b84238807a5fa9d71 100644 |
| --- a/chrome/browser/extensions/api/file_system/file_system_api.cc |
| +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/extension_util.h" |
| #include "chrome/browser/extensions/path_util.h" |
| #include "chrome/browser/platform_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -32,6 +33,7 @@ |
| #include "content/public/browser/child_process_security_policy.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/storage_partition.h" |
| #include "content/public/browser/web_contents.h" |
| #include "extensions/browser/app_window/app_window.h" |
| #include "extensions/browser/app_window/app_window_registry.h" |
| @@ -42,6 +44,7 @@ |
| #include "extensions/common/permissions/permissions_data.h" |
| #include "net/base/mime_util.h" |
| #include "storage/browser/fileapi/external_mount_points.h" |
| +#include "storage/browser/fileapi/file_system_operation_runner.h" |
| #include "storage/browser/fileapi/isolated_context.h" |
| #include "storage/common/fileapi/file_system_types.h" |
| #include "storage/common/fileapi/file_system_util.h" |
| @@ -868,14 +871,33 @@ bool FileSystemRetainEntryFunction::RunAsync() { |
| return false; |
| } |
| - content::BrowserThread::PostTaskAndReply( |
| - content::BrowserThread::FILE, |
| + std::string filesystem_id; |
| + if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) |
| + return false; |
| + |
| + const GURL site = |
| + extensions::util::GetSiteForExtensionId(extension_id(), GetProfile()); |
| + storage::FileSystemContext* const context = |
| + content::BrowserContext::GetStoragePartitionForSite(GetProfile(), site) |
| + ->GetFileSystemContext(); |
| + const storage::FileSystemURL url = context->CreateCrackedFileSystemURL( |
| + site, |
| + storage::kFileSystemTypeIsolated, |
| + IsolatedContext::GetInstance() |
| + ->CreateVirtualRootPath(filesystem_id) |
| + .Append(filesystem_path)); |
| + |
| + content::BrowserThread::PostTask( |
| + content::BrowserThread::IO, |
| FROM_HERE, |
| - base::Bind(&FileSystemRetainEntryFunction::SetIsDirectoryOnFileThread, |
| - this), |
| - base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry, |
| - this, |
| - entry_id)); |
| + base::Bind( |
| + base::IgnoreResult( |
| + &storage::FileSystemOperationRunner::GetMetadata), |
| + context->operation_runner()->AsWeakPtr(), |
| + url, |
| + base::Bind(&FileSystemRetainEntryFunction::SetIsDirectoryOnIOThread, |
| + this, |
| + entry_id))); |
| return true; |
| } |
| @@ -886,6 +908,11 @@ bool FileSystemRetainEntryFunction::RunAsync() { |
| void FileSystemRetainEntryFunction::RetainFileEntry( |
| const std::string& entry_id) { |
| + if (entry_id.empty()) { |
| + SendResponse(false); |
| + return; |
| + } |
| + |
| SavedFilesService* saved_files_service = SavedFilesService::Get(GetProfile()); |
| saved_files_service->RegisterFileEntry( |
| extension_->id(), entry_id, path_, is_directory_); |
| @@ -893,8 +920,21 @@ void FileSystemRetainEntryFunction::RetainFileEntry( |
| SendResponse(true); |
| } |
| -void FileSystemRetainEntryFunction::SetIsDirectoryOnFileThread() { |
| - is_directory_ = base::DirectoryExists(path_); |
| +void FileSystemRetainEntryFunction::SetIsDirectoryOnIOThread( |
|
mtomasz
2014/10/14 06:08:49
Calling SetIsDirectoryOnIOThread should only set "
hirono
2014/10/14 09:22:10
I removed the method and aggregated the procedures
|
| + const std::string& entry_id, |
| + base::File::Error result, |
| + const base::File::Info& file_info) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| + |
| + if (result == base::File::FILE_OK) |
| + is_directory_ = file_info.is_directory; |
| + |
| + content::BrowserThread::PostTask( |
|
mtomasz
2014/10/14 06:08:50
IO -> UI?
hirono
2014/10/14 09:22:10
Thank you for catching it. Done.
|
| + content::BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&FileSystemRetainEntryFunction::RetainFileEntry, |
| + this, |
| + result == base::File::FILE_OK ? entry_id : "")); |
| } |
| bool FileSystemIsRestorableFunction::RunSync() { |