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

Side by Side Diff: chrome/browser/media_gallery/media_storage_util.cc

Issue 10873072: Rename SystemMonitor's MediaDevice calls to RemovableStorage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // chrome::MediaStorageUtil implementation. 5 // chrome::MediaStorageUtil implementation.
6 6
7 #include "chrome/browser/media_gallery/media_storage_util.h" 7 #include "chrome/browser/media_gallery/media_storage_util.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/system_monitor/system_monitor.h" 14 #include "base/system_monitor/system_monitor.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 using base::SystemMonitor; 17 using base::SystemMonitor;
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 namespace chrome { 20 namespace chrome {
21 21
22 namespace { 22 namespace {
23 23
24 typedef std::vector<SystemMonitor::MediaDeviceInfo> MediaDevicesInfo; 24 typedef std::vector<SystemMonitor::RemovableStorageInfo> RemovableStorageInfo;
25 25
26 // Prefix constants for different device id spaces. 26 // Prefix constants for different device id spaces.
27 const char kUsbMassStorageWithDCIMPrefix[] = "dcim:"; 27 const char kUsbMassStorageWithDCIMPrefix[] = "dcim:";
28 const char kUsbMassStorageNoDCIMPrefix[] = "usb:"; 28 const char kUsbMassStorageNoDCIMPrefix[] = "usb:";
29 const char kOtherMassStoragePrefix[] = "path:"; 29 const char kOtherMassStoragePrefix[] = "path:";
30 const char kUsbMtpPrefix[] = "mtp:"; 30 const char kUsbMtpPrefix[] = "mtp:";
31 31
32 void EmptyPathIsFalseCallback(const MediaStorageUtil::BoolCallback& callback, 32 void EmptyPathIsFalseCallback(const MediaStorageUtil::BoolCallback& callback,
33 FilePath path) { 33 FilePath path) {
34 callback.Run(!path.empty()); 34 callback.Run(!path.empty());
35 } 35 }
36 36
37 void ValidatePathOnFileThread( 37 void ValidatePathOnFileThread(
38 const FilePath& path, const MediaStorageUtil::FilePathCallback& callback) { 38 const FilePath& path, const MediaStorageUtil::FilePathCallback& callback) {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
40 FilePath result; 40 FilePath result;
41 if (file_util::PathExists(path)) 41 if (file_util::PathExists(path))
42 result = path; 42 result = path;
43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 43 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
44 base::Bind(callback, path)); 44 base::Bind(callback, path));
45 } 45 }
46 46
47 FilePath::StringType FindMediaDeviceLocationById(const std::string& device_id) { 47 FilePath::StringType FindRemovableStorageLocationById(
48 MediaDevicesInfo media_devices = 48 const std::string& device_id) {
49 SystemMonitor::Get()->GetAttachedMediaDevices(); 49 RemovableStorageInfo media_devices =
50 for (MediaDevicesInfo::const_iterator it = media_devices.begin(); 50 SystemMonitor::Get()->GetAttachedRemovableStorage();
51 for (RemovableStorageInfo::const_iterator it = media_devices.begin();
51 it != media_devices.end(); 52 it != media_devices.end();
52 ++it) { 53 ++it) {
53 if (it->unique_id == device_id) 54 if (it->device_id == device_id)
54 return it->location; 55 return it->location;
55 } 56 }
56 return FilePath::StringType(); 57 return FilePath::StringType();
57 } 58 }
58 59
59 // TODO(vandebo) use FilePath::AppendRelativePath instead 60 // TODO(vandebo) use FilePath::AppendRelativePath instead
60 // Make |path| a relative path, i.e. strip the drive letter and leading /. 61 // Make |path| a relative path, i.e. strip the drive letter and leading /.
61 FilePath MakePathRelative(const FilePath& path) { 62 FilePath MakePathRelative(const FilePath& path) {
62 if (!path.IsAbsolute()) 63 if (!path.IsAbsolute())
63 return path; 64 return path;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 std::string unique_id; 145 std::string unique_id;
145 if (!CrackDeviceId(device_id, &type, &unique_id)) { 146 if (!CrackDeviceId(device_id, &type, &unique_id)) {
146 callback.Run(false); 147 callback.Run(false);
147 return; 148 return;
148 } 149 }
149 150
150 switch (type) { 151 switch (type) {
151 case USB_MTP: // Fall through 152 case USB_MTP: // Fall through
152 case USB_MASS_STORAGE_WITH_DCIM: 153 case USB_MASS_STORAGE_WITH_DCIM:
153 // We should be able to find media devices in SystemMonitor. 154 // We should be able to find media devices in SystemMonitor.
154 callback.Run(!FindMediaDeviceLocationById(device_id).empty()); 155 callback.Run(!FindRemovableStorageLocationById(device_id).empty());
155 break; 156 break;
156 case USB_MASS_STORAGE_NO_DCIM: 157 case USB_MASS_STORAGE_NO_DCIM:
157 FindUSBDeviceById(unique_id, 158 FindUSBDeviceById(unique_id,
158 base::Bind(&EmptyPathIsFalseCallback, callback)); 159 base::Bind(&EmptyPathIsFalseCallback, callback));
159 break; 160 break;
160 case OTHER_MASS_STORAGE: 161 case OTHER_MASS_STORAGE:
161 // For this type, the unique_id is the path. 162 // For this type, the unique_id is the path.
162 BrowserThread::PostTask( 163 BrowserThread::PostTask(
163 BrowserThread::FILE, FROM_HERE, 164 BrowserThread::FILE, FROM_HERE,
164 base::Bind(&ValidatePathOnFileThread, 165 base::Bind(&ValidatePathOnFileThread,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 FindUSBDeviceById(unique_id, callback); 204 FindUSBDeviceById(unique_id, callback);
204 break; 205 break;
205 case OTHER_MASS_STORAGE: 206 case OTHER_MASS_STORAGE:
206 // For this type, the unique_id is the path. 207 // For this type, the unique_id is the path.
207 BrowserThread::PostTask( 208 BrowserThread::PostTask(
208 BrowserThread::FILE, FROM_HERE, 209 BrowserThread::FILE, FROM_HERE,
209 base::Bind(&ValidatePathOnFileThread, 210 base::Bind(&ValidatePathOnFileThread,
210 FilePath::FromUTF8Unsafe(unique_id), callback)); 211 FilePath::FromUTF8Unsafe(unique_id), callback));
211 break; 212 break;
212 case USB_MASS_STORAGE_WITH_DCIM: 213 case USB_MASS_STORAGE_WITH_DCIM:
213 callback.Run(FilePath(FindMediaDeviceLocationById(device_id))); 214 callback.Run(FilePath(FindRemovableStorageLocationById(device_id)));
214 break; 215 break;
215 } 216 }
216 NOTREACHED(); 217 NOTREACHED();
217 callback.Run(FilePath()); 218 callback.Run(FilePath());
218 } 219 }
219 220
220 MediaStorageUtil::MediaStorageUtil() {} 221 MediaStorageUtil::MediaStorageUtil() {}
221 222
222 // static 223 // static
223 void MediaStorageUtil::FindUSBDeviceById(const std::string& unique_id, 224 void MediaStorageUtil::FindUSBDeviceById(const std::string& unique_id,
224 const FilePathCallback& callback) { 225 const FilePathCallback& callback) {
225 // TODO(vandebo) This needs to be implemented per platform. 226 // TODO(vandebo) This needs to be implemented per platform.
226 // Type is USB_MASS_STORAGE_NO_DCIM, so it's a device possibly mounted 227 // Type is USB_MASS_STORAGE_NO_DCIM, so it's a device possibly mounted
227 // somewhere... 228 // somewhere...
228 NOTREACHED(); 229 NOTREACHED();
229 callback.Run(FilePath()); 230 callback.Run(FilePath());
230 } 231 }
231 232
232 } // namespace chrome 233 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/media_gallery/media_file_system_registry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698