Home | History | Annotate | Download | only in storage_monitor
      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 
      5 // MediaStorageUtil provides information about storage devices attached
      6 // to the computer.
      7 
      8 #ifndef COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
      9 #define COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
     10 
     11 #include <set>
     12 #include <string>
     13 
     14 #include "base/basictypes.h"
     15 #include "base/callback_forward.h"
     16 #include "base/files/file_path.h"
     17 
     18 namespace storage_monitor {
     19 
     20 class StorageInfo;
     21 
     22 class MediaStorageUtil {
     23  public:
     24   typedef std::set<std::string /*device id*/> DeviceIdSet;
     25 
     26   // Check if the file system at the passed mount point looks like a media
     27   // device using the existence of DCIM directory.
     28   // Returns true if it looks like a media device, otherwise returns false.
     29   // Mac OS X behaves similarly, but this is not the only heuristic it uses.
     30   // TODO(vandebo) Try to figure out how Mac OS X decides this, and rename
     31   // if additional OS X heuristic is implemented.
     32   static bool HasDcim(const base::FilePath& mount_point);
     33 
     34   // Returns true if we will be able to create a filesystem for this device.
     35   static bool CanCreateFileSystem(const std::string& device_id,
     36                                   const base::FilePath& path);
     37 
     38   // Removes disconnected devices from |devices| and then calls |done|.
     39   static void FilterAttachedDevices(DeviceIdSet* devices,
     40                                     const base::Closure& done);
     41 
     42   // Given |path|, fill in |device_info|, and |relative_path|
     43   // (from the root of the device).
     44   static bool GetDeviceInfoFromPath(const base::FilePath& path,
     45                                     StorageInfo* device_info,
     46                                     base::FilePath* relative_path);
     47 
     48   // Get a base::FilePath for the given |device_id|.  If the device isn't a mass
     49   // storage type, the base::FilePath will be empty.  This does not check that
     50   // the device is connected.
     51   static base::FilePath FindDevicePathById(const std::string& device_id);
     52 
     53   // Record device information histogram for the given |device_uuid| and
     54   // |device_label|. |mass_storage| indicates whether the current device is a
     55   // mass storage device, as defined by IsMassStorageDevice().
     56   static void RecordDeviceInfoHistogram(bool mass_storage,
     57                                         const std::string& device_uuid,
     58                                         const base::string16& device_label);
     59 
     60   // Returns true if the |id| is both a removable device and also
     61   // currently attached.
     62   static bool IsRemovableStorageAttached(const std::string& id);
     63 
     64  private:
     65   DISALLOW_IMPLICIT_CONSTRUCTORS(MediaStorageUtil);
     66 };
     67 
     68 }  // namespace storage_monitor
     69 
     70 #endif  // COMPONENTS_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
     71