diff options
7 files changed, 69 insertions, 79 deletions
diff --git a/chrome/browser/chromeos/drive/file_system_util.cc b/chrome/browser/chromeos/drive/file_system_util.cc index 1abe96f..416bbc5 100644 --- a/chrome/browser/chromeos/drive/file_system_util.cc +++ b/chrome/browser/chromeos/drive/file_system_util.cc @@ -89,15 +89,6 @@ DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) { return service; } -void CheckDirectoryExistsAfterGetResourceEntry( - const FileOperationCallback& callback, - FileError error, - scoped_ptr<ResourceEntry> entry) { - if (error == FILE_ERROR_OK && !entry->file_info().is_directory()) - error = FILE_ERROR_NOT_A_DIRECTORY; - callback.Run(error); -} - } // namespace const base::FilePath& GetDriveGrandRootPath() { @@ -338,20 +329,6 @@ void EnsureDirectoryExists(Profile* profile, } } -void CheckDirectoryExists(Profile* profile, - const base::FilePath& directory, - const FileOperationCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!callback.is_null()); - - FileSystemInterface* file_system = GetFileSystemByProfile(profile); - DCHECK(file_system); - - file_system->GetResourceEntry( - ExtractDrivePath(directory), - base::Bind(&CheckDirectoryExistsAfterGetResourceEntry, callback)); -} - void EmptyFileOperationCallback(FileError error) { } diff --git a/chrome/browser/chromeos/drive/file_system_util.h b/chrome/browser/chromeos/drive/file_system_util.h index 278ecbc..a16ed60 100644 --- a/chrome/browser/chromeos/drive/file_system_util.h +++ b/chrome/browser/chromeos/drive/file_system_util.h @@ -144,12 +144,6 @@ void PrepareWritableFileAndRun(Profile* profile, const base::FilePath& path, const PrepareWritableFileCallback& callback); -// Checks whether a directory exists at the given Drive path |directory|. -// Must be called from UI thread. The result will be called back to |callback|. -void CheckDirectoryExists(Profile* profile, - const base::FilePath& directory, - const FileOperationCallback& callback); - // Ensures the existence of |directory| of '/special/drive/foo'. This will // create |directory| and its ancestors if they don't exist. |callback| is // invoked after making sure that |directory| exists. |callback| should diff --git a/chrome/browser/chromeos/file_manager/fileapi_util.cc b/chrome/browser/chromeos/file_manager/fileapi_util.cc index 0286b58..68e4cab 100644 --- a/chrome/browser/chromeos/file_manager/fileapi_util.cc +++ b/chrome/browser/chromeos/file_manager/fileapi_util.cc @@ -7,6 +7,7 @@ #include "base/files/file.h" #include "base/files/file_path.h" #include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/chromeos/file_manager/app_id.h" #include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" @@ -14,6 +15,7 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/storage_partition.h" #include "extensions/common/extension.h" +#include "google_apis/drive/task_util.h" #include "net/base/escape.h" #include "url/gurl.h" #include "webkit/browser/fileapi/file_system_context.h" @@ -211,6 +213,18 @@ void OnConvertFileDefinitionDone( callback.Run(entry_definition_list->at(0)); } +// Used to implement CheckIfDirectoryExists(). +void CheckIfDirectoryExistsOnIOThread( + scoped_refptr<fileapi::FileSystemContext> file_system_context, + const GURL& url, + const fileapi::FileSystemOperationRunner::StatusCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + fileapi::FileSystemURL file_system_url = file_system_context->CrackURL(url); + file_system_context->operation_runner()->DirectoryExists( + file_system_url, callback); +} + } // namespace EntryDefinition::EntryDefinition() { @@ -328,5 +342,26 @@ void ConvertFileDefinitionToEntryDefinition( base::Bind(&OnConvertFileDefinitionDone, callback)); } +void CheckIfDirectoryExists( + scoped_refptr<fileapi::FileSystemContext> file_system_context, + const GURL& url, + const fileapi::FileSystemOperationRunner::StatusCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + // Check the existence of directory using file system API implementation on + // behalf of the file manager app. We need to grant access beforehand. + fileapi::ExternalFileSystemBackend* backend = + file_system_context->external_backend(); + DCHECK(backend); + backend->GrantFullAccessToExtension(kFileManagerAppId); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&CheckIfDirectoryExistsOnIOThread, + file_system_context, + url, + google_apis::CreateRelayCallback(callback))); +} + } // namespace util } // namespace file_manager diff --git a/chrome/browser/chromeos/file_manager/fileapi_util.h b/chrome/browser/chromeos/file_manager/fileapi_util.h index 305857a..fe9c52f 100644 --- a/chrome/browser/chromeos/file_manager/fileapi_util.h +++ b/chrome/browser/chromeos/file_manager/fileapi_util.h @@ -13,6 +13,7 @@ #include "base/files/file.h" #include "base/files/file_path.h" #include "url/gurl.h" +#include "webkit/browser/fileapi/file_system_operation_runner.h" class Profile; @@ -124,6 +125,12 @@ void ConvertFileDefinitionListToEntryDefinitionList( const FileDefinitionList& file_definition_list, const EntryDefinitionListCallback& callback); +// Checks if a directory exists at |url|. +void CheckIfDirectoryExists( + scoped_refptr<fileapi::FileSystemContext> file_system_context, + const GURL& url, + const fileapi::FileSystemOperationRunner::StatusCallback& callback); + } // namespace util } // namespace file_manager diff --git a/chrome/browser/chromeos/file_manager/filesystem_api_util.cc b/chrome/browser/chromeos/file_manager/filesystem_api_util.cc index 04dc1d5..f53c6b1 100644 --- a/chrome/browser/chromeos/file_manager/filesystem_api_util.cc +++ b/chrome/browser/chromeos/file_manager/filesystem_api_util.cc @@ -36,11 +36,14 @@ void GetMimeTypeAfterGetResourceEntry( callback.Run(true, entry->file_specific_info().content_mime_type()); } -void CheckDirectoryAfterDriveCheck(const base::Callback<void(bool)>& callback, - drive::FileError error) { +// Helper function to converts a callback that takes boolean value to that takes +// File::Error, by regarding FILE_OK as the only successful value. +void BoolCallbackAsFileErrorCallback( + const base::Callback<void(bool)>& callback, + base::File::Error error) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - return callback.Run(error == drive::FILE_ERROR_OK); + return callback.Run(error == base::File::FILE_OK); } void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, @@ -65,13 +68,9 @@ bool IsUnderNonNativeLocalPath(Profile* profile, return false; } - content::StoragePartition* partition = - content::BrowserContext::GetStoragePartitionForSite( - profile, - extensions::util::GetSiteForExtensionId(kFileManagerAppId, profile)); - fileapi::FileSystemContext* context = partition->GetFileSystemContext(); - - fileapi::FileSystemURL filesystem_url = context->CrackURL(url); + fileapi::FileSystemURL filesystem_url = + GetFileSystemContextForExtensionId(profile, + kFileManagerAppId)->CrackURL(url); if (!filesystem_url.is_valid()) return false; @@ -123,12 +122,23 @@ void IsNonNativeLocalPathDirectory( const base::FilePath& path, const base::Callback<void(bool)>& callback) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + DCHECK(IsUnderNonNativeLocalPath(profile, path)); - // TODO(kinaba): support other types of volumes besides Drive. - drive::util::CheckDirectoryExists( - profile, - path, - base::Bind(&CheckDirectoryAfterDriveCheck, callback)); + GURL url; + if (!util::ConvertAbsoluteFilePathToFileSystemUrl( + profile, path, kFileManagerAppId, &url)) { + // Posting to the current thread, so that we always call back asynchronously + // independent from whether or not the operation succeeeds. + content::BrowserThread::PostTask(content::BrowserThread::UI, + FROM_HERE, + base::Bind(callback, false)); + return; + } + + util::CheckIfDirectoryExists( + GetFileSystemContextForExtensionId(profile, kFileManagerAppId), + url, + base::Bind(&BoolCallbackAsFileErrorCallback, callback)); } void PrepareNonNativeLocalPathWritableFile( diff --git a/chrome/browser/chromeos/file_manager/open_util.cc b/chrome/browser/chromeos/file_manager/open_util.cc index b16ffc8..3378da0 100644 --- a/chrome/browser/chromeos/file_manager/open_util.cc +++ b/chrome/browser/chromeos/file_manager/open_util.cc @@ -21,7 +21,6 @@ #include "chrome/browser/ui/simple_message_box.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/user_metrics.h" -#include "google_apis/drive/task_util.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "webkit/browser/fileapi/file_system_backend.h" @@ -144,40 +143,6 @@ void ContinueOpenItem(Profile* profile, } } -// Used to implement CheckIfDirectoryExists(). -void CheckIfDirectoryExistsOnIOThread( - scoped_refptr<fileapi::FileSystemContext> file_system_context, - const GURL& url, - const fileapi::FileSystemOperationRunner::StatusCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - fileapi::FileSystemURL file_system_url = file_system_context->CrackURL(url); - file_system_context->operation_runner()->DirectoryExists( - file_system_url, callback); -} - -// Checks if a directory exists at |url|. -void CheckIfDirectoryExists( - scoped_refptr<fileapi::FileSystemContext> file_system_context, - const GURL& url, - const fileapi::FileSystemOperationRunner::StatusCallback& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // Check the existence of directory using file system API implementation on - // behalf of the file manager app. We need to grant access beforehand. - fileapi::ExternalFileSystemBackend* backend = - file_system_context->external_backend(); - DCHECK(backend); - backend->GrantFullAccessToExtension(kFileManagerAppId); - - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&CheckIfDirectoryExistsOnIOThread, - file_system_context, - url, - google_apis::CreateRelayCallback(callback))); -} - // Converts the |given_path| passed from external callers to the form that the // file manager can correctly handle. It first migrates old Drive/Download // folder path to the new formats, and then converts path to filesystem URL. diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc b/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc index b6e67fa..f5b5d00 100644 --- a/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc +++ b/chrome/browser/extensions/api/file_system/file_system_apitest_chromeos.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chromeos/drive/test_util.h" #include "chrome/browser/drive/fake_drive_service.h" #include "chrome/browser/extensions/api/file_system/file_system_api.h" +#include "chrome/browser/extensions/component_loader.h" #include "content/public/test/test_utils.h" #include "google_apis/drive/test_util.h" @@ -27,6 +28,7 @@ class FileSystemApiTestForDrive : public PlatformAppBrowserTest { // real DriveIntegrationService instance is created.) virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture(); + extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); ASSERT_TRUE(test_cache_root_.CreateUniqueTempDir()); |