blob: 84f833452914d310bc42c2c1e73dbd18343c9f03 [file] [log] [blame]
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CROS_DISKS_RENAME_MANAGER_H_
#define CROS_DISKS_RENAME_MANAGER_H_
#include <map>
#include <string>
#include <base/macros.h>
#include <base/memory/weak_ptr.h>
#include <brillo/process_reaper.h>
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest_prod.h>
#include "cros-disks/sandboxed_process.h"
namespace cros_disks {
class Platform;
class RenameManagerObserverInterface;
class RenameManager {
public:
RenameManager(Platform* platform, brillo::ProcessReaper* process_reaper);
~RenameManager();
// Starts a renaming process of a given device.
RenameErrorType StartRenaming(const std::string& device_path,
const std::string& device_file,
const std::string& volume_name,
const std::string& filesystem_type);
void set_observer(RenameManagerObserverInterface* observer) {
observer_ = observer;
}
private:
FRIEND_TEST(RenameManagerTest, CanRename);
FRIEND_TEST(RenameManagerTest, ValidateParameters);
FRIEND_TEST(RenameManagerVolumeNameTest, ValidateParameters);
void OnRenameProcessTerminated(const std::string& device_path,
const siginfo_t& info);
// Returns RENAME_ERROR_NONE if file system type is supported, and new
// |volume_name| contains only allowed characters and length is not greater
// than file system's limit.
RenameErrorType ValidateParameters(const std::string& volume_name,
const std::string& filesystem_type) const;
// Returns true if renaming |source_path| is supported.
bool CanRename(const std::string& source_path) const;
// Platform service
Platform* platform_;
brillo::ProcessReaper* process_reaper_;
// A list of outstanding renaming processes indexed by device path.
std::map<std::string, SandboxedProcess> rename_process_;
RenameManagerObserverInterface* observer_;
base::WeakPtrFactory<RenameManager> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(RenameManager);
};
} // namespace cros_disks
#endif // CROS_DISKS_RENAME_MANAGER_H_