Commit 6b154b3c authored by kinaba@chromium.org's avatar kinaba@chromium.org

Support cross-profile copy between Chrome OS Google Drive folders.

Previously the processing of Drive entries are delegated to the
running profile of the apps, but now it is passed to the owning
profiles of each entries.

BUG=339706

Review URL: https://codereview.chromium.org/145973016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248921 0039d316-1c4b-4281-b951-d872f2087c98
parent 1624bab9
...@@ -2555,7 +2555,7 @@ void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( ...@@ -2555,7 +2555,7 @@ void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
DCHECK(external_mount_points); DCHECK(external_mount_points);
chromeos::FileSystemBackend* backend = chromeos::FileSystemBackend* backend =
new chromeos::FileSystemBackend( new chromeos::FileSystemBackend(
new drive::FileSystemBackendDelegate(browser_context), new drive::FileSystemBackendDelegate,
browser_context->GetSpecialStoragePolicy(), browser_context->GetSpecialStoragePolicy(),
external_mount_points, external_mount_points,
fileapi::ExternalMountPoints::GetSystemInstance()); fileapi::ExternalMountPoints::GetSystemInstance());
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/platform_file.h" #include "base/platform_file.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -46,7 +47,7 @@ void PostFileSystemCallback( ...@@ -46,7 +47,7 @@ void PostFileSystemCallback(
// Runs CreateOrOpenFile callback based on the given |error| and |file|. // Runs CreateOrOpenFile callback based on the given |error| and |file|.
void RunCreateOrOpenFileCallback( void RunCreateOrOpenFileCallback(
const AsyncFileUtil::FileSystemGetter& file_system_getter, const fileapi_internal::FileSystemGetter& file_system_getter,
const base::FilePath& file_path, const base::FilePath& file_path,
const AsyncFileUtil::CreateOrOpenCallback& callback, const AsyncFileUtil::CreateOrOpenCallback& callback,
base::File::Error error, base::File::Error error,
...@@ -114,8 +115,7 @@ void RunCreateSnapshotFileCallback( ...@@ -114,8 +115,7 @@ void RunCreateSnapshotFileCallback(
} // namespace } // namespace
AsyncFileUtil::AsyncFileUtil(const FileSystemGetter& file_system_getter) AsyncFileUtil::AsyncFileUtil() {
: file_system_getter_(file_system_getter) {
} }
AsyncFileUtil::~AsyncFileUtil() { AsyncFileUtil::~AsyncFileUtil() {
...@@ -137,13 +137,15 @@ void AsyncFileUtil::CreateOrOpen( ...@@ -137,13 +137,15 @@ void AsyncFileUtil::CreateOrOpen(
return; return;
} }
const fileapi_internal::FileSystemGetter getter =
base::Bind(&fileapi_internal::GetFileSystemFromUrl, url);
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, getter,
base::Bind(&fileapi_internal::OpenFile, base::Bind(&fileapi_internal::OpenFile,
file_path, file_flags, file_path, file_flags,
google_apis::CreateRelayCallback( google_apis::CreateRelayCallback(
base::Bind(&RunCreateOrOpenFileCallback, base::Bind(&RunCreateOrOpenFileCallback,
file_system_getter_, file_path, callback))), getter, file_path, callback))),
base::Bind(&RunCreateOrOpenFileCallbackOnError, base::Bind(&RunCreateOrOpenFileCallbackOnError,
callback, base::File::FILE_ERROR_FAILED)); callback, base::File::FILE_ERROR_FAILED));
} }
...@@ -161,7 +163,7 @@ void AsyncFileUtil::EnsureFileExists( ...@@ -161,7 +163,7 @@ void AsyncFileUtil::EnsureFileExists(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::CreateFile, base::Bind(&fileapi_internal::CreateFile,
file_path, true /* is_exlusive */, file_path, true /* is_exlusive */,
google_apis::CreateRelayCallback( google_apis::CreateRelayCallback(
...@@ -184,7 +186,7 @@ void AsyncFileUtil::CreateDirectory( ...@@ -184,7 +186,7 @@ void AsyncFileUtil::CreateDirectory(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::CreateDirectory, base::Bind(&fileapi_internal::CreateDirectory,
file_path, exclusive, recursive, file_path, exclusive, recursive,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -204,7 +206,7 @@ void AsyncFileUtil::GetFileInfo( ...@@ -204,7 +206,7 @@ void AsyncFileUtil::GetFileInfo(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::GetFileInfo, base::Bind(&fileapi_internal::GetFileInfo,
file_path, google_apis::CreateRelayCallback(callback)), file_path, google_apis::CreateRelayCallback(callback)),
base::Bind(callback, base::File::FILE_ERROR_FAILED, base::Bind(callback, base::File::FILE_ERROR_FAILED,
...@@ -224,7 +226,7 @@ void AsyncFileUtil::ReadDirectory( ...@@ -224,7 +226,7 @@ void AsyncFileUtil::ReadDirectory(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::ReadDirectory, base::Bind(&fileapi_internal::ReadDirectory,
file_path, google_apis::CreateRelayCallback(callback)), file_path, google_apis::CreateRelayCallback(callback)),
base::Bind(callback, base::File::FILE_ERROR_FAILED, base::Bind(callback, base::File::FILE_ERROR_FAILED,
...@@ -246,7 +248,7 @@ void AsyncFileUtil::Touch( ...@@ -246,7 +248,7 @@ void AsyncFileUtil::Touch(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::TouchFile, base::Bind(&fileapi_internal::TouchFile,
file_path, last_access_time, last_modified_time, file_path, last_access_time, last_modified_time,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -267,7 +269,7 @@ void AsyncFileUtil::Truncate( ...@@ -267,7 +269,7 @@ void AsyncFileUtil::Truncate(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::Truncate, base::Bind(&fileapi_internal::Truncate,
file_path, length, google_apis::CreateRelayCallback(callback)), file_path, length, google_apis::CreateRelayCallback(callback)),
base::Bind(callback, base::File::FILE_ERROR_FAILED)); base::Bind(callback, base::File::FILE_ERROR_FAILED));
...@@ -289,8 +291,14 @@ void AsyncFileUtil::CopyFileLocal( ...@@ -289,8 +291,14 @@ void AsyncFileUtil::CopyFileLocal(
return; return;
} }
// TODO(kinaba): crbug.com/339794.
// Assumption here is that |src_url| and |dest_url| are always from the same
// profile. This indeed holds as long as we mount different profiles onto
// different mount point. Hence, using GetFileSystemFromUrl(dest_url) is safe.
// This will change after we introduce cross-profile sharing etc., and we
// need to deal with files from different profiles here.
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url),
base::Bind( base::Bind(
&fileapi_internal::Copy, &fileapi_internal::Copy,
src_path, dest_path, src_path, dest_path,
...@@ -314,8 +322,11 @@ void AsyncFileUtil::MoveFileLocal( ...@@ -314,8 +322,11 @@ void AsyncFileUtil::MoveFileLocal(
return; return;
} }
// TODO(kinaba): see the comment in CopyFileLocal(). |src_url| and |dest_url|
// always return the same FileSystem by GetFileSystemFromUrl, but we need to
// change it in order to support cross-profile file sharing etc.
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url),
base::Bind( base::Bind(
&fileapi_internal::Move, &fileapi_internal::Move,
src_path, dest_path, src_path, dest_path,
...@@ -338,7 +349,7 @@ void AsyncFileUtil::CopyInForeignFile( ...@@ -338,7 +349,7 @@ void AsyncFileUtil::CopyInForeignFile(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, dest_url),
base::Bind(&fileapi_internal::CopyInForeignFile, base::Bind(&fileapi_internal::CopyInForeignFile,
src_file_path, dest_path, src_file_path, dest_path,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -358,7 +369,7 @@ void AsyncFileUtil::DeleteFile( ...@@ -358,7 +369,7 @@ void AsyncFileUtil::DeleteFile(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::Remove, base::Bind(&fileapi_internal::Remove,
file_path, false /* not recursive */, file_path, false /* not recursive */,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -378,7 +389,7 @@ void AsyncFileUtil::DeleteDirectory( ...@@ -378,7 +389,7 @@ void AsyncFileUtil::DeleteDirectory(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::Remove, base::Bind(&fileapi_internal::Remove,
file_path, false /* not recursive */, file_path, false /* not recursive */,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -398,7 +409,7 @@ void AsyncFileUtil::DeleteRecursively( ...@@ -398,7 +409,7 @@ void AsyncFileUtil::DeleteRecursively(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::Remove, base::Bind(&fileapi_internal::Remove,
file_path, true /* recursive */, file_path, true /* recursive */,
google_apis::CreateRelayCallback(callback)), google_apis::CreateRelayCallback(callback)),
...@@ -421,7 +432,7 @@ void AsyncFileUtil::CreateSnapshotFile( ...@@ -421,7 +432,7 @@ void AsyncFileUtil::CreateSnapshotFile(
} }
PostFileSystemCallback( PostFileSystemCallback(
file_system_getter_, base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
base::Bind(&fileapi_internal::CreateSnapshotFile, base::Bind(&fileapi_internal::CreateSnapshotFile,
file_path, file_path,
google_apis::CreateRelayCallback( google_apis::CreateRelayCallback(
......
...@@ -18,13 +18,7 @@ namespace internal { ...@@ -18,13 +18,7 @@ namespace internal {
// The implementation of fileapi::AsyncFileUtil for Drive File System. // The implementation of fileapi::AsyncFileUtil for Drive File System.
class AsyncFileUtil : public fileapi::AsyncFileUtil { class AsyncFileUtil : public fileapi::AsyncFileUtil {
public: public:
// Callback to return the FileSystemInterface instance. This is an AsyncFileUtil();
// injecting point for testing.
// Note that the callback will be copied between threads (IO and UI), and
// will be called on UI thread.
typedef base::Callback<FileSystemInterface*()> FileSystemGetter;
explicit AsyncFileUtil(const FileSystemGetter& file_system_getter);
virtual ~AsyncFileUtil(); virtual ~AsyncFileUtil();
// fileapi::AsyncFileUtil overrides. // fileapi::AsyncFileUtil overrides.
...@@ -98,8 +92,6 @@ class AsyncFileUtil : public fileapi::AsyncFileUtil { ...@@ -98,8 +92,6 @@ class AsyncFileUtil : public fileapi::AsyncFileUtil {
const CreateSnapshotFileCallback& callback) OVERRIDE; const CreateSnapshotFileCallback& callback) OVERRIDE;
private: private:
FileSystemGetter file_system_getter_;
DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil); DISALLOW_COPY_AND_ASSIGN(AsyncFileUtil);
}; };
......
...@@ -9,10 +9,9 @@ ...@@ -9,10 +9,9 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/fileapi/async_file_util.h" #include "chrome/browser/chromeos/drive/fileapi/async_file_util.h"
#include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
#include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h" #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h"
#include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h" #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "webkit/browser/blob/file_stream_reader.h" #include "webkit/browser/blob/file_stream_reader.h"
#include "webkit/browser/fileapi/async_file_util.h" #include "webkit/browser/fileapi/async_file_util.h"
...@@ -23,12 +22,8 @@ using content::BrowserThread; ...@@ -23,12 +22,8 @@ using content::BrowserThread;
namespace drive { namespace drive {
FileSystemBackendDelegate::FileSystemBackendDelegate( FileSystemBackendDelegate::FileSystemBackendDelegate()
content::BrowserContext* browser_context) : async_file_util_(new internal::AsyncFileUtil) {
: profile_id_(Profile::FromBrowserContext(browser_context)),
async_file_util_(new internal::AsyncFileUtil(
base::Bind(&util::GetFileSystemByProfileId, profile_id_))) {
DCHECK(profile_id_);
} }
FileSystemBackendDelegate::~FileSystemBackendDelegate() { FileSystemBackendDelegate::~FileSystemBackendDelegate() {
...@@ -56,7 +51,7 @@ FileSystemBackendDelegate::CreateFileStreamReader( ...@@ -56,7 +51,7 @@ FileSystemBackendDelegate::CreateFileStreamReader(
return scoped_ptr<webkit_blob::FileStreamReader>( return scoped_ptr<webkit_blob::FileStreamReader>(
new internal::WebkitFileStreamReaderImpl( new internal::WebkitFileStreamReaderImpl(
base::Bind(&util::GetFileSystemByProfileId, profile_id_), base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
context->default_file_task_runner(), context->default_file_task_runner(),
file_path, offset, expected_modification_time)); file_path, offset, expected_modification_time));
} }
...@@ -76,7 +71,7 @@ FileSystemBackendDelegate::CreateFileStreamWriter( ...@@ -76,7 +71,7 @@ FileSystemBackendDelegate::CreateFileStreamWriter(
return scoped_ptr<fileapi::FileStreamWriter>( return scoped_ptr<fileapi::FileStreamWriter>(
new internal::WebkitFileStreamWriterImpl( new internal::WebkitFileStreamWriterImpl(
base::Bind(&util::GetFileSystemByProfileId, profile_id_), base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
context->default_file_task_runner(),file_path, offset)); context->default_file_task_runner(),file_path, offset));
} }
......
...@@ -9,10 +9,6 @@ ...@@ -9,10 +9,6 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h" #include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h"
namespace content {
class BrowserContext;
} // namespace content
namespace fileapi { namespace fileapi {
class AsyncFileUtil; class AsyncFileUtil;
} // namespace fileapi } // namespace fileapi
...@@ -23,8 +19,7 @@ namespace drive { ...@@ -23,8 +19,7 @@ namespace drive {
// for Drive file system. // for Drive file system.
class FileSystemBackendDelegate : public chromeos::FileSystemBackendDelegate { class FileSystemBackendDelegate : public chromeos::FileSystemBackendDelegate {
public: public:
// |browser_context| is used to obtain |profile_id_|. FileSystemBackendDelegate();
explicit FileSystemBackendDelegate(content::BrowserContext* browser_context);
virtual ~FileSystemBackendDelegate(); virtual ~FileSystemBackendDelegate();
// FileSystemBackend::Delegate overrides. // FileSystemBackend::Delegate overrides.
...@@ -41,8 +36,6 @@ class FileSystemBackendDelegate : public chromeos::FileSystemBackendDelegate { ...@@ -41,8 +36,6 @@ class FileSystemBackendDelegate : public chromeos::FileSystemBackendDelegate {
fileapi::FileSystemContext* context) OVERRIDE; fileapi::FileSystemContext* context) OVERRIDE;
private: private:
// The profile for processing Drive accesses. Should not be NULL.
void* profile_id_;
scoped_ptr<fileapi::AsyncFileUtil> async_file_util_; scoped_ptr<fileapi::AsyncFileUtil> async_file_util_;
DISALLOW_COPY_AND_ASSIGN(FileSystemBackendDelegate); DISALLOW_COPY_AND_ASSIGN(FileSystemBackendDelegate);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/resource_entry_conversion.h" #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "webkit/browser/fileapi/file_system_url.h"
#include "webkit/common/fileapi/directory_entry.h" #include "webkit/common/fileapi/directory_entry.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -197,6 +198,13 @@ void OpenFileAfterFileSystemOpenFile(int file_flags, ...@@ -197,6 +198,13 @@ void OpenFileAfterFileSystemOpenFile(int file_flags,
} // namespace } // namespace
FileSystemInterface* GetFileSystemFromUrl(const fileapi::FileSystemURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Profile* profile = util::ExtractProfileFromPath(url.path());
return profile ? util::GetFileSystemByProfile(profile) : NULL;
}
void RunFileSystemCallback( void RunFileSystemCallback(
const FileSystemGetter& file_system_getter, const FileSystemGetter& file_system_getter,
const base::Callback<void(FileSystemInterface*)>& callback, const base::Callback<void(FileSystemInterface*)>& callback,
......
...@@ -34,6 +34,7 @@ class FilePath; ...@@ -34,6 +34,7 @@ class FilePath;
namespace fileapi { namespace fileapi {
struct DirectoryEntry; struct DirectoryEntry;
class FileSystemURL;
} // namespace fileapi } // namespace fileapi
namespace drive { namespace drive {
...@@ -69,6 +70,11 @@ typedef base::Callback< ...@@ -69,6 +70,11 @@ typedef base::Callback<
base::PlatformFile platform_file, base::PlatformFile platform_file,
const base::Closure& close_callback)> OpenFileCallback; const base::Closure& close_callback)> OpenFileCallback;
// Gets the profile of the Drive entry pointed by |url|. Used as
// FileSystemGetter callback by binding an URL on the IO thread and passing to
// the UI thread.
FileSystemInterface* GetFileSystemFromUrl(const fileapi::FileSystemURL& url);
// Runs |file_system_getter| to obtain the instance of FileSystemInstance, // Runs |file_system_getter| to obtain the instance of FileSystemInstance,
// and then runs |callback| with it. // and then runs |callback| with it.
// If |file_system_getter| returns NULL, runs |error_callback| instead. // If |file_system_getter| returns NULL, runs |error_callback| instead.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment