Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1897)

Unified Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 2707193005: Some linked_ptr removal in chromeos file_browser_handler. (Closed)
Patch Set: sync Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/file_manager/volume_manager.cc
diff --git a/chrome/browser/chromeos/file_manager/volume_manager.cc b/chrome/browser/chromeos/file_manager/volume_manager.cc
index 8d592b6a2a778360974b525c78e39ea1ae4f25d8..b8aef4826754d800d09f386524bd861f6aa6d843 100644
--- a/chrome/browser/chromeos/file_manager/volume_manager.cc
+++ b/chrome/browser/chromeos/file_manager/volume_manager.cc
@@ -168,10 +168,10 @@ Volume::~Volume() {
}
// static
-Volume* Volume::CreateForDrive(Profile* profile) {
+std::unique_ptr<Volume> Volume::CreateForDrive(Profile* profile) {
const base::FilePath& drive_path =
drive::util::GetDriveMountPointPath(profile);
- Volume* const volume = new Volume;
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE;
volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
volume->source_path_ = drive_path;
@@ -184,8 +184,9 @@ Volume* Volume::CreateForDrive(Profile* profile) {
}
// static
-Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) {
- Volume* const volume = new Volume;
+std::unique_ptr<Volume> Volume::CreateForDownloads(
+ const base::FilePath& downloads_path) {
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY;
volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
// Keep source_path empty.
@@ -198,10 +199,10 @@ Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) {
}
// static
-Volume* Volume::CreateForRemovable(
+std::unique_ptr<Volume> Volume::CreateForRemovable(
const chromeos::disks::DiskMountManager::MountPointInfo& mount_point,
const chromeos::disks::DiskMountManager::Disk* disk) {
- Volume* const volume = new Volume;
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = MountTypeToVolumeType(mount_point.mount_type);
volume->source_path_ = base::FilePath(mount_point.source_path);
volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE
@@ -228,11 +229,11 @@ Volume* Volume::CreateForRemovable(
}
// static
-Volume* Volume::CreateForProvidedFileSystem(
+std::unique_ptr<Volume> Volume::CreateForProvidedFileSystem(
const chromeos::file_system_provider::ProvidedFileSystemInfo&
file_system_info,
MountContext mount_context) {
- Volume* const volume = new Volume;
+ std::unique_ptr<Volume> volume(new Volume());
volume->file_system_id_ = file_system_info.file_system_id();
volume->extension_id_ = file_system_info.extension_id();
switch (file_system_info.source()) {
@@ -260,10 +261,10 @@ Volume* Volume::CreateForProvidedFileSystem(
}
// static
-Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
- const std::string& label,
- bool read_only) {
- Volume* const volume = new Volume;
+std::unique_ptr<Volume> Volume::CreateForMTP(const base::FilePath& mount_path,
+ const std::string& label,
+ bool read_only) {
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = VOLUME_TYPE_MTP;
volume->mount_path_ = mount_path;
volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
@@ -278,8 +279,9 @@ Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
}
// static
-Volume* Volume::CreateForMediaView(const std::string& root_document_id) {
- Volume* const volume = new Volume;
+std::unique_ptr<Volume> Volume::CreateForMediaView(
+ const std::string& root_document_id) {
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = VOLUME_TYPE_MEDIA_VIEW;
volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
volume->source_ = SOURCE_SYSTEM;
@@ -294,11 +296,12 @@ Volume* Volume::CreateForMediaView(const std::string& root_document_id) {
}
// static
-Volume* Volume::CreateForTesting(const base::FilePath& path,
- VolumeType volume_type,
- chromeos::DeviceType device_type,
- bool read_only) {
- Volume* const volume = new Volume;
+std::unique_ptr<Volume> Volume::CreateForTesting(
+ const base::FilePath& path,
+ VolumeType volume_type,
+ chromeos::DeviceType device_type,
+ bool read_only) {
+ std::unique_ptr<Volume> volume(new Volume());
volume->type_ = volume_type;
volume->device_type_ = device_type;
// Keep source_path empty.
@@ -311,9 +314,10 @@ Volume* Volume::CreateForTesting(const base::FilePath& path,
}
// static
-Volume* Volume::CreateForTesting(const base::FilePath& device_path,
- const base::FilePath& mount_path) {
- Volume* const volume = new Volume;
+std::unique_ptr<Volume> Volume::CreateForTesting(
+ const base::FilePath& device_path,
+ const base::FilePath& mount_path) {
+ std::unique_ptr<Volume> volume(new Volume());
volume->system_path_prefix_ = device_path;
volume->mount_path_ = mount_path;
return volume;
@@ -355,14 +359,14 @@ void VolumeManager::Initialize() {
DCHECK(success);
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- make_linked_ptr(Volume::CreateForDownloads(downloads)));
+ Volume::CreateForDownloads(downloads));
// Subscribe to DriveIntegrationService.
if (drive_integration_service_) {
drive_integration_service_->AddObserver(this);
if (drive_integration_service_->IsMounted()) {
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- make_linked_ptr(Volume::CreateForDrive(profile_)));
+ Volume::CreateForDrive(profile_));
}
}
@@ -382,9 +386,9 @@ void VolumeManager::Initialize() {
std::vector<ProvidedFileSystemInfo> file_system_info_list =
file_system_provider_service_->GetProvidedFileSystemInfoList();
for (size_t i = 0; i < file_system_info_list.size(); ++i) {
- linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem(
- file_system_info_list[i], MOUNT_CONTEXT_AUTO));
- DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
+ std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem(
+ file_system_info_list[i], MOUNT_CONTEXT_AUTO);
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume));
}
}
@@ -457,6 +461,7 @@ std::vector<base::WeakPtr<Volume>> VolumeManager::GetVolumeList() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::vector<base::WeakPtr<Volume>> result;
+ result.reserve(mounted_volumes_.size());
for (const auto& pair : mounted_volumes_) {
result.push_back(pair.second->AsWeakPtr());
}
@@ -480,13 +485,13 @@ bool VolumeManager::RegisterDownloadsDirectoryForTesting(
base::FilePath old_path;
if (FindDownloadsMountPointPath(profile_, &old_path)) {
DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
- make_linked_ptr(Volume::CreateForDownloads(old_path)));
+ *Volume::CreateForDownloads(old_path));
}
bool success = RegisterDownloadsMountPoint(profile_, path);
DoMountEvent(
success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH,
- make_linked_ptr(Volume::CreateForDownloads(path)));
+ Volume::CreateForDownloads(path));
return success;
}
@@ -495,14 +500,14 @@ void VolumeManager::AddVolumeForTesting(const base::FilePath& path,
chromeos::DeviceType device_type,
bool read_only) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- make_linked_ptr(Volume::CreateForTesting(
- path, volume_type, device_type, read_only)));
+ DoMountEvent(
+ chromeos::MOUNT_ERROR_NONE,
+ Volume::CreateForTesting(path, volume_type, device_type, read_only));
}
-void VolumeManager::AddVolumeForTesting(const linked_ptr<Volume>& volume) {
+void VolumeManager::AddVolumeForTesting(std::unique_ptr<Volume> volume) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume));
}
void VolumeManager::OnFileSystemMounted() {
@@ -511,15 +516,13 @@ void VolumeManager::OnFileSystemMounted() {
// Raise mount event.
// We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
// or network is unreachable. These two errors will be handled later.
- linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
- DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, Volume::CreateForDrive(profile_));
}
void VolumeManager::OnFileSystemBeingUnmounted() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
- DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume);
+ DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *Volume::CreateForDrive(profile_));
}
void VolumeManager::OnDiskEvent(
@@ -629,14 +632,14 @@ void VolumeManager::OnMountEvent(
// Notify a mounting/unmounting event to observers.
const chromeos::disks::DiskMountManager::Disk* const disk =
disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path);
- linked_ptr<Volume> volume(Volume::CreateForRemovable(mount_info, disk));
+ std::unique_ptr<Volume> volume = Volume::CreateForRemovable(mount_info, disk);
switch (event) {
case chromeos::disks::DiskMountManager::MOUNTING: {
- DoMountEvent(error_code, volume);
+ DoMountEvent(error_code, std::move(volume));
return;
}
case chromeos::disks::DiskMountManager::UNMOUNTING:
- DoUnmountEvent(error_code, volume);
+ DoUnmountEvent(error_code, *volume);
return;
}
NOTREACHED();
@@ -694,8 +697,8 @@ void VolumeManager::OnProvidedFileSystemMount(
break;
}
- linked_ptr<Volume> volume(
- Volume::CreateForProvidedFileSystem(file_system_info, volume_context));
+ std::unique_ptr<Volume> volume =
+ Volume::CreateForProvidedFileSystem(file_system_info, volume_context);
// TODO(mtomasz): Introduce own type, and avoid using MountError internally,
// since it is related to cros disks only.
@@ -712,7 +715,7 @@ void VolumeManager::OnProvidedFileSystemMount(
break;
}
- DoMountEvent(mount_error, volume);
+ DoMountEvent(mount_error, std::move(volume));
}
void VolumeManager::OnProvidedFileSystemUnmount(
@@ -724,9 +727,9 @@ void VolumeManager::OnProvidedFileSystemUnmount(
const chromeos::MountError mount_error = error == base::File::FILE_OK
? chromeos::MOUNT_ERROR_NONE
: chromeos::MOUNT_ERROR_UNKNOWN;
- linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem(
- file_system_info, MOUNT_CONTEXT_UNKNOWN));
- DoUnmountEvent(mount_error, volume);
+ std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem(
+ file_system_info, MOUNT_CONTEXT_UNKNOWN);
+ DoUnmountEvent(mount_error, *volume);
}
void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback(
@@ -753,24 +756,18 @@ void VolumeManager::OnArcPlayStoreEnabledChanged(bool enabled) {
if (enabled) {
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
+ Volume::CreateForMediaView(arc::kImagesRootDocumentId));
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
+ Volume::CreateForMediaView(arc::kVideosRootDocumentId));
DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
+ Volume::CreateForMediaView(arc::kAudioRootDocumentId));
} else {
DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
+ *Volume::CreateForMediaView(arc::kImagesRootDocumentId));
DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
+ *Volume::CreateForMediaView(arc::kVideosRootDocumentId));
DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
- linked_ptr<Volume>(
- Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
+ *Volume::CreateForMediaView(arc::kAudioRootDocumentId));
}
arc_volumes_mounted_ = enabled;
@@ -858,8 +855,8 @@ void VolumeManager::OnRemovableStorageAttached(
base::Unretained(MTPDeviceMapService::GetInstance()),
info.location(), fsid, read_only));
- linked_ptr<Volume> volume(Volume::CreateForMTP(path, label, read_only));
- DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
+ std::unique_ptr<Volume> volume = Volume::CreateForMTP(path, label, read_only);
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume));
}
void VolumeManager::OnRemovableStorageDetached(
@@ -867,9 +864,9 @@ void VolumeManager::OnRemovableStorageDetached(
if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
return;
- for (const auto mounted_volume : mounted_volumes_) {
+ for (const auto& mounted_volume : mounted_volumes_) {
if (mounted_volume.second->source_path().value() == info.location()) {
- DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, mounted_volume.second);
+ DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *mounted_volume.second.get());
const std::string fsid = GetMountPointNameForMediaStorage(info);
storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid);
@@ -889,7 +886,7 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) {
return;
}
- std::vector<linked_ptr<Volume>> archives;
+ std::vector<std::unique_ptr<Volume>> archives;
const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
disk_mount_manager_->mount_points();
@@ -899,14 +896,14 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) {
++it) {
if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
// Archives are mounted after other types of volume. See below.
- archives.push_back(
- make_linked_ptr(Volume::CreateForRemovable(it->second, NULL)));
+ archives.push_back(Volume::CreateForRemovable(it->second, nullptr));
continue;
}
- DoMountEvent(chromeos::MOUNT_ERROR_NONE,
- make_linked_ptr(Volume::CreateForRemovable(
- it->second, disk_mount_manager_->FindDiskBySourcePath(
- it->second.source_path))));
+ DoMountEvent(
+ chromeos::MOUNT_ERROR_NONE,
+ Volume::CreateForRemovable(
+ it->second,
+ disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)));
}
// We mount archives only if they are opened from currently mounted volumes.
@@ -916,24 +913,26 @@ void VolumeManager::OnDiskMountManagerRefreshed(bool success) {
if (done[i])
continue;
- std::vector<linked_ptr<Volume>> chain;
+ std::vector<std::unique_ptr<Volume>> chain;
+ // done[x] = true means archives[x] is null and that volume is in |chain|.
done[i] = true;
- chain.push_back(archives[i]);
+ chain.push_back(std::move(archives[i]));
// If archives[i]'s source_path is in another archive, mount it first.
for (size_t parent = i + 1; parent < archives.size(); ++parent) {
if (!done[parent] &&
archives[parent]->mount_path().IsParent(
chain.back()->source_path())) {
+ // done[parent] started false, so archives[parent] is non-null.
done[parent] = true;
- chain.push_back(archives[parent]);
+ chain.push_back(std::move(archives[parent]));
parent = i + 1; // Search archives[parent]'s parent from the beginning.
}
}
// Mount from the tail of chain.
for (size_t i = chain.size(); i > 0; --i) {
- DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1]);
+ DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(chain[i - 1]));
}
}
}
@@ -947,7 +946,7 @@ void VolumeManager::OnStorageMonitorInitialized() {
}
void VolumeManager::DoMountEvent(chromeos::MountError error_code,
- const linked_ptr<Volume>& volume) {
+ std::unique_ptr<Volume> volume) {
// Archive files are mounted globally in system. We however don't want to show
// archives from profile-specific folders (Drive/Downloads) of other users in
// multi-profile session. To this end, we filter out archives not on the
@@ -972,25 +971,27 @@ void VolumeManager::DoMountEvent(chromeos::MountError error_code,
return;
}
+ Volume* raw_volume = volume.get();
if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) {
- mounted_volumes_[volume->volume_id()] = volume;
- UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(),
+ mounted_volumes_[volume->volume_id()] = std::move(volume);
+ UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", raw_volume->type(),
NUM_VOLUME_TYPE);
}
for (auto& observer : observers_)
- observer.OnVolumeMounted(error_code, *volume);
+ observer.OnVolumeMounted(error_code, *raw_volume);
}
void VolumeManager::DoUnmountEvent(chromeos::MountError error_code,
- const linked_ptr<Volume>& volume) {
- if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
+ const Volume& volume) {
+ auto iter = mounted_volumes_.find(volume.volume_id());
+ if (iter == mounted_volumes_.end())
return;
if (error_code == chromeos::MOUNT_ERROR_NONE)
- mounted_volumes_.erase(volume->volume_id());
+ mounted_volumes_.erase(iter);
for (auto& observer : observers_)
- observer.OnVolumeUnmounted(error_code, *volume.get());
+ observer.OnVolumeUnmounted(error_code, volume);
}
} // namespace file_manager
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698