media_storage_util.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2014 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.
  4. // MediaStorageUtil provides information about storage devices attached
  5. // to the computer.
  6. #ifndef COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
  7. #define COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
  8. #include <set>
  9. #include <string>
  10. #include "base/callback_forward.h"
  11. #include "base/files/file_path.h"
  12. namespace storage_monitor {
  13. class StorageInfo;
  14. class MediaStorageUtil {
  15. public:
  16. typedef std::set<std::string /*device id*/> DeviceIdSet;
  17. MediaStorageUtil() = delete;
  18. MediaStorageUtil(const MediaStorageUtil&) = delete;
  19. MediaStorageUtil& operator=(const MediaStorageUtil&) = delete;
  20. // Check if the file system at the passed mount point looks like a media
  21. // device using the existence of DCIM directory.
  22. // Returns true if it looks like a media device, otherwise returns false.
  23. // Mac OS X behaves similarly, but this is not the only heuristic it uses.
  24. // TODO(vandebo) Try to figure out how Mac OS X decides this, and rename
  25. // if additional OS X heuristic is implemented.
  26. static bool HasDcim(const base::FilePath& mount_point);
  27. // Returns true if we will be able to create a filesystem for this device.
  28. static bool CanCreateFileSystem(const std::string& device_id,
  29. const base::FilePath& path);
  30. // Removes disconnected devices from |devices| and then calls |done|.
  31. static void FilterAttachedDevices(DeviceIdSet* devices,
  32. base::OnceClosure done);
  33. // Given |path|, fill in |device_info|, and |relative_path|
  34. // (from the root of the device).
  35. static bool GetDeviceInfoFromPath(const base::FilePath& path,
  36. StorageInfo* device_info,
  37. base::FilePath* relative_path);
  38. // Get a base::FilePath for the given |device_id|. If the device isn't a mass
  39. // storage type, the base::FilePath will be empty. This does not check that
  40. // the device is connected.
  41. static base::FilePath FindDevicePathById(const std::string& device_id);
  42. // Returns true if the |id| is both a removable device and also
  43. // currently attached.
  44. static bool IsRemovableStorageAttached(const std::string& id);
  45. };
  46. } // namespace storage_monitor
  47. #endif // COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_