Commit 52f15a75 authored by Omid Tourzan's avatar Omid Tourzan Committed by Commit Bot

[partition-as-single] Add SinglePartitionFormat to private api.


Bug: 491043
Change-Id: Ib87a5acf508ad25cbd5a84e584c75cb5df0d5c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422102Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarAustin Tankiang <austinct@chromium.org>
Commit-Queue: Omid Tourzan <oto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812567}
parent a510cd7f
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "chrome/common/extensions/api/file_manager_private.h" #include "chrome/common/extensions/api/file_manager_private.h"
#include "chrome/common/extensions/api/file_manager_private_internal.h" #include "chrome/common/extensions/api/file_manager_private_internal.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/disks/disk.h"
#include "chromeos/disks/disk_mount_manager.h" #include "chromeos/disks/disk_mount_manager.h"
#include "components/drive/event_logger.h" #include "components/drive/event_logger.h"
#include "components/drive/file_system_core_util.h" #include "components/drive/file_system_core_util.h"
...@@ -700,6 +701,44 @@ FileManagerPrivateFormatVolumeFunction::Run() { ...@@ -700,6 +701,44 @@ FileManagerPrivateFormatVolumeFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
ExtensionFunction::ResponseAction
FileManagerPrivateSinglePartitionFormatFunction::Run() {
using extensions::api::file_manager_private::SinglePartitionFormat::Params;
const std::unique_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
const ChromeExtensionFunctionDetails chrome_details(this);
const DiskMountManager::DiskMap& disks =
DiskMountManager::GetInstance()->disks();
chromeos::disks::Disk* device_disk;
DiskMountManager::DiskMap::const_iterator it;
for (it = disks.begin(); it != disks.end(); ++it) {
if (it->second->storage_device_path() == params->device_storage_path &&
it->second->is_parent()) {
device_disk = it->second.get();
break;
}
}
if (it == disks.end()) {
return RespondNow(Error("Device not found"));
}
if (!device_disk->on_removable_device() || device_disk->on_boot_device() ||
device_disk->is_read_only()) {
return RespondNow(Error("Invalid device"));
}
DiskMountManager::GetInstance()->SinglePartitionFormatDevice(
device_disk->device_path(),
ApiFormatFileSystemToChromeEnum(params->filesystem),
params->volume_label);
return RespondNow(NoArguments());
}
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
FileManagerPrivateRenameVolumeFunction::Run() { FileManagerPrivateRenameVolumeFunction::Run() {
using extensions::api::file_manager_private::RenameVolume::Params; using extensions::api::file_manager_private::RenameVolume::Params;
......
...@@ -229,6 +229,21 @@ class FileManagerPrivateFormatVolumeFunction : public LoggedExtensionFunction { ...@@ -229,6 +229,21 @@ class FileManagerPrivateFormatVolumeFunction : public LoggedExtensionFunction {
ResponseAction Run() override; ResponseAction Run() override;
}; };
// Implements the chrome.fileManagerPrivate.singlePartitionFormat method.
// Deletes removable device partitions, create a single partition and format.
class FileManagerPrivateSinglePartitionFormatFunction
: public LoggedExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.singlePartitionFormat",
FILEMANAGERPRIVATE_SINGLEPARTITIONFORMAT)
protected:
~FileManagerPrivateSinglePartitionFormatFunction() override = default;
// ExtensionFunction overrides.
ResponseAction Run() override;
};
// Implements the chrome.fileManagerPrivate.renameVolume method. // Implements the chrome.fileManagerPrivate.renameVolume method.
// Renames Volume given its mount path and new Volume name. // Renames Volume given its mount path and new Volume name.
class FileManagerPrivateRenameVolumeFunction : public LoggedExtensionFunction { class FileManagerPrivateRenameVolumeFunction : public LoggedExtensionFunction {
......
...@@ -1117,6 +1117,15 @@ interface Functions { ...@@ -1117,6 +1117,15 @@ interface Functions {
FormatFileSystemType filesystem, FormatFileSystemType filesystem,
DOMString volumeLabel); DOMString volumeLabel);
// Deletes partitions of removable device, creates a new partition and format
// it.
// |deviceStoragePath| Storage path of the device to be formatted.
// |filesystem| Filesystem type to be formatted to.
// |volumeLabel| Label of the drive after formatting.
static void singlePartitionFormat(DOMString deviceStoragePath,
FormatFileSystemType filesystem,
DOMString volumeLabel);
// Renames a mounted volume. // Renames a mounted volume.
// |volumeId| ID of the volume to be renamed. // |volumeId| ID of the volume to be renamed.
// |newName| New name of the target volume. // |newName| New name of the target volume.
......
...@@ -1571,6 +1571,7 @@ enum HistogramValue { ...@@ -1571,6 +1571,7 @@ enum HistogramValue {
DECLARATIVENETREQUEST_ISREGEXSUPPORTED = 1508, DECLARATIVENETREQUEST_ISREGEXSUPPORTED = 1508,
PASSWORDSPRIVATE_GETWEAKCREDENTIALS = 1509, PASSWORDSPRIVATE_GETWEAKCREDENTIALS = 1509,
ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT = 1510, ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT = 1510,
FILEMANAGERPRIVATE_SINGLEPARTITIONFORMAT = 1511,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -824,6 +824,16 @@ chrome.fileManagerPrivate.getSizeStats = function(volumeId, callback) {}; ...@@ -824,6 +824,16 @@ chrome.fileManagerPrivate.getSizeStats = function(volumeId, callback) {};
chrome.fileManagerPrivate.formatVolume = function(volumeId, filesystem, chrome.fileManagerPrivate.formatVolume = function(volumeId, filesystem,
volumeLabel) {}; volumeLabel) {};
/**
* Deletes partitions of removable device, creates a single partition
* and format it.
* @param {string} devicePath
* @param {chrome.fileManagerPrivate.FormatFileSystemType} filesystem
* @param {string} volumeLabel
*/
chrome.fileManagerPrivate.singlePartitionFormat = function(devicePath,
filesystem, volumeLabel) {};
/** /**
* Renames a mounted volume. |volumeId| ID of the volume to be renamed to * Renames a mounted volume. |volumeId| ID of the volume to be renamed to
* |newName|. * |newName|.
......
...@@ -24667,6 +24667,7 @@ Called by update_extension_histograms.py.--> ...@@ -24667,6 +24667,7 @@ Called by update_extension_histograms.py.-->
<int value="1508" label="DECLARATIVENETREQUEST_ISREGEXSUPPORTED"/> <int value="1508" label="DECLARATIVENETREQUEST_ISREGEXSUPPORTED"/>
<int value="1509" label="PASSWORDSPRIVATE_GETWEAKCREDENTIALS"/> <int value="1509" label="PASSWORDSPRIVATE_GETWEAKCREDENTIALS"/>
<int value="1510" label="ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT"/> <int value="1510" label="ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT"/>
<int value="1511" label="FILEMANAGERPRIVATE_SINGLEPARTITIONFORMAT"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
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