diff options
Diffstat (limited to 'chrome')
6 files changed, 85 insertions, 54 deletions
diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.cc b/chrome/browser/chromeos/extensions/file_manager/event_router.cc index a4fef16..ce4c9b0 100644 --- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc @@ -92,6 +92,7 @@ bool IsUploadJob(drive::JobType type) { // Converts the job info to a IDL generated type. void JobInfoToTransferStatus( + Profile* profile, const std::string& extension_id, const std::string& job_status, const drive::JobInfo& job_info, @@ -99,8 +100,8 @@ void JobInfoToTransferStatus( DCHECK(IsActiveFileTransferJobInfo(job_info)); scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); - GURL url = util::ConvertRelativeFilePathToFileSystemUrl( - job_info.file_path, extension_id); + GURL url = util::ConvertDrivePathToFileSystemUrl( + profile, job_info.file_path, extension_id); status->file_url = url.spec(); status->transfer_state = file_browser_private::ParseTransferState(job_status); status->transfer_type = @@ -547,7 +548,8 @@ void EventRouter::SendDriveFileTransferEvent(bool always) { iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { linked_ptr<file_browser_private::FileTransferStatus> status( new file_browser_private::FileTransferStatus()); - JobInfoToTransferStatus(kFileManagerAppId, + JobInfoToTransferStatus(profile_, + kFileManagerAppId, iter->second.status, iter->second.job_info, status.get()); @@ -560,13 +562,12 @@ void EventRouter::SendDriveFileTransferEvent(bool always) { last_file_transfer_event_ = now; } -void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) { - HandleFileWatchNotification(directory_path, false); +void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) { + HandleFileWatchNotification(drive_path, false); } -void EventRouter::OnDriveSyncError( - drive::file_system::DriveSyncErrorType type, - const base::FilePath& file_path) { +void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type, + const base::FilePath& drive_path) { file_browser_private::DriveSyncErrorEvent event; switch (type) { case drive::file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION: @@ -582,8 +583,8 @@ void EventRouter::OnDriveSyncError( file_browser_private::DRIVE_SYNC_ERROR_TYPE_MISC; break; } - event.file_url = util::ConvertRelativeFilePathToFileSystemUrl( - file_path, kFileManagerAppId).spec(); + event.file_url = util::ConvertDrivePathToFileSystemUrl( + profile_, drive_path, kFileManagerAppId).spec(); BroadcastEvent( profile_, file_browser_private::OnDriveSyncError::kEventName, diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.h b/chrome/browser/chromeos/extensions/file_manager/event_router.h index 30a26ff..b038c3d 100644 --- a/chrome/browser/chromeos/extensions/file_manager/event_router.h +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.h @@ -96,11 +96,9 @@ class EventRouter virtual void OnRefreshTokenInvalid() OVERRIDE; // drive::FileSystemObserver overrides. - virtual void OnDirectoryChanged( - const base::FilePath& directory_path) OVERRIDE; - virtual void OnDriveSyncError( - drive::file_system::DriveSyncErrorType type, - const base::FilePath& file_path) OVERRIDE; + virtual void OnDirectoryChanged(const base::FilePath& drive_path) OVERRIDE; + virtual void OnDriveSyncError(drive::file_system::DriveSyncErrorType type, + const base::FilePath& drive_path) OVERRIDE; // VolumeManagerObserver overrides. virtual void OnDiskAdded( diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc index 139ca7e..dd43e4d 100644 --- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc +++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc @@ -8,6 +8,7 @@ #include "chrome/browser/chromeos/drive/logging.h" #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" #include "chrome/browser/chromeos/file_manager/file_tasks.h" +#include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "chrome/browser/chromeos/file_manager/url_util.h" #include "chrome/browser/chromeos/fileapi/file_system_backend.h" #include "chrome/browser/drive/drive_app_registry.h" @@ -404,7 +405,9 @@ void FileBrowserPrivateSearchDriveFunction::OnSearch( base::DictionaryValue* entry = new base::DictionaryValue(); entry->SetString("fileSystemName", info.name); entry->SetString("fileSystemRoot", info.root_url.spec()); - entry->SetString("fileFullPath", "/" + results->at(i).path.value()); + entry->SetString("fileFullPath", + "/" + file_manager::util::ConvertDrivePathToRelativeFileSystemPath( + GetProfile(), results->at(i).path).AsUTF8Unsafe()); entry->SetBoolean("fileIsDirectory", results->at(i).is_directory); entries->Append(entry); } @@ -491,7 +494,9 @@ void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( base::DictionaryValue* entry = new base::DictionaryValue(); entry->SetString("fileSystemName", info.name); entry->SetString("fileSystemRoot", info.root_url.spec()); - entry->SetString("fileFullPath", "/" + results->at(i).path.value()); + entry->SetString("fileFullPath", + "/" + file_manager::util::ConvertDrivePathToRelativeFileSystemPath( + GetProfile(), results->at(i).path).AsUTF8Unsafe()); entry->SetBoolean("fileIsDirectory", results->at(i).entry.file_info().is_directory()); diff --git a/chrome/browser/chromeos/file_manager/file_browser_handlers.cc b/chrome/browser/chromeos/file_manager/file_browser_handlers.cc index 6e4bf80..7087115 100644 --- a/chrome/browser/chromeos/file_manager/file_browser_handlers.cc +++ b/chrome/browser/chromeos/file_manager/file_browser_handlers.cc @@ -260,8 +260,7 @@ FileBrowserHandlerExecutor::SetupFileAccessPermissions( // Grant access to this particular file to target extension. This will // ensure that the target extension can access only this FS entry and // prevent from traversing FS hierarchy upward. - backend->GrantFileAccessToExtension( - handler_extension->id(), virtual_path); + backend->GrantFileAccessToExtension(handler_extension->id(), virtual_path); // Output values. FileDefinition file; @@ -395,9 +394,8 @@ void FileBrowserHandlerExecutor::SetupPermissionsAndDispatchEvent( file_entries->Append(file_def); file_def->SetString("fileSystemName", file_system_name); file_def->SetString("fileSystemRoot", file_system_root.spec()); - base::FilePath root(FILE_PATH_LITERAL("/")); - base::FilePath full_path = root.Append(iter->virtual_path); - file_def->SetString("fileFullPath", full_path.value()); + file_def->SetString("fileFullPath", + "/" + iter->virtual_path.AsUTF8Unsafe()); file_def->SetBoolean("fileIsDirectory", iter->is_directory); } diff --git a/chrome/browser/chromeos/file_manager/fileapi_util.cc b/chrome/browser/chromeos/file_manager/fileapi_util.cc index 0a74354..edad4fb 100644 --- a/chrome/browser/chromeos/file_manager/fileapi_util.cc +++ b/chrome/browser/chromeos/file_manager/fileapi_util.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chromeos/file_manager/fileapi_util.h" #include "base/files/file_path.h" +#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile.h" @@ -20,6 +21,20 @@ namespace file_manager { namespace util { +namespace { + +GURL ConvertRelativeFilePathToFileSystemUrl(const base::FilePath& relative_path, + const std::string& extension_id) { + GURL base_url = fileapi::GetFileSystemRootURI( + extensions::Extension::GetBaseURLFromExtensionId(extension_id), + fileapi::kFileSystemTypeExternal); + return GURL(base_url.spec() + + net::EscapeUrlEncodedData(relative_path.AsUTF8Unsafe(), + false)); // Space to %20 instead of +. +} + +} // namespace + fileapi::FileSystemContext* GetFileSystemContextForExtensionId( Profile* profile, const std::string& extension_id) { @@ -37,27 +52,33 @@ fileapi::FileSystemContext* GetFileSystemContextForRenderViewHost( GetFileSystemContext(); } -GURL ConvertRelativeFilePathToFileSystemUrl(const base::FilePath& relative_path, - const std::string& extension_id) { - GURL base_url = fileapi::GetFileSystemRootURI( - extensions::Extension::GetBaseURLFromExtensionId(extension_id), - fileapi::kFileSystemTypeExternal); - return GURL(base_url.spec() + - net::EscapeUrlEncodedData(relative_path.AsUTF8Unsafe(), - false)); // Space to %20 instead of +. +base::FilePath ConvertDrivePathToRelativeFileSystemPath( + Profile* profile, + const base::FilePath& drive_path) { + // "drive-xxx" + base::FilePath path = drive::util::GetDriveMountPointPath(profile).BaseName(); + // appended with (|drive_path| - "drive"). + drive::util::GetDriveGrandRootPath().AppendRelativePath(drive_path, &path); + return path; } -bool ConvertAbsoluteFilePathToFileSystemUrl( - Profile* profile, - const base::FilePath& absolute_path, - const std::string& extension_id, - GURL* url) { +GURL ConvertDrivePathToFileSystemUrl(Profile* profile, + const base::FilePath& drive_path, + const std::string& extension_id) { + const base::FilePath relative_path = + ConvertDrivePathToRelativeFileSystemPath(profile, drive_path); + return ConvertRelativeFilePathToFileSystemUrl(drive_path, extension_id); +} + +bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile, + const base::FilePath& absolute_path, + const std::string& extension_id, + GURL* url) { base::FilePath relative_path; - if (!ConvertAbsoluteFilePathToRelativeFileSystemPath( - profile, - extension_id, - absolute_path, - &relative_path)) { + if (!ConvertAbsoluteFilePathToRelativeFileSystemPath(profile, + extension_id, + absolute_path, + &relative_path)) { return false; } *url = ConvertRelativeFilePathToFileSystemUrl(relative_path, extension_id); diff --git a/chrome/browser/chromeos/file_manager/fileapi_util.h b/chrome/browser/chromeos/file_manager/fileapi_util.h index 703b14a..454c806 100644 --- a/chrome/browser/chromeos/file_manager/fileapi_util.h +++ b/chrome/browser/chromeos/file_manager/fileapi_util.h @@ -39,23 +39,31 @@ fileapi::FileSystemContext* GetFileSystemContextForRenderViewHost( Profile* profile, content::RenderViewHost* render_view_host); -// Converts |relative_path| (e.g., "drive/root" or "Downloads") into external -// filesystem URL (e.g., filesystem://id/external/drive/root). -GURL ConvertRelativeFilePathToFileSystemUrl(const base::FilePath& relative_path, - const std::string& extension_id); +// Converts DrivePath (e.g., "drive/root", which always starts with the fixed +// "drive" directory) to a RelativeFileSystemPathrelative (e.g., +// "drive-xxx/root/foo". which starts from the "mount point" in the FileSystem +// API that may be distinguished for each profile by the appended "xxx" part.) +base::FilePath ConvertDrivePathToRelativeFileSystemPath( + Profile* profile, + const base::FilePath& drive_path); + +// Converts DrivePath to FileSystem URL. +// E.g., "drive/root" to filesystem://id/external/drive-xxx/root. +GURL ConvertDrivePathToFileSystemUrl(Profile* profile, + const base::FilePath& drive_path, + const std::string& extension_id); -// Converts |absolute_path| (e.g., "/special/drive/root" or -// "/home/chronos/user/Downloads") into external filesystem URL. Returns false +// Converts AbsolutePath (e.g., "/special/drive-xxx/root" or +// "/home/chronos/u-xxx/Downloads") into filesystem URL. Returns false // if |absolute_path| is not managed by the external filesystem provider. -bool ConvertAbsoluteFilePathToFileSystemUrl( - Profile* profile, - const base::FilePath& absolute_path, - const std::string& extension_id, - GURL* url); +bool ConvertAbsoluteFilePathToFileSystemUrl(Profile* profile, + const base::FilePath& absolute_path, + const std::string& extension_id, + GURL* url); -// Converts |absolute_path| into |relative_path| within the external -// provider in File API. Returns false if |absolute_path| is not managed -// by the external filesystem provider. +// Converts AbsolutePath into RelativeFileSystemPath (e.g., +// "/special/drive-xxx/root/foo" => "drive-xxx/root/foo".) Returns false if +// |absolute_path| is not managed by the external filesystem provider. bool ConvertAbsoluteFilePathToRelativeFileSystemPath( Profile* profile, const std::string& extension_id, |