diff options
author | hshi@google.com <hshi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:46:48 +0000 |
---|---|---|
committer | hshi@google.com <hshi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 21:46:48 +0000 |
commit | b9f22d1e6fb76de05b9bb8a361bae8c7a58ed656 (patch) | |
tree | b28ef1c64ac86963caa1460d5feb60fc8825e9e9 | |
parent | c83d50b0b385cf6adb4da9d33fb81da9d5beacc2 (diff) | |
download | chromium_src-b9f22d1e6fb76de05b9bb8a361bae8c7a58ed656.zip chromium_src-b9f22d1e6fb76de05b9bb8a361bae8c7a58ed656.tar.gz chromium_src-b9f22d1e6fb76de05b9bb8a361bae8c7a58ed656.tar.bz2 |
gdata: Support opening zip file on Google Docs.
Pass the file extension in the 2nd argument to DiskMountManager::MountPath
to indicate the archive format (e.g.: .zip, .rar, etc.)
When mounting and unmounting archive files in GData cache, call
GDataFileSystem::SetMountedState to set or clear the "mounted" state
accordingly.
BUG=chromium-os:28678
TEST=Verify that mounting/unmounting archive files on GData works correctly.
Review URL: http://codereview.chromium.org/10083067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133987 0039d316-1c4b-4281-b951-d872f2087c98
13 files changed, 105 insertions, 42 deletions
diff --git a/chrome/browser/chromeos/disks/disk_mount_manager.cc b/chrome/browser/chromeos/disks/disk_mount_manager.cc index 38fbf02..5553054 100644 --- a/chrome/browser/chromeos/disks/disk_mount_manager.cc +++ b/chrome/browser/chromeos/disks/disk_mount_manager.cc @@ -58,6 +58,7 @@ class DiskMountManagerImpl : public DiskMountManager { // DiskMountManager override. virtual void MountPath(const std::string& source_path, + const std::string& source_format, MountType type) OVERRIDE { // Hidden and non-existent devices should not be mounted. if (type == MOUNT_TYPE_DEVICE) { @@ -70,6 +71,7 @@ class DiskMountManagerImpl : public DiskMountManager { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); cros_disks_client_->Mount( source_path, + source_format, type, // When succeeds, OnMountCompleted will be called by // "MountCompleted" signal instead. diff --git a/chrome/browser/chromeos/disks/disk_mount_manager.h b/chrome/browser/chromeos/disks/disk_mount_manager.h index af8406f..53aca0e 100644 --- a/chrome/browser/chromeos/disks/disk_mount_manager.h +++ b/chrome/browser/chromeos/disks/disk_mount_manager.h @@ -201,7 +201,9 @@ class DiskMountManager { virtual void RequestMountInfoRefresh() = 0; // Mounts a device. - virtual void MountPath(const std::string& source_path, MountType type) = 0; + virtual void MountPath(const std::string& source_path, + const std::string& source_format, + MountType type) = 0; // Unmounts a mounted disk. virtual void UnmountPath(const std::string& mount_path) = 0; diff --git a/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc index 38a6cd0..720311e 100644 --- a/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc +++ b/chrome/browser/chromeos/disks/mock_disk_mount_manager.cc @@ -136,7 +136,7 @@ void MockDiskMountManager::SetupDefaultReplies() { .WillRepeatedly(ReturnRef(disks_)); EXPECT_CALL(*this, RequestMountInfoRefresh()) .Times(AnyNumber()); - EXPECT_CALL(*this, MountPath(_, _)) + EXPECT_CALL(*this, MountPath(_, _, _)) .Times(AnyNumber()); EXPECT_CALL(*this, UnmountPath(_)) .Times(AnyNumber()); diff --git a/chrome/browser/chromeos/disks/mock_disk_mount_manager.h b/chrome/browser/chromeos/disks/mock_disk_mount_manager.h index e6fb7ed..d728f18 100644 --- a/chrome/browser/chromeos/disks/mock_disk_mount_manager.h +++ b/chrome/browser/chromeos/disks/mock_disk_mount_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -30,7 +30,8 @@ class MockDiskMountManager : public DiskMountManager { MOCK_CONST_METHOD0(mount_points, const DiskMountManager::MountPointMap&(void)); MOCK_METHOD0(RequestMountInfoRefresh, void(void)); - MOCK_METHOD2(MountPath, void(const std::string&, MountType)); + MOCK_METHOD3(MountPath, void(const std::string&, const std::string&, + MountType)); MOCK_METHOD1(UnmountPath, void(const std::string&)); MOCK_METHOD3(GetSizeStatsOnFileThread, void(const std::string&, size_t*, size_t*)); diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc index 3332c34..6a5ae12 100644 --- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc @@ -240,6 +240,20 @@ void FileBrowserEventRouter::MountCompleted( disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), error_code == chromeos::MOUNT_ERROR_NONE, error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM); + } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { + // Clear the "mounted" state for archive files in gdata cache + // when mounting failed or unmounting succeeded. + if ((event_type == DiskMountManager::MOUNTING) != + (error_code == chromeos::MOUNT_ERROR_NONE)) { + FilePath source_path(mount_info.source_path); + gdata::GDataSystemService* system_service = + gdata::GDataSystemServiceFactory::GetForProfile(profile_); + gdata::GDataFileSystem* file_system = + system_service ? system_service->file_system() : NULL; + if (file_system && file_system->IsUnderGDataCacheDirectory(source_path)) + file_system->SetMountedState(source_path, false, + gdata::SetMountedStateCallback()); + } } } @@ -415,9 +429,10 @@ void FileBrowserEventRouter::OnDiskAdded( // If disk is not mounted yet and it has media, give it a try. if (disk->mount_path().empty() && disk->has_media()) { - // Initiate disk mount operation. + // Initiate disk mount operation. MountPath auto-detects the filesystem + // format if the second argument is empty. DiskMountManager::GetInstance()->MountPath( - disk->device_path(), chromeos::MOUNT_TYPE_DEVICE); + disk->device_path(), std::string(), chromeos::MOUNT_TYPE_DEVICE); } else { // Either the disk was mounted or it has no media. In both cases we don't // want the Scanning notification to persist. @@ -483,8 +498,8 @@ void FileBrowserEventRouter::OnFormattingFinished( // Hide it after a couple of seconds. notifications_->HideNotificationDelayed( FileBrowserNotifications::FORMAT_SUCCESS, device_path, 4000); - - DiskMountManager::GetInstance()->MountPath(device_path, + // MountPath auto-detects filesystem format if second argument is empty. + DiskMountManager::GetInstance()->MountPath(device_path, std::string(), chromeos::MOUNT_TYPE_DEVICE); } else { notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_browser_private_api.cc index 4d6b804..a722228 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_api.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_api.cc @@ -1017,14 +1017,42 @@ void AddMountFunction::GetLocalPathsResponseOnUIThread( } #if defined(OS_CHROMEOS) - FilePath source_file = files[0].path; - DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); - // MountPath() takes a std::string. - disk_mount_manager->MountPath(source_file.AsUTF8Unsafe(), - DiskMountManager::MountTypeFromString(mount_type_str)); + const FilePath& source_path = files[0].path; + const FilePath::StringType& display_name = files[0].display_name; + // Check if the source path is under GData cache directory. + gdata::GDataSystemService* system_service = + gdata::GDataSystemServiceFactory::GetForProfile(profile_); + gdata::GDataFileSystem* file_system = + system_service ? system_service->file_system() : NULL; + if (file_system && file_system->IsUnderGDataCacheDirectory(source_path)) { + file_system->SetMountedState( + source_path, + true, + base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, + display_name)); + } else { + OnMountedStateSet(mount_type_str, display_name, + base::PLATFORM_FILE_OK, source_path); + } +#else + SendResponse(true); #endif // defined(OS_CHROMEOS) +} +void AddMountFunction::OnMountedStateSet(const std::string& mount_type, + const FilePath::StringType& file_name, + base::PlatformFileError error, + const FilePath& file_path) { +#if defined(OS_CHROMEOS) + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); + // MountPath() takes a std::string. + disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), + FilePath(file_name).Extension(), + DiskMountManager::MountTypeFromString( + mount_type)); SendResponse(true); +#endif // defined(OS_CHROMEOS) } RemoveMountFunction::RemoveMountFunction() { diff --git a/chrome/browser/chromeos/extensions/file_browser_private_api.h b/chrome/browser/chromeos/extensions/file_browser_private_api.h index e6ef63b..111dc00a 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_api.h +++ b/chrome/browser/chromeos/extensions/file_browser_private_api.h @@ -246,6 +246,11 @@ class AddMountFunction // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, const SelectedFileInfoList& files); + // A callback method to handle the result of SetMountedState. + void OnMountedStateSet(const std::string& mount_type, + const FilePath::StringType& file_name, + base::PlatformFileError error, + const FilePath& file_path); DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.addMount"); }; diff --git a/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc b/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc index 9a5b606..9237c5b 100644 --- a/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc +++ b/chrome/browser/chromeos/extensions/file_browser_private_apitest.cc @@ -221,7 +221,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionFileBrowserPrivateApiTest, FileBrowserMount) { EXPECT_CALL(*disk_mount_manager_mock_, UnmountPath(_)) .Times(0); EXPECT_CALL(*disk_mount_manager_mock_, - UnmountPath(StrEq("/tmp/test_file.zip"))).Times(1); + UnmountPath(StrEq("/media/archive/archive_mount_path"))).Times(1); EXPECT_CALL(*disk_mount_manager_mock_, disks()) .WillRepeatedly(ReturnRef(volumes_)); diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index ee31365..c89a56e 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -2645,13 +2645,16 @@ FileManager.prototype = { } chrome.mediaPlayerPrivate.play(urls, position); } else if (id == 'mount-archive') { - for (var index = 0; index < urls.length; ++index) { - // Url in MountCompleted event won't be escaped, so let's make sure - // we don't use escaped one in mountRequests_. - var unescapedUrl = unescape(urls[index]); - this.mountRequests_.push(unescapedUrl); - chrome.fileBrowserPrivate.addMount(unescapedUrl, 'file', {}); - } + var self = this; + this.resolveSelectResults_(urls, function(urls) { + for (var index = 0; index < urls.length; ++index) { + // Url in MountCompleted event won't be escaped, so let's make sure + // we don't use escaped one in mountRequests_. + var unescapedUrl = unescape(urls[index]); + self.mountRequests_.push(unescapedUrl); + chrome.fileBrowserPrivate.addMount(unescapedUrl, 'file', {}); + } + }); } else if (id == 'format-device') { this.confirm.show(str('FORMATTING_WARNING'), function() { chrome.fileBrowserPrivate.formatDevice(urls[0]); diff --git a/chrome/test/data/extensions/api_test/filebrowser_mount/test.js b/chrome/test/data/extensions/api_test/filebrowser_mount/test.js index a2dfb66..a35a812 100644 --- a/chrome/test/data/extensions/api_test/filebrowser_mount/test.js +++ b/chrome/test/data/extensions/api_test/filebrowser_mount/test.js @@ -11,7 +11,7 @@ var expectedVolume1 = { deviceLabel: 'device_label1', driveLabel: 'drive_label1', deviceType: 'usb', - totalSize: 1073741824, + totalSize: 1073741824, isParent: false, isReadOnly: false, hasMedia: false, @@ -26,7 +26,7 @@ var expectedVolume2 = { deviceLabel: 'device_label2', driveLabel: 'drive_label2', deviceType: 'mobile', - totalSize: 47723, + totalSize: 47723, isParent: true, isReadOnly: true, hasMedia: true, @@ -41,7 +41,7 @@ var expectedVolume3 = { deviceLabel: 'device_label3', driveLabel: 'drive_label3', deviceType: 'optical', - totalSize: 0, + totalSize: 0, isParent: true, isReadOnly: false, hasMedia: false, @@ -92,7 +92,7 @@ function treatMountPointException(received, expected, key) { expectedSourceUrl + "' but got '" + received['sourceUrl'] + "' instead."); return { wasValidated: true, success: success }; -}; +} function validateObject(received, expected, name, treatException) { for (var key in expected) { @@ -113,23 +113,23 @@ function validateObject(received, expected, name, treatException) { } } if (Object.keys(expected).length != Object.keys(received).length) { - console.warn("Unexpected property found in returned volume"); + console.warn('Unexpected property found in returned volume'); return false; } return true; -}; +} function createFileUrl(fileName) { - var testExtensionId = "ddammdhioacbehjngdmkjcjbnfginlla"; - var fileUrl = "filesystem:chrome-extension://" + testExtensionId + - "/external/" + fileName; + var testExtensionId = 'ddammdhioacbehjngdmkjcjbnfginlla'; + var fileUrl = 'filesystem:chrome-extension://' + testExtensionId + + '/external/' + fileName; return fileUrl; -}; +} chrome.test.runTests([ function removeMount() { // The ID of this extension. - var fileUrl = createFileUrl("tmp/test_file.zip"); + var fileUrl = createFileUrl('archive/archive_mount_path'); chrome.fileBrowserPrivate.removeMount(fileUrl); @@ -144,7 +144,7 @@ chrome.test.runTests([ chrome.test.callbackPass(function(result) { chrome.test.assertTrue( validateObject(result, expectedVolume1, 'volume'), - "getVolumeMetadata result for first volume not as expected"); + 'getVolumeMetadata result for first volume not as expected'); })); }, @@ -154,7 +154,7 @@ chrome.test.runTests([ chrome.test.callbackPass(function(result) { chrome.test.assertTrue( validateObject(result, expectedVolume2, 'volume'), - "getVolumeMetadata result for second volume not as expected"); + 'getVolumeMetadata result for second volume not as expected'); })); }, @@ -164,13 +164,13 @@ chrome.test.runTests([ chrome.test.callbackPass(function(result) { chrome.test.assertTrue( validateObject(result, expectedVolume3, 'volume'), - "getVolumeMetadata result for third volume not as expected"); + 'getVolumeMetadata result for third volume not as expected'); })); }, function getVolumeMetadataNonExistentPath() { chrome.fileBrowserPrivate.getVolumeMetadata( - createFileUrl("removable/non_existent_device_path"), + createFileUrl('removable/non_existent_device_path'), chrome.test.callbackPass(function(result) { chrome.test.assertEq(undefined, result); })); @@ -179,7 +179,7 @@ chrome.test.runTests([ function getVolumeMetadataArchive() { chrome.fileBrowserPrivate.getVolumeMetadata( - createFileUrl("archive/archive_mount_path"), + createFileUrl('archive/archive_mount_path'), chrome.test.callbackPass(function(result) { chrome.test.assertEq(undefined, result); })); @@ -187,8 +187,8 @@ chrome.test.runTests([ function getVolumeMetadataInvalidPath() { chrome.fileBrowserPrivate.getVolumeMetadata( - "some path", - chrome.test.callbackFail("Invalid mount path.")); + 'some path', + chrome.test.callbackFail('Invalid mount path.')); }, function getMountPointsTest() { @@ -200,7 +200,7 @@ chrome.test.runTests([ chrome.test.assertTrue( validateObject(result[i], expectedMountPoints[i], 'mountPoint', treatMountPointException), - 'getMountPoints result[' + i +'] not as expected'); + 'getMountPoints result[' + i + '] not as expected'); } })); } diff --git a/chromeos/dbus/cros_disks_client.cc b/chromeos/dbus/cros_disks_client.cc index 441b7fe..b9c420f 100644 --- a/chromeos/dbus/cros_disks_client.cc +++ b/chromeos/dbus/cros_disks_client.cc @@ -113,6 +113,7 @@ class CrosDisksClientImpl : public CrosDisksClient { // CrosDisksClient override. virtual void Mount(const std::string& source_path, + const std::string& source_format, MountType type, const MountCallback& callback, const ErrorCallback& error_callback) OVERRIDE { @@ -120,7 +121,7 @@ class CrosDisksClientImpl : public CrosDisksClient { cros_disks::kMount); dbus::MessageWriter writer(&method_call); writer.AppendString(source_path); - writer.AppendString(""); // auto detect filesystem. + writer.AppendString(source_format); std::vector<std::string> mount_options(kDefaultMountOptions, kDefaultMountOptions + arraysize(kDefaultMountOptions)); @@ -375,6 +376,7 @@ class CrosDisksClientStubImpl : public CrosDisksClient { virtual ~CrosDisksClientStubImpl() {} virtual void Mount(const std::string& source_path, + const std::string& source_format, MountType type, const MountCallback& callback, const ErrorCallback& error_callback) OVERRIDE {} diff --git a/chromeos/dbus/cros_disks_client.h b/chromeos/dbus/cros_disks_client.h index 88e6aee..a4ea8c4 100644 --- a/chromeos/dbus/cros_disks_client.h +++ b/chromeos/dbus/cros_disks_client.h @@ -178,7 +178,11 @@ class CHROMEOS_EXPORT CrosDisksClient { // Calls Mount method. |callback| is called after the method call succeeds, // otherwise, |error_callback| is called. + // When mounting an archive, the |source_format| argument passes the file + // extension (with the leading dot, for example ".zip"). If |source_format| is + // empty then the source format is auto-detected. virtual void Mount(const std::string& source_path, + const std::string& source_format, MountType type, const MountCallback& callback, const ErrorCallback& error_callback) = 0; diff --git a/chromeos/dbus/mock_cros_disks_client.h b/chromeos/dbus/mock_cros_disks_client.h index b258935..101b80f 100644 --- a/chromeos/dbus/mock_cros_disks_client.h +++ b/chromeos/dbus/mock_cros_disks_client.h @@ -18,7 +18,8 @@ class MockCrosDisksClient : public CrosDisksClient { MockCrosDisksClient(); virtual ~MockCrosDisksClient(); - MOCK_METHOD4(Mount, void(const std::string&, + MOCK_METHOD5(Mount, void(const std::string&, + const std::string&, MountType, const MountCallback&, const ErrorCallback&)); |