Skip to content

Commit

Permalink
[partition-as-single] Add SinglePartitionFormat to private api.
Browse files Browse the repository at this point in the history
Bug: 491043
Change-Id: Ib87a5acf508ad25cbd5a84e584c75cb5df0d5c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422102
Reviewed-by: Ben Wells <benwells@chromium.org>
Reviewed-by: Austin Tankiang <austinct@chromium.org>
Commit-Queue: Omid Tourzan <oto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812567}
  • Loading branch information
Omid Tourzan authored and Commit Bot committed Oct 1, 2020
1 parent a510cd7 commit 52f15a7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "chrome/common/extensions/api/file_manager_private.h"
#include "chrome/common/extensions/api/file_manager_private_internal.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/disks/disk.h"
#include "chromeos/disks/disk_mount_manager.h"
#include "components/drive/event_logger.h"
#include "components/drive/file_system_core_util.h"
Expand Down Expand Up @@ -700,6 +701,44 @@ FileManagerPrivateFormatVolumeFunction::Run() {
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
FileManagerPrivateRenameVolumeFunction::Run() {
using extensions::api::file_manager_private::RenameVolume::Params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ class FileManagerPrivateFormatVolumeFunction : public LoggedExtensionFunction {
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.
// Renames Volume given its mount path and new Volume name.
class FileManagerPrivateRenameVolumeFunction : public LoggedExtensionFunction {
Expand Down
9 changes: 9 additions & 0 deletions chrome/common/extensions/api/file_manager_private.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,15 @@ interface Functions {
FormatFileSystemType filesystem,
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.
// |volumeId| ID of the volume to be renamed.
// |newName| New name of the target volume.
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/extension_function_histogram_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,7 @@ enum HistogramValue {
DECLARATIVENETREQUEST_ISREGEXSUPPORTED = 1508,
PASSWORDSPRIVATE_GETWEAKCREDENTIALS = 1509,
ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT = 1510,
FILEMANAGERPRIVATE_SINGLEPARTITIONFORMAT = 1511,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
10 changes: 10 additions & 0 deletions third_party/closure_compiler/externs/file_manager_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,16 @@ chrome.fileManagerPrivate.getSizeStats = function(volumeId, callback) {};
chrome.fileManagerPrivate.formatVolume = function(volumeId, filesystem,
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
* |newName|.
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24667,6 +24667,7 @@ Called by update_extension_histograms.py.-->
<int value="1508" label="DECLARATIVENETREQUEST_ISREGEXSUPPORTED"/>
<int value="1509" label="PASSWORDSPRIVATE_GETWEAKCREDENTIALS"/>
<int value="1510" label="ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT"/>
<int value="1511" label="FILEMANAGERPRIVATE_SINGLEPARTITIONFORMAT"/>
</enum>

<enum name="ExtensionIconState">
Expand Down

0 comments on commit 52f15a7

Please sign in to comment.