Commit 7291c487 authored by tbarzic@chromium.org's avatar tbarzic@chromium.org

Revert 94812 - Formatting feature initial commit for ChromeOS Tree

Reverting to make merging next patch into M14 easier.

Added formatting API for browser extension as well as event routing. 
Created a complete UI for formatting.

This code depends on the following changes to libcros:
http://gerrit.chromium.org/gerrit/#change,4446

BUG=chromium-os:4541, chromium-os:17071
TEST=Try to format removable media.


Review URL: http://codereview.chromium.org/7471024

TBR=sidor@chromium.org
Review URL: http://codereview.chromium.org/7599015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95909 0039d316-1c4b-4281-b951-d872f2087c98
parent 1339dd16
...@@ -9040,10 +9040,6 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -9040,10 +9040,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
Are you sure you want to delete $1 items? Are you sure you want to delete $1 items?
</message> </message>
<message name="IDS_FILE_BROWSER_FORMATTING_WARNING" desc="Displayed when you attempt to format device.">
Formatting the removable media is going to erase all data. Do you wish to continue?
</message>
<message name="IDS_FILE_BROWSER_SELECT_FOLDER_TITLE" desc="Select folder title."> <message name="IDS_FILE_BROWSER_SELECT_FOLDER_TITLE" desc="Select folder title.">
Select a folder to open Select a folder to open
</message> </message>
...@@ -12287,26 +12283,6 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -12287,26 +12283,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
Scanning content... Scanning content...
</message> </message>
<!-- Formatting device notifications -->
<message name="IDS_FORMATTING_OF_DEVICE_PENDING_TITLE" desc="Text of notification message which is shown when formatting process of some device is pending">
Formatting pending
</message>
<message name="IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE" desc="Text of notification message which is shown when formatting process finshes">
Formatting finished
</message>
<message name="IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE" desc="Text of notification message which is shown when formatting process of some device is pending">
The formatting process can take a couple of seconds. Please wait.
</message>
<message name="IDS_FORMATTING_STARTED_FAILURE_MESSAGE" desc="Text of notification message which is shown when formatting process can not be started.">
Could not start the formatting process.
</message>
<message name="IDS_FORMATTING_FINISHED_SUCCESS_MESSAGE" desc="Text of notification message which is shown when formatting finishes without any errors.">
Formatting finished successfully!
</message>
<message name="IDS_FORMATTING_FINISHED_FAILURE_MESSAGE" desc="Text of notification message which is shown when there are some errors while formatting.">
Aw, Snap! There've been some errors while formatting...
</message>
<!-- Network state strings for ChromeOS --> <!-- Network state strings for ChromeOS -->
<message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN"> <message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN">
Unknown Unknown
......
...@@ -132,10 +132,6 @@ void MockMountLibrary::SetupDefaultReplies() { ...@@ -132,10 +132,6 @@ void MockMountLibrary::SetupDefaultReplies() {
.Times(AnyNumber()); .Times(AnyNumber());
EXPECT_CALL(*this, UnmountPath(_)) EXPECT_CALL(*this, UnmountPath(_))
.Times(AnyNumber()); .Times(AnyNumber());
EXPECT_CALL(*this, FormatUnmountedDevice(_))
.Times(AnyNumber());
EXPECT_CALL(*this, FormatMountedDevice(_))
.Times(AnyNumber());
EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _)) EXPECT_CALL(*this, UnmountDeviceRecursive(_, _, _))
.Times(AnyNumber()); .Times(AnyNumber());
} }
......
...@@ -31,8 +31,6 @@ class MockMountLibrary : public MountLibrary { ...@@ -31,8 +31,6 @@ class MockMountLibrary : public MountLibrary {
MOCK_METHOD3(MountPath, void(const char*, MountType, MOCK_METHOD3(MountPath, void(const char*, MountType,
const MountPathOptions&)); const MountPathOptions&));
MOCK_METHOD1(UnmountPath, void(const char*)); MOCK_METHOD1(UnmountPath, void(const char*));
MOCK_METHOD1(FormatUnmountedDevice, void(const char*));
MOCK_METHOD1(FormatMountedDevice, void(const char*));
MOCK_METHOD3(UnmountDeviceRecursive, void(const char*, MOCK_METHOD3(UnmountDeviceRecursive, void(const char*,
MountLibrary::UnmountDeviceRecursiveCallbackType, void*)); MountLibrary::UnmountDeviceRecursiveCallbackType, void*));
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/cros/mount_library.h" #include "chrome/browser/chromeos/cros/mount_library.h"
#include <set> #include <set>
#include <vector>
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -145,62 +144,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -145,62 +144,6 @@ class MountLibraryImpl : public MountLibrary {
UnmountMountPoint(path, &MountLibraryImpl::UnmountMountPointCallback, this); UnmountMountPoint(path, &MountLibraryImpl::UnmountMountPointCallback, this);
} }
virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!CrosLibrary::Get()->EnsureLoaded()) {
OnFormatDevice(file_path,
false,
MOUNT_METHOD_ERROR_LOCAL,
kLibraryNotLoaded);
return;
}
for (MountLibrary::DiskMap::iterator it = disks_.begin();
it != disks_.end(); ++it) {
if (it->second->file_path().compare(file_path) == 0 &&
!it->second->mount_path().empty()) {
OnFormatDevice(file_path,
false,
MOUNT_METHOD_ERROR_LOCAL,
"Device is still mounted.");
return;
}
}
FormatDevice(file_path,
"vfat", // currently format in vfat by default
&MountLibraryImpl::FormatDeviceCallback,
this);
}
virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {
DCHECK(mount_path);
std::string device_path, file_path;
for (MountLibrary::DiskMap::iterator it = disks_.begin();
it != disks_.end(); ++it) {
if (it->second->mount_path().compare(mount_path) == 0) {
device_path = it->second->device_path();
file_path = it->second->file_path();
break;
}
}
if (device_path.empty()) {
OnFormatDevice(device_path.c_str(),
false,
MOUNT_METHOD_ERROR_LOCAL,
"Device with this mount path not found.");
return;
}
if (formatting_pending_.find(device_path) != formatting_pending_.end()) {
OnFormatDevice(device_path.c_str(),
false,
MOUNT_METHOD_ERROR_LOCAL,
"Formatting is already pending.");
return;
}
// Formatting process continues, after unmounting.
formatting_pending_[device_path] = file_path;
UnmountPath(device_path.c_str());
}
virtual void UnmountDeviceRecursive(const char* device_path, virtual void UnmountDeviceRecursive(const char* device_path,
UnmountDeviceRecursiveCallbackType callback, void* user_data) UnmountDeviceRecursiveCallbackType callback, void* user_data)
OVERRIDE { OVERRIDE {
...@@ -288,17 +231,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -288,17 +231,6 @@ class MountLibraryImpl : public MountLibrary {
self->OnUnmountPath(device_path, error, error_message); self->OnUnmountPath(device_path, error, error_message);
} }
// Callback for FormatRemovableDevice method.
static void FormatDeviceCallback(void* object,
const char* device_path,
bool success,
MountMethodErrorType error,
const char* error_message) {
DCHECK(object);
MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
self->OnFormatDevice(device_path, success, error, error_message);
}
// Callback for UnmountDeviceRecursive. // Callback for UnmountDeviceRecursive.
static void UnmountDeviceRecursiveCallback(void* object, static void UnmountDeviceRecursiveCallback(void* object,
const char* device_path, const char* device_path,
...@@ -426,13 +358,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -426,13 +358,6 @@ class MountLibraryImpl : public MountLibrary {
DCHECK(disk); DCHECK(disk);
disk->clear_mount_path(); disk->clear_mount_path();
FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk); FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk);
// Check if there is a formatting scheduled
PathMap::iterator it = formatting_pending_.find(source_path);
if (it != formatting_pending_.end()) {
const std::string file_path = it->second;
formatting_pending_.erase(it);
FormatUnmountedDevice(file_path.c_str());
}
} else { } else {
LOG(WARNING) << "Unmount request failed for device " LOG(WARNING) << "Unmount request failed for device "
<< source_path << ", with error: " << source_path << ", with error: "
...@@ -440,24 +365,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -440,24 +365,6 @@ class MountLibraryImpl : public MountLibrary {
} }
} }
void OnFormatDevice(const char* device_path,
bool success,
MountMethodErrorType error,
const char* error_message) {
DCHECK(device_path);
if (error == MOUNT_METHOD_ERROR_NONE && device_path && success) {
FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path);
} else {
FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED,
std::string("!") + device_path);
LOG(WARNING) << "Format request failed for device "
<< device_path << ", with error: "
<< (error_message ? error_message : "Unknown");
}
}
void OnGetDiskProperties(const char* device_path, void OnGetDiskProperties(const char* device_path,
const DiskInfo* disk1, const DiskInfo* disk1,
MountMethodErrorType error, MountMethodErrorType error,
...@@ -613,10 +520,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -613,10 +520,6 @@ class MountLibraryImpl : public MountLibrary {
type = MOUNT_DEVICE_SCANNED; type = MOUNT_DEVICE_SCANNED;
break; break;
} }
case FORMATTING_FINISHED: {
type = MOUNT_FORMATTING_FINISHED;
break;
}
default: { default: {
return; return;
} }
...@@ -668,10 +571,6 @@ class MountLibraryImpl : public MountLibrary { ...@@ -668,10 +571,6 @@ class MountLibraryImpl : public MountLibrary {
MountLibrary::DiskMap disks_; MountLibrary::DiskMap disks_;
MountLibrary::MountPointMap mount_points_; MountLibrary::MountPointMap mount_points_;
// Set of devices that are supposed to be formated, but are currently waiting
// to be unmounted. When device is in this map, the formatting process HAVEN'T
// started yet.
PathMap formatting_pending_;
DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
}; };
...@@ -692,8 +591,6 @@ class MountLibraryStubImpl : public MountLibrary { ...@@ -692,8 +591,6 @@ class MountLibraryStubImpl : public MountLibrary {
virtual void MountPath(const char* source_path, MountType type, virtual void MountPath(const char* source_path, MountType type,
const MountPathOptions& options) OVERRIDE {} const MountPathOptions& options) OVERRIDE {}
virtual void UnmountPath(const char* path) OVERRIDE {} virtual void UnmountPath(const char* path) OVERRIDE {}
virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
virtual void UnmountDeviceRecursive(const char* device_path, virtual void UnmountDeviceRecursive(const char* device_path,
UnmountDeviceRecursiveCallbackType callback, void* user_data) UnmountDeviceRecursiveCallbackType callback, void* user_data)
OVERRIDE {} OVERRIDE {}
......
...@@ -24,9 +24,7 @@ typedef enum MountLibraryEventType { ...@@ -24,9 +24,7 @@ typedef enum MountLibraryEventType {
MOUNT_DISK_UNMOUNTED, MOUNT_DISK_UNMOUNTED,
MOUNT_DEVICE_ADDED, MOUNT_DEVICE_ADDED,
MOUNT_DEVICE_REMOVED, MOUNT_DEVICE_REMOVED,
MOUNT_DEVICE_SCANNED, MOUNT_DEVICE_SCANNED
MOUNT_FORMATTING_STARTED,
MOUNT_FORMATTING_FINISHED
} MountLibraryEventType; } MountLibraryEventType;
// This class handles the interaction with the ChromeOS mount library APIs. // This class handles the interaction with the ChromeOS mount library APIs.
...@@ -102,7 +100,6 @@ class MountLibrary { ...@@ -102,7 +100,6 @@ class MountLibrary {
bool on_boot_device_; bool on_boot_device_;
}; };
typedef std::map<std::string, Disk*> DiskMap; typedef std::map<std::string, Disk*> DiskMap;
typedef std::map<std::string, std::string> PathMap;
// MountPointInfo: {mount_path, mount_type}. // MountPointInfo: {mount_path, mount_type}.
struct MountPointInfo { struct MountPointInfo {
...@@ -148,14 +145,6 @@ class MountLibrary { ...@@ -148,14 +145,6 @@ class MountLibrary {
// |path| may be source od mount path. // |path| may be source od mount path.
virtual void UnmountPath(const char* path) = 0; virtual void UnmountPath(const char* path) = 0;
// Formats device given its file path.
// Example: file_path: /dev/sdb1
virtual void FormatUnmountedDevice(const char* file_path) = 0;
// Formats Device given its mount path. Unmount's the device
// Example: mount_path: /media/VOLUME_LABEL
virtual void FormatMountedDevice(const char* mount_path) = 0;
// Unmounts device_poath and all of its known children. // Unmounts device_poath and all of its known children.
virtual void UnmountDeviceRecursive(const char* device_path, virtual void UnmountDeviceRecursive(const char* device_path,
UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0;
......
...@@ -27,11 +27,6 @@ class SystemNotification; ...@@ -27,11 +27,6 @@ class SystemNotification;
// found. // found.
class ExtensionFileBrowserEventRouter class ExtensionFileBrowserEventRouter
: public chromeos::MountLibrary::Observer { : public chromeos::MountLibrary::Observer {
friend void HideFileBrowserNotificationExternally(
const std::string& category, const std::string& system_path,
ExtensionFileBrowserEventRouter* that);
public: public:
explicit ExtensionFileBrowserEventRouter(Profile* profile); explicit ExtensionFileBrowserEventRouter(Profile* profile);
virtual ~ExtensionFileBrowserEventRouter(); virtual ~ExtensionFileBrowserEventRouter();
...@@ -61,8 +56,7 @@ class ExtensionFileBrowserEventRouter ...@@ -61,8 +56,7 @@ class ExtensionFileBrowserEventRouter
NotificationMap; NotificationMap;
typedef std::map<std::string, std::string> MountPointMap; typedef std::map<std::string, std::string> MountPointMap;
typedef struct FileWatcherExtensions { typedef struct FileWatcherExtensions {
FileWatcherExtensions(const FilePath& path, FileWatcherExtensions(const FilePath& path, const std::string& extension_id) {
const std::string& extension_id) {
file_watcher.reset(new base::files::FilePathWatcher()); file_watcher.reset(new base::files::FilePathWatcher());
virtual_path = path; virtual_path = path;
extensions.insert(extension_id); extensions.insert(extension_id);
...@@ -94,17 +88,13 @@ class ExtensionFileBrowserEventRouter ...@@ -94,17 +88,13 @@ class ExtensionFileBrowserEventRouter
void OnDiskAdded(const chromeos::MountLibrary::Disk* disk); void OnDiskAdded(const chromeos::MountLibrary::Disk* disk);
void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk); void OnDiskRemoved(const chromeos::MountLibrary::Disk* disk);
void OnDiskChanged(const chromeos::MountLibrary::Disk* disk); void OnDiskChanged(const chromeos::MountLibrary::Disk* disk);
void OnDiskMounted(const chromeos::MountLibrary::Disk* disk);
void OnDiskUnmounted(const chromeos::MountLibrary::Disk* disk);
void OnDeviceAdded(const std::string& device_path); void OnDeviceAdded(const std::string& device_path);
void OnDeviceRemoved(const std::string& device_path); void OnDeviceRemoved(const std::string& device_path);
void OnDeviceScanned(const std::string& device_path); void OnDeviceScanned(const std::string& device_path);
void OnFormattingStarted(const std::string& device_path);
void OnFormattingFinished(const std::string& device_path);
// Finds first notifications corresponding to the same device. Ensures that // Finds first notifications corresponding to the same device. Ensures that
// we don't pop up multiple notifications for the same device. // we don't pop up multiple notifications for the same device.
NotificationMap::iterator FindNotificationForId(const std::string& path); NotificationMap::iterator FindNotificationForPath(const std::string& path);
// Process file watch notifications. // Process file watch notifications.
void HandleFileWatchNotification(const FilePath& path, void HandleFileWatchNotification(const FilePath& path,
...@@ -130,13 +120,10 @@ class ExtensionFileBrowserEventRouter ...@@ -130,13 +120,10 @@ class ExtensionFileBrowserEventRouter
bool small); bool small);
// Show/hide desktop notifications. // Show/hide desktop notifications.
void ShowFileBrowserNotification(const std::string& category, void ShowDeviceNotification(const std::string& system_path,
const std::string& system_path,
int icon_resource_id, int icon_resource_id,
const string16& title,
const string16& message); const string16& message);
void HideFileBrowserNotification(const std::string& category, void HideDeviceNotification(const std::string& system_path);
const std::string& system_path);
scoped_refptr<FileWatcherDelegate> delegate_; scoped_refptr<FileWatcherDelegate> delegate_;
MountPointMap mounted_devices_; MountPointMap mounted_devices_;
......
...@@ -1244,7 +1244,6 @@ void RemoveMountFunction::GetLocalPathsResponseOnUIThread( ...@@ -1244,7 +1244,6 @@ void RemoveMountFunction::GetLocalPathsResponseOnUIThread(
SendResponse(true); SendResponse(true);
} }
GetMountPointsFunction::GetMountPointsFunction() { GetMountPointsFunction::GetMountPointsFunction() {
} }
...@@ -1258,7 +1257,7 @@ bool GetMountPointsFunction::RunImpl() { ...@@ -1258,7 +1257,7 @@ bool GetMountPointsFunction::RunImpl() {
base::ListValue *mounts = new base::ListValue(); base::ListValue *mounts = new base::ListValue();
result_.reset(mounts); result_.reset(mounts);
#ifdef OS_CHROMEOS #ifdef OS_CHROMEOS
chromeos::MountLibrary *mount_lib = chromeos::MountLibrary *mount_lib =
chromeos::CrosLibrary::Get()->GetMountLibrary(); chromeos::CrosLibrary::Get()->GetMountLibrary();
chromeos::MountLibrary::MountPointMap mount_points = chromeos::MountLibrary::MountPointMap mount_points =
...@@ -1271,33 +1270,6 @@ bool GetMountPointsFunction::RunImpl() { ...@@ -1271,33 +1270,6 @@ bool GetMountPointsFunction::RunImpl() {
mounts->Append(MountPointToValue(profile_, it->second)); mounts->Append(MountPointToValue(profile_, it->second));
} }
#endif #endif
SendResponse(true);
return true;
}
FormatDeviceFunction::FormatDeviceFunction() {
}
FormatDeviceFunction::~FormatDeviceFunction() {
}
bool FormatDeviceFunction::RunImpl() {
if (args_->GetSize() != 1) {
return false;
}
std::string volume_mount_path;
if (!args_->GetString(0, &volume_mount_path)) {
NOTREACHED();
return false;
}
#ifdef OS_CHROMEOS
chromeos::CrosLibrary::Get()->GetMountLibrary()->FormatMountedDevice(
volume_mount_path.c_str());
#endif
SendResponse(true); SendResponse(true);
return true; return true;
} }
...@@ -1453,8 +1425,6 @@ bool FileDialogStringsFunction::RunImpl() { ...@@ -1453,8 +1425,6 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, CONFIRM_DELETE_ONE); SET_STRING(IDS_FILE_BROWSER, CONFIRM_DELETE_ONE);
SET_STRING(IDS_FILE_BROWSER, CONFIRM_DELETE_SOME); SET_STRING(IDS_FILE_BROWSER, CONFIRM_DELETE_SOME);
SET_STRING(IDS_FILE_BROWSER, FORMATTING_WARNING);
SET_STRING(IDS_FILE_BROWSER, SELECT_FOLDER_TITLE); SET_STRING(IDS_FILE_BROWSER, SELECT_FOLDER_TITLE);
SET_STRING(IDS_FILE_BROWSER, SELECT_OPEN_FILE_TITLE); SET_STRING(IDS_FILE_BROWSER, SELECT_OPEN_FILE_TITLE);
SET_STRING(IDS_FILE_BROWSER, SELECT_OPEN_MULTI_FILE_TITLE); SET_STRING(IDS_FILE_BROWSER, SELECT_OPEN_MULTI_FILE_TITLE);
......
...@@ -277,21 +277,6 @@ class GetMountPointsFunction ...@@ -277,21 +277,6 @@ class GetMountPointsFunction
DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints"); DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.getMountPoints");
}; };
// Formats Device given its mount path.
class FormatDeviceFunction
: public SyncExtensionFunction {
public:
FormatDeviceFunction();
protected:
virtual ~FormatDeviceFunction();
virtual bool RunImpl() OVERRIDE;
private:
DECLARE_EXTENSION_FUNCTION_NAME("fileBrowserPrivate.formatDevice");
};
// Retrieves devices meta-data. Expects volume's device path as an argument. // Retrieves devices meta-data. Expects volume's device path as an argument.
class GetVolumeMetadataFunction class GetVolumeMetadataFunction
: public SyncExtensionFunction { : public SyncExtensionFunction {
......
...@@ -368,7 +368,6 @@ void FactoryRegistry::ResetFunctions() { ...@@ -368,7 +368,6 @@ void FactoryRegistry::ResetFunctions() {
RegisterFunction<AddMountFunction>(); RegisterFunction<AddMountFunction>();
RegisterFunction<RemoveMountFunction>(); RegisterFunction<RemoveMountFunction>();
RegisterFunction<GetMountPointsFunction>(); RegisterFunction<GetMountPointsFunction>();
RegisterFunction<FormatDeviceFunction>();
RegisterFunction<ViewFilesFunction>(); RegisterFunction<ViewFilesFunction>();
// Mediaplayer // Mediaplayer
......
...@@ -6365,17 +6365,6 @@ ...@@ -6365,17 +6365,6 @@
] ]
} }
] ]
},
{
"name": "formatDevice",
"description": "Formats a mounted device",
"parameters": [
{
"name": "mountPath",
"type": "string",
"description": "Device's mount path."
}
]
} }
], ],
"events": [ "events": [
......
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