[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / chromeos / disks / disk_mount_manager.cc
blob36e4c46f5e4514a2a488bdd5c4e2e2d9a5932c51
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/disks/disk_mount_manager.h"
7 #include <set>
9 #include "base/bind.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
16 namespace chromeos {
17 namespace disks {
19 namespace {
21 const char kDeviceNotFound[] = "Device could not be found";
23 DiskMountManager* g_disk_mount_manager = NULL;
25 // The DiskMountManager implementation.
26 class DiskMountManagerImpl : public DiskMountManager {
27 public:
28 DiskMountManagerImpl() :
29 already_refreshed_(false),
30 weak_ptr_factory_(this) {
31 DBusThreadManager* dbus_thread_manager = DBusThreadManager::Get();
32 DCHECK(dbus_thread_manager);
33 cros_disks_client_ = dbus_thread_manager->GetCrosDisksClient();
34 DCHECK(cros_disks_client_);
35 cros_disks_client_->SetMountEventHandler(
36 base::Bind(&DiskMountManagerImpl::OnMountEvent,
37 weak_ptr_factory_.GetWeakPtr()));
38 cros_disks_client_->SetMountCompletedHandler(
39 base::Bind(&DiskMountManagerImpl::OnMountCompleted,
40 weak_ptr_factory_.GetWeakPtr()));
41 cros_disks_client_->SetFormatCompletedHandler(
42 base::Bind(&DiskMountManagerImpl::OnFormatCompleted,
43 weak_ptr_factory_.GetWeakPtr()));
46 ~DiskMountManagerImpl() override {
47 STLDeleteContainerPairSecondPointers(disks_.begin(), disks_.end());
50 // DiskMountManager override.
51 void AddObserver(Observer* observer) override {
52 observers_.AddObserver(observer);
55 // DiskMountManager override.
56 void RemoveObserver(Observer* observer) override {
57 observers_.RemoveObserver(observer);
60 // DiskMountManager override.
61 void MountPath(const std::string& source_path,
62 const std::string& source_format,
63 const std::string& mount_label,
64 MountType type) override {
65 // Hidden and non-existent devices should not be mounted.
66 if (type == MOUNT_TYPE_DEVICE) {
67 DiskMap::const_iterator it = disks_.find(source_path);
68 if (it == disks_.end() || it->second->is_hidden()) {
69 OnMountCompleted(MountEntry(MOUNT_ERROR_INTERNAL, source_path, type,
70 ""));
71 return;
74 cros_disks_client_->Mount(
75 source_path,
76 source_format,
77 mount_label,
78 // When succeeds, OnMountCompleted will be called by
79 // "MountCompleted" signal instead.
80 base::Bind(&base::DoNothing),
81 base::Bind(&DiskMountManagerImpl::OnMountCompleted,
82 weak_ptr_factory_.GetWeakPtr(),
83 MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, "")));
86 // DiskMountManager override.
87 void UnmountPath(const std::string& mount_path,
88 UnmountOptions options,
89 const UnmountPathCallback& callback) override {
90 UnmountChildMounts(mount_path);
91 cros_disks_client_->Unmount(mount_path, options,
92 base::Bind(&DiskMountManagerImpl::OnUnmountPath,
93 weak_ptr_factory_.GetWeakPtr(),
94 callback,
95 true,
96 mount_path),
97 base::Bind(&DiskMountManagerImpl::OnUnmountPath,
98 weak_ptr_factory_.GetWeakPtr(),
99 callback,
100 false,
101 mount_path));
104 // DiskMountManager override.
105 void FormatMountedDevice(const std::string& mount_path) override {
106 MountPointMap::const_iterator mount_point = mount_points_.find(mount_path);
107 if (mount_point == mount_points_.end()) {
108 LOG(ERROR) << "Mount point with path \"" << mount_path << "\" not found.";
109 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, mount_path);
110 return;
113 std::string device_path = mount_point->second.source_path;
114 DiskMap::const_iterator disk = disks_.find(device_path);
115 if (disk == disks_.end()) {
116 LOG(ERROR) << "Device with path \"" << device_path << "\" not found.";
117 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, device_path);
118 return;
121 UnmountPath(disk->second->mount_path(),
122 UNMOUNT_OPTIONS_NONE,
123 base::Bind(&DiskMountManagerImpl::OnUnmountPathForFormat,
124 weak_ptr_factory_.GetWeakPtr(),
125 device_path));
128 // DiskMountManager override.
129 void UnmountDeviceRecursively(
130 const std::string& device_path,
131 const UnmountDeviceRecursivelyCallbackType& callback) override {
132 std::vector<std::string> devices_to_unmount;
134 // Get list of all devices to unmount.
135 int device_path_len = device_path.length();
136 for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) {
137 if (!it->second->mount_path().empty() &&
138 strncmp(device_path.c_str(), it->second->device_path().c_str(),
139 device_path_len) == 0) {
140 devices_to_unmount.push_back(it->second->mount_path());
144 // We should detect at least original device.
145 if (devices_to_unmount.empty()) {
146 if (disks_.find(device_path) == disks_.end()) {
147 LOG(WARNING) << "Unmount recursive request failed for device "
148 << device_path << ", with error: " << kDeviceNotFound;
149 callback.Run(false);
150 return;
153 // Nothing to unmount.
154 callback.Run(true);
155 return;
158 // We will send the same callback data object to all Unmount calls and use
159 // it to synchronize callbacks.
160 // Note: this implementation has a potential memory leak issue. For
161 // example if this instance is destructed before all the callbacks for
162 // Unmount are invoked, the memory pointed by |cb_data| will be leaked.
163 // It is because the UnmountDeviceRecursivelyCallbackData keeps how
164 // many times OnUnmountDeviceRecursively callback is called and when
165 // all the callbacks are called, |cb_data| will be deleted in the method.
166 // However destructing the instance before all callback invocations will
167 // cancel all pending callbacks, so that the |cb_data| would never be
168 // deleted.
169 // Fortunately, in the real scenario, the instance will be destructed
170 // only for ShutDown. So, probably the memory would rarely be leaked.
171 // TODO(hidehiko): Fix the issue.
172 UnmountDeviceRecursivelyCallbackData* cb_data =
173 new UnmountDeviceRecursivelyCallbackData(
174 callback, devices_to_unmount.size());
175 for (size_t i = 0; i < devices_to_unmount.size(); ++i) {
176 cros_disks_client_->Unmount(
177 devices_to_unmount[i],
178 UNMOUNT_OPTIONS_NONE,
179 base::Bind(&DiskMountManagerImpl::OnUnmountDeviceRecursively,
180 weak_ptr_factory_.GetWeakPtr(),
181 cb_data,
182 true,
183 devices_to_unmount[i]),
184 base::Bind(&DiskMountManagerImpl::OnUnmountDeviceRecursively,
185 weak_ptr_factory_.GetWeakPtr(),
186 cb_data,
187 false,
188 devices_to_unmount[i]));
192 // DiskMountManager override.
193 void EnsureMountInfoRefreshed(
194 const EnsureMountInfoRefreshedCallback& callback) override {
195 if (already_refreshed_) {
196 callback.Run(true);
197 return;
200 refresh_callbacks_.push_back(callback);
201 if (refresh_callbacks_.size() == 1) {
202 // If there's no in-flight refreshing task, start it.
203 cros_disks_client_->EnumerateAutoMountableDevices(
204 base::Bind(&DiskMountManagerImpl::RefreshAfterEnumerateDevices,
205 weak_ptr_factory_.GetWeakPtr()),
206 base::Bind(&DiskMountManagerImpl::RefreshCompleted,
207 weak_ptr_factory_.GetWeakPtr(), false));
211 // DiskMountManager override.
212 const DiskMap& disks() const override { return disks_; }
214 // DiskMountManager override.
215 const Disk* FindDiskBySourcePath(
216 const std::string& source_path) const override {
217 DiskMap::const_iterator disk_it = disks_.find(source_path);
218 return disk_it == disks_.end() ? NULL : disk_it->second;
221 // DiskMountManager override.
222 const MountPointMap& mount_points() const override { return mount_points_; }
224 // DiskMountManager override.
225 bool AddDiskForTest(Disk* disk) override {
226 if (disks_.find(disk->device_path()) != disks_.end()) {
227 LOG(ERROR) << "Attempt to add a duplicate disk";
228 return false;
231 disks_.insert(std::make_pair(disk->device_path(), disk));
232 return true;
235 // DiskMountManager override.
236 // Corresponding disk should be added to the manager before this is called.
237 bool AddMountPointForTest(const MountPointInfo& mount_point) override {
238 if (mount_points_.find(mount_point.mount_path) != mount_points_.end()) {
239 LOG(ERROR) << "Attempt to add a duplicate mount point";
240 return false;
242 if (mount_point.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
243 disks_.find(mount_point.source_path) == disks_.end()) {
244 LOG(ERROR) << "Device mount points must have a disk entry.";
245 return false;
248 mount_points_.insert(std::make_pair(mount_point.mount_path, mount_point));
249 return true;
252 private:
253 struct UnmountDeviceRecursivelyCallbackData {
254 UnmountDeviceRecursivelyCallbackData(
255 const UnmountDeviceRecursivelyCallbackType& in_callback,
256 int in_num_pending_callbacks)
257 : callback(in_callback),
258 num_pending_callbacks(in_num_pending_callbacks) {
261 const UnmountDeviceRecursivelyCallbackType callback;
262 size_t num_pending_callbacks;
265 // Unmounts all mount points whose source path is transitively parented by
266 // |mount_path|.
267 void UnmountChildMounts(const std::string& mount_path_in) {
268 std::string mount_path = mount_path_in;
269 // Let's make sure mount path has trailing slash.
270 if (mount_path[mount_path.length() - 1] != '/')
271 mount_path += '/';
273 for (MountPointMap::iterator it = mount_points_.begin();
274 it != mount_points_.end();
275 ++it) {
276 if (base::StartsWithASCII(it->second.source_path, mount_path,
277 true /*case sensitive*/)) {
278 // TODO(tbarzic): Handle the case where this fails.
279 UnmountPath(it->second.mount_path,
280 UNMOUNT_OPTIONS_NONE,
281 UnmountPathCallback());
286 // Callback for UnmountDeviceRecursively.
287 void OnUnmountDeviceRecursively(
288 UnmountDeviceRecursivelyCallbackData* cb_data,
289 bool success,
290 const std::string& mount_path) {
291 if (success) {
292 // Do standard processing for Unmount event.
293 OnUnmountPath(UnmountPathCallback(), true, mount_path);
294 VLOG(1) << mount_path << " unmounted.";
296 // This is safe as long as all callbacks are called on the same thread as
297 // UnmountDeviceRecursively.
298 cb_data->num_pending_callbacks--;
300 if (cb_data->num_pending_callbacks == 0) {
301 // This code has a problem that the |success| status used here is for the
302 // last "unmount" callback, but not whether all unmounting is succeeded.
303 // TODO(hidehiko): Fix the issue.
304 cb_data->callback.Run(success);
305 delete cb_data;
309 // Callback to handle MountCompleted signal and Mount method call failure.
310 void OnMountCompleted(const MountEntry& entry) {
311 MountCondition mount_condition = MOUNT_CONDITION_NONE;
312 if (entry.mount_type() == MOUNT_TYPE_DEVICE) {
313 if (entry.error_code() == MOUNT_ERROR_UNKNOWN_FILESYSTEM) {
314 mount_condition = MOUNT_CONDITION_UNKNOWN_FILESYSTEM;
316 if (entry.error_code() == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) {
317 mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM;
320 const MountPointInfo mount_info(entry.source_path(),
321 entry.mount_path(),
322 entry.mount_type(),
323 mount_condition);
325 NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
327 // If the device is corrupted but it's still possible to format it, it will
328 // be fake mounted.
329 if ((entry.error_code() == MOUNT_ERROR_NONE ||
330 mount_info.mount_condition) &&
331 mount_points_.find(mount_info.mount_path) == mount_points_.end()) {
332 mount_points_.insert(MountPointMap::value_type(mount_info.mount_path,
333 mount_info));
335 if ((entry.error_code() == MOUNT_ERROR_NONE ||
336 mount_info.mount_condition) &&
337 mount_info.mount_type == MOUNT_TYPE_DEVICE &&
338 !mount_info.source_path.empty() &&
339 !mount_info.mount_path.empty()) {
340 DiskMap::iterator iter = disks_.find(mount_info.source_path);
341 if (iter == disks_.end()) {
342 // disk might have been removed by now?
343 return;
345 Disk* disk = iter->second;
346 DCHECK(disk);
347 disk->set_mount_path(mount_info.mount_path);
351 // Callback for UnmountPath.
352 void OnUnmountPath(const UnmountPathCallback& callback,
353 bool success,
354 const std::string& mount_path) {
355 MountPointMap::iterator mount_points_it = mount_points_.find(mount_path);
356 if (mount_points_it == mount_points_.end()) {
357 // The path was unmounted, but not as a result of this unmount request,
358 // so return error.
359 if (!callback.is_null())
360 callback.Run(MOUNT_ERROR_INTERNAL);
361 return;
364 NotifyMountStatusUpdate(
365 UNMOUNTING,
366 success ? MOUNT_ERROR_NONE : MOUNT_ERROR_INTERNAL,
367 MountPointInfo(mount_points_it->second.source_path,
368 mount_points_it->second.mount_path,
369 mount_points_it->second.mount_type,
370 mount_points_it->second.mount_condition));
372 std::string path(mount_points_it->second.source_path);
373 if (success)
374 mount_points_.erase(mount_points_it);
376 DiskMap::iterator disk_iter = disks_.find(path);
377 if (disk_iter != disks_.end()) {
378 DCHECK(disk_iter->second);
379 if (success)
380 disk_iter->second->clear_mount_path();
383 if (!callback.is_null())
384 callback.Run(success ? MOUNT_ERROR_NONE : MOUNT_ERROR_INTERNAL);
387 void OnUnmountPathForFormat(const std::string& device_path,
388 MountError error_code) {
389 if (error_code == MOUNT_ERROR_NONE &&
390 disks_.find(device_path) != disks_.end()) {
391 FormatUnmountedDevice(device_path);
392 } else {
393 OnFormatCompleted(FORMAT_ERROR_UNKNOWN, device_path);
397 // Starts device formatting.
398 void FormatUnmountedDevice(const std::string& device_path) {
399 DiskMap::const_iterator disk = disks_.find(device_path);
400 DCHECK(disk != disks_.end() && disk->second->mount_path().empty());
402 const char kFormatVFAT[] = "vfat";
403 cros_disks_client_->Format(
404 device_path,
405 kFormatVFAT,
406 base::Bind(&DiskMountManagerImpl::OnFormatStarted,
407 weak_ptr_factory_.GetWeakPtr(),
408 device_path),
409 base::Bind(&DiskMountManagerImpl::OnFormatCompleted,
410 weak_ptr_factory_.GetWeakPtr(),
411 FORMAT_ERROR_UNKNOWN,
412 device_path));
415 // Callback for Format.
416 void OnFormatStarted(const std::string& device_path) {
417 NotifyFormatStatusUpdate(FORMAT_STARTED, FORMAT_ERROR_NONE, device_path);
420 // Callback to handle FormatCompleted signal and Format method call failure.
421 void OnFormatCompleted(FormatError error_code,
422 const std::string& device_path) {
423 NotifyFormatStatusUpdate(FORMAT_COMPLETED, error_code, device_path);
426 // Callback for GetDeviceProperties.
427 void OnGetDeviceProperties(const DiskInfo& disk_info) {
428 // TODO(zelidrag): Find a better way to filter these out before we
429 // fetch the properties:
430 // Ignore disks coming from the device we booted the system from.
431 if (disk_info.on_boot_device())
432 return;
434 LOG(WARNING) << "Found disk " << disk_info.device_path();
435 // Delete previous disk info for this path:
436 bool is_new = true;
437 DiskMap::iterator iter = disks_.find(disk_info.device_path());
438 if (iter != disks_.end()) {
439 delete iter->second;
440 disks_.erase(iter);
441 is_new = false;
443 Disk* disk = new Disk(disk_info.device_path(),
444 disk_info.mount_path(),
445 disk_info.system_path(),
446 disk_info.file_path(),
447 disk_info.label(),
448 disk_info.drive_label(),
449 disk_info.vendor_id(),
450 disk_info.vendor_name(),
451 disk_info.product_id(),
452 disk_info.product_name(),
453 disk_info.uuid(),
454 FindSystemPathPrefix(disk_info.system_path()),
455 disk_info.device_type(),
456 disk_info.total_size_in_bytes(),
457 disk_info.is_drive(),
458 disk_info.is_read_only(),
459 disk_info.has_media(),
460 disk_info.on_boot_device(),
461 disk_info.on_removable_device(),
462 disk_info.is_hidden());
463 disks_.insert(std::make_pair(disk_info.device_path(), disk));
464 NotifyDiskStatusUpdate(is_new ? DISK_ADDED : DISK_CHANGED, disk);
467 // Part of EnsureMountInfoRefreshed(). Called after the list of devices are
468 // enumerated.
469 void RefreshAfterEnumerateDevices(const std::vector<std::string>& devices) {
470 std::set<std::string> current_device_set(devices.begin(), devices.end());
471 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) {
472 if (current_device_set.find(iter->first) == current_device_set.end()) {
473 delete iter->second;
474 disks_.erase(iter++);
475 } else {
476 ++iter;
479 RefreshDeviceAtIndex(devices, 0);
482 // Part of EnsureMountInfoRefreshed(). Called for each device to refresh info.
483 void RefreshDeviceAtIndex(const std::vector<std::string>& devices,
484 size_t index) {
485 if (index == devices.size()) {
486 // All devices info retrieved. Proceed to enumerate mount point info.
487 cros_disks_client_->EnumerateMountEntries(
488 base::Bind(&DiskMountManagerImpl::RefreshAfterEnumerateMountEntries,
489 weak_ptr_factory_.GetWeakPtr()),
490 base::Bind(&DiskMountManagerImpl::RefreshCompleted,
491 weak_ptr_factory_.GetWeakPtr(), false));
492 return;
495 cros_disks_client_->GetDeviceProperties(
496 devices[index],
497 base::Bind(&DiskMountManagerImpl::RefreshAfterGetDeviceProperties,
498 weak_ptr_factory_.GetWeakPtr(), devices, index + 1),
499 base::Bind(&DiskMountManagerImpl::RefreshCompleted,
500 weak_ptr_factory_.GetWeakPtr(), false));
503 // Part of EnsureMountInfoRefreshed().
504 void RefreshAfterGetDeviceProperties(const std::vector<std::string>& devices,
505 size_t next_index,
506 const DiskInfo& disk_info) {
507 OnGetDeviceProperties(disk_info);
508 RefreshDeviceAtIndex(devices, next_index);
511 // Part of EnsureMountInfoRefreshed(). Called after mount entries are listed.
512 void RefreshAfterEnumerateMountEntries(
513 const std::vector<MountEntry>& entries) {
514 for (size_t i = 0; i < entries.size(); ++i)
515 OnMountCompleted(entries[i]);
516 RefreshCompleted(true);
519 // Part of EnsureMountInfoRefreshed(). Called when the refreshing is done.
520 void RefreshCompleted(bool success) {
521 already_refreshed_ = true;
522 for (size_t i = 0; i < refresh_callbacks_.size(); ++i)
523 refresh_callbacks_[i].Run(success);
524 refresh_callbacks_.clear();
527 // Callback to handle mount event signals.
528 void OnMountEvent(MountEventType event, const std::string& device_path_arg) {
529 // Take a copy of the argument so we can modify it below.
530 std::string device_path = device_path_arg;
531 switch (event) {
532 case CROS_DISKS_DISK_ADDED: {
533 cros_disks_client_->GetDeviceProperties(
534 device_path,
535 base::Bind(&DiskMountManagerImpl::OnGetDeviceProperties,
536 weak_ptr_factory_.GetWeakPtr()),
537 base::Bind(&base::DoNothing));
538 break;
540 case CROS_DISKS_DISK_REMOVED: {
541 // Search and remove disks that are no longer present.
542 DiskMountManager::DiskMap::iterator iter = disks_.find(device_path);
543 if (iter != disks_.end()) {
544 Disk* disk = iter->second;
545 NotifyDiskStatusUpdate(DISK_REMOVED, disk);
546 delete iter->second;
547 disks_.erase(iter);
549 break;
551 case CROS_DISKS_DEVICE_ADDED: {
552 system_path_prefixes_.insert(device_path);
553 NotifyDeviceStatusUpdate(DEVICE_ADDED, device_path);
554 break;
556 case CROS_DISKS_DEVICE_REMOVED: {
557 system_path_prefixes_.erase(device_path);
558 NotifyDeviceStatusUpdate(DEVICE_REMOVED, device_path);
559 break;
561 case CROS_DISKS_DEVICE_SCANNED: {
562 NotifyDeviceStatusUpdate(DEVICE_SCANNED, device_path);
563 break;
565 default: {
566 LOG(ERROR) << "Unknown event: " << event;
571 // Notifies all observers about disk status update.
572 void NotifyDiskStatusUpdate(DiskEvent event,
573 const Disk* disk) {
574 FOR_EACH_OBSERVER(Observer, observers_, OnDiskEvent(event, disk));
577 // Notifies all observers about device status update.
578 void NotifyDeviceStatusUpdate(DeviceEvent event,
579 const std::string& device_path) {
580 FOR_EACH_OBSERVER(Observer, observers_, OnDeviceEvent(event, device_path));
583 // Notifies all observers about mount completion.
584 void NotifyMountStatusUpdate(MountEvent event,
585 MountError error_code,
586 const MountPointInfo& mount_info) {
587 FOR_EACH_OBSERVER(Observer, observers_,
588 OnMountEvent(event, error_code, mount_info));
591 void NotifyFormatStatusUpdate(FormatEvent event,
592 FormatError error_code,
593 const std::string& device_path) {
594 FOR_EACH_OBSERVER(Observer, observers_,
595 OnFormatEvent(event, error_code, device_path));
598 // Finds system path prefix from |system_path|.
599 const std::string& FindSystemPathPrefix(const std::string& system_path) {
600 if (system_path.empty())
601 return base::EmptyString();
602 for (SystemPathPrefixSet::const_iterator it = system_path_prefixes_.begin();
603 it != system_path_prefixes_.end();
604 ++it) {
605 const std::string& prefix = *it;
606 if (base::StartsWithASCII(system_path, prefix, true))
607 return prefix;
609 return base::EmptyString();
612 // Mount event change observers.
613 base::ObserverList<Observer> observers_;
615 CrosDisksClient* cros_disks_client_;
617 // The list of disks found.
618 DiskMountManager::DiskMap disks_;
620 DiskMountManager::MountPointMap mount_points_;
622 typedef std::set<std::string> SystemPathPrefixSet;
623 SystemPathPrefixSet system_path_prefixes_;
625 bool already_refreshed_;
626 std::vector<EnsureMountInfoRefreshedCallback> refresh_callbacks_;
628 base::WeakPtrFactory<DiskMountManagerImpl> weak_ptr_factory_;
630 DISALLOW_COPY_AND_ASSIGN(DiskMountManagerImpl);
633 } // namespace
635 DiskMountManager::Disk::Disk(const std::string& device_path,
636 const std::string& mount_path,
637 const std::string& system_path,
638 const std::string& file_path,
639 const std::string& device_label,
640 const std::string& drive_label,
641 const std::string& vendor_id,
642 const std::string& vendor_name,
643 const std::string& product_id,
644 const std::string& product_name,
645 const std::string& fs_uuid,
646 const std::string& system_path_prefix,
647 DeviceType device_type,
648 uint64 total_size_in_bytes,
649 bool is_parent,
650 bool is_read_only,
651 bool has_media,
652 bool on_boot_device,
653 bool on_removable_device,
654 bool is_hidden)
655 : device_path_(device_path),
656 mount_path_(mount_path),
657 system_path_(system_path),
658 file_path_(file_path),
659 device_label_(device_label),
660 drive_label_(drive_label),
661 vendor_id_(vendor_id),
662 vendor_name_(vendor_name),
663 product_id_(product_id),
664 product_name_(product_name),
665 fs_uuid_(fs_uuid),
666 system_path_prefix_(system_path_prefix),
667 device_type_(device_type),
668 total_size_in_bytes_(total_size_in_bytes),
669 is_parent_(is_parent),
670 is_read_only_(is_read_only),
671 has_media_(has_media),
672 on_boot_device_(on_boot_device),
673 on_removable_device_(on_removable_device),
674 is_hidden_(is_hidden) {
677 DiskMountManager::Disk::~Disk() {}
679 bool DiskMountManager::AddDiskForTest(Disk* disk) {
680 return false;
683 bool DiskMountManager::AddMountPointForTest(const MountPointInfo& mount_point) {
684 return false;
687 // static
688 std::string DiskMountManager::MountConditionToString(MountCondition condition) {
689 switch (condition) {
690 case MOUNT_CONDITION_NONE:
691 return "";
692 case MOUNT_CONDITION_UNKNOWN_FILESYSTEM:
693 return "unknown_filesystem";
694 case MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM:
695 return "unsupported_filesystem";
696 default:
697 NOTREACHED();
699 return "";
702 // static
703 std::string DiskMountManager::DeviceTypeToString(DeviceType type) {
704 switch (type) {
705 case DEVICE_TYPE_USB:
706 return "usb";
707 case DEVICE_TYPE_SD:
708 return "sd";
709 case DEVICE_TYPE_OPTICAL_DISC:
710 return "optical";
711 case DEVICE_TYPE_MOBILE:
712 return "mobile";
713 default:
714 return "unknown";
718 // static
719 void DiskMountManager::Initialize() {
720 if (g_disk_mount_manager) {
721 LOG(WARNING) << "DiskMountManager was already initialized";
722 return;
724 g_disk_mount_manager = new DiskMountManagerImpl();
725 VLOG(1) << "DiskMountManager initialized";
728 // static
729 void DiskMountManager::InitializeForTesting(
730 DiskMountManager* disk_mount_manager) {
731 if (g_disk_mount_manager) {
732 LOG(WARNING) << "DiskMountManager was already initialized";
733 return;
735 g_disk_mount_manager = disk_mount_manager;
736 VLOG(1) << "DiskMountManager initialized";
739 // static
740 void DiskMountManager::Shutdown() {
741 if (!g_disk_mount_manager) {
742 LOG(WARNING) << "DiskMountManager::Shutdown() called with NULL manager";
743 return;
745 delete g_disk_mount_manager;
746 g_disk_mount_manager = NULL;
747 VLOG(1) << "DiskMountManager Shutdown completed";
750 // static
751 DiskMountManager* DiskMountManager::GetInstance() {
752 return g_disk_mount_manager;
755 } // namespace disks
756 } // namespace chromeos