Fix build break
[chromium-blink-merge.git] / chrome / browser / storage_monitor / media_storage_util.h
blob87f1bb2789fbc78f2585ff155f61fef22f2cc15b
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 // chrome::MediaStorageUtil provides information about storage devices attached
6 // to the computer.
8 #ifndef CHROME_BROWSER_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
9 #define CHROME_BROWSER_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_
11 #include <set>
12 #include <string>
14 #include "base/basictypes.h"
15 #include "base/callback_forward.h"
16 #include "base/files/file_path.h"
17 #include "chrome/browser/storage_monitor/storage_monitor.h"
19 namespace chrome {
21 class MediaStorageUtil {
22 public:
23 enum Type {
24 // A removable mass storage device with a DCIM directory.
25 REMOVABLE_MASS_STORAGE_WITH_DCIM,
26 // A removable mass storage device without a DCIM directory.
27 REMOVABLE_MASS_STORAGE_NO_DCIM,
28 // A fixed mass storage device.
29 FIXED_MASS_STORAGE,
30 // A MTP or PTP device.
31 MTP_OR_PTP,
32 // A Mac ImageCapture device.
33 MAC_IMAGE_CAPTURE,
36 typedef std::set<std::string /*device id*/> DeviceIdSet;
37 typedef base::Callback<void(bool)> BoolCallback;
40 // Check if the file system at the passed mount point looks like a media
41 // device using the existence of DCIM directory.
42 // Returns true if it looks like a media device, otherwise returns false.
43 // Mac OS X behaves similarly, but this is not the only heuristic it uses.
44 // TODO(vandebo) Try to figure out how Mac OS X decides this, and rename
45 // if additional OS X heuristic is implemented.
46 static bool HasDcim(const base::FilePath& mount_point);
48 // Constructs the device product name from |vendor_name| and |model_name|.
49 static string16 GetFullProductName(const std::string& vendor_name,
50 const std::string& model_name);
52 // Constructs the display name for device from |storage_size_in_bytes| and
53 // |name|.
54 static string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes,
55 const string16& name);
57 // Returns a device id given properties of the device. A prefix dependent on
58 // |type| is added so |unique_id| need only be unique within the given type.
59 // Returns an empty string if an invalid type is passed in.
60 static std::string MakeDeviceId(Type type, const std::string& unique_id);
62 // Extracts the device |type| and |unique_id| from |device_id|. Returns false
63 // if the device_id isn't properly formatted.
64 static bool CrackDeviceId(const std::string& device_id,
65 Type* type, std::string* unique_id);
67 // Looks inside |device_id| to determine if it is a media device
68 // (type is REMOVABLE_MASS_STORAGE_WITH_DCIM or MTP_OR_PTP).
69 static bool IsMediaDevice(const std::string& device_id);
71 // Looks inside |device_id| to determine if it is a media device
72 // (type isn't FIXED_MASS_STORAGE).
73 static bool IsRemovableDevice(const std::string& device_id);
75 // Looks inside |device_id| to determine if it is a mass storage device
76 // (type isn't MTP_OR_PTP).
77 static bool IsMassStorageDevice(const std::string& device_id);
79 // Returns true if we will be able to create a filesystem for this device.
80 static bool CanCreateFileSystem(const std::string& device_id,
81 const base::FilePath& path);
83 // Determines if the device is attached to the computer.
84 static void IsDeviceAttached(const std::string& device_id,
85 const BoolCallback& callback);
87 // Removes disconnected devices from |devices| and then calls |done|.
88 static void FilterAttachedDevices(DeviceIdSet* devices,
89 const base::Closure& done);
91 // Given |path|, fill in |device_info|, and |relative_path|
92 // (from the root of the device) if they are not NULL.
93 static bool GetDeviceInfoFromPath(const base::FilePath& path,
94 StorageInfo* device_info,
95 base::FilePath* relative_path);
97 // Get a base::FilePath for the given |device_id|. If the device isn't a mass
98 // storage type, the base::FilePath will be empty. This does not check that
99 // the device is connected.
100 static base::FilePath FindDevicePathById(const std::string& device_id);
102 // Record device information histogram for the given |device_uuid| and
103 // |device_name|. |mass_storage| indicates whether the current device is a
104 // mass storage device, as defined by IsMassStorageDevice().
105 static void RecordDeviceInfoHistogram(bool mass_storage,
106 const std::string& device_uuid,
107 const string16& device_name);
109 private:
110 DISALLOW_IMPLICIT_CONSTRUCTORS(MediaStorageUtil);
113 } // namespace chrome
115 #endif // CHROME_BROWSER_STORAGE_MONITOR_MEDIA_STORAGE_UTIL_H_