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

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

Issue 11573048: [Media Galleries] Move RemovableStorageInfo notifications to chrome namespace (part 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing up tests Created 7 years, 11 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
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/system_monitor/media_storage_util.h" 7 #include "chrome/browser/system_monitor/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/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/system_monitor/system_monitor.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/system_monitor/media_device_notifications_utils.h" 16 #include "chrome/browser/system_monitor/media_device_notifications_utils.h"
18 #include "chrome/browser/system_monitor/removable_storage_notifications.h" 17 #include "chrome/browser/system_monitor/removable_storage_notifications.h"
19 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
20 19
21 #if defined(OS_LINUX) // Implies OS_CHROMEOS 20 #if defined(OS_LINUX) // Implies OS_CHROMEOS
22 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ linux.h" 21 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ linux.h"
23 #endif 22 #endif
24 23
25 using base::SystemMonitor;
26 using content::BrowserThread; 24 using content::BrowserThread;
27 25
28 const char kRootPath[] = "/"; 26 const char kRootPath[] = "/";
29 27
30 namespace chrome { 28 namespace chrome {
31 29
32 namespace { 30 namespace {
33 31
34 // MediaDeviceNotification.DeviceInfo histogram values. 32 // MediaDeviceNotification.DeviceInfo histogram values.
35 enum DeviceInfoHistogramBuckets { 33 enum DeviceInfoHistogramBuckets {
(...skipping 20 matching lines...) Expand all
56 FilePath* relative_path) = NULL; 54 FilePath* relative_path) = NULL;
57 55
58 void ValidatePathOnFileThread( 56 void ValidatePathOnFileThread(
59 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) { 57 const FilePath& path, const MediaStorageUtil::BoolCallback& callback) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
61 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 59 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
62 base::Bind(callback, file_util::PathExists(path))); 60 base::Bind(callback, file_util::PathExists(path)));
63 } 61 }
64 62
65 bool IsRemovableStorageAttached(const std::string& id) { 63 bool IsRemovableStorageAttached(const std::string& id) {
66 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = 64 std::vector<RemovableStorageNotifications::StorageInfo> devices =
67 SystemMonitor::Get()->GetAttachedRemovableStorage(); 65 RemovableStorageNotifications::GetInstance()->GetAttachedStorage();
68 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = 66 for (std::vector<RemovableStorageNotifications::StorageInfo>::
vandebo (ex-Chrome) 2013/01/24 19:19:10 nit: add a typedef for the vector<StorageInfo> typ
Greg Billock 2013/01/24 20:46:03 Yeah, I thought about this. I don't like typedefs,
vandebo (ex-Chrome) 2013/01/24 23:39:01 I'm not the biggest fan of typedefs, but when it s
Greg Billock 2013/01/25 20:01:21 Done.
69 media_devices.begin(); 67 const_iterator it = devices.begin();
70 it != media_devices.end(); 68 it != devices.end();
71 ++it) { 69 ++it) {
72 if (it->device_id == id) 70 if (it->device_id == id)
73 return true; 71 return true;
74 } 72 }
75 return false; 73 return false;
76 } 74 }
77 75
78 FilePath::StringType FindRemovableStorageLocationById( 76 FilePath::StringType FindRemovableStorageLocationById(
79 const std::string& device_id) { 77 const std::string& device_id) {
80 std::vector<SystemMonitor::RemovableStorageInfo> media_devices = 78 std::vector<RemovableStorageNotifications::StorageInfo> devices =
81 SystemMonitor::Get()->GetAttachedRemovableStorage(); 79 RemovableStorageNotifications::GetInstance()->GetAttachedStorage();
82 for (std::vector<SystemMonitor::RemovableStorageInfo>::const_iterator it = 80 for (std::vector<RemovableStorageNotifications::StorageInfo>::
83 media_devices.begin(); 81 const_iterator it = devices.begin();
84 it != media_devices.end(); 82 it != devices.end();
85 ++it) { 83 ++it) {
86 if (it->device_id == device_id) 84 if (it->device_id == device_id)
87 return it->location; 85 return it->location;
88 } 86 }
89 return FilePath::StringType(); 87 return FilePath::StringType();
90 } 88 }
91 89
92 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { 90 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
94 MediaStorageUtil::DeviceIdSet missing_devices; 92 MediaStorageUtil::DeviceIdSet missing_devices;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (type == FIXED_MASS_STORAGE) { 233 if (type == FIXED_MASS_STORAGE) {
236 // For this type, the unique_id is the path. 234 // For this type, the unique_id is the path.
237 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 235 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
238 base::Bind(&ValidatePathOnFileThread, 236 base::Bind(&ValidatePathOnFileThread,
239 FilePath::FromUTF8Unsafe(unique_id), 237 FilePath::FromUTF8Unsafe(unique_id),
240 callback)); 238 callback));
241 } else { 239 } else {
242 DCHECK(type == MTP_OR_PTP || 240 DCHECK(type == MTP_OR_PTP ||
243 type == REMOVABLE_MASS_STORAGE_WITH_DCIM || 241 type == REMOVABLE_MASS_STORAGE_WITH_DCIM ||
244 type == REMOVABLE_MASS_STORAGE_NO_DCIM); 242 type == REMOVABLE_MASS_STORAGE_NO_DCIM);
245 // We should be able to find removable storage in SystemMonitor. 243 // We should be able to find removable storage.
246 callback.Run(IsRemovableStorageAttached(device_id)); 244 callback.Run(IsRemovableStorageAttached(device_id));
247 } 245 }
248 } 246 }
249 247
250 // static 248 // static
251 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices, 249 void MediaStorageUtil::FilterAttachedDevices(DeviceIdSet* devices,
252 const base::Closure& done) { 250 const base::Closure& done) {
253 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { 251 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) {
254 FilterAttachedDevicesOnFileThread(devices); 252 FilterAttachedDevicesOnFileThread(devices);
255 done.Run(); 253 done.Run();
(...skipping 14 matching lines...) Expand all
270 if (!path.IsAbsolute()) 268 if (!path.IsAbsolute())
271 return false; 269 return false;
272 270
273 if (g_test_get_device_info_from_path_function) { 271 if (g_test_get_device_info_from_path_function) {
274 return g_test_get_device_info_from_path_function(path, device_id, 272 return g_test_get_device_info_from_path_function(path, device_id,
275 device_name, 273 device_name,
276 relative_path); 274 relative_path);
277 } 275 }
278 276
279 bool found_device = false; 277 bool found_device = false;
280 base::SystemMonitor::RemovableStorageInfo device_info; 278 RemovableStorageNotifications::StorageInfo device_info;
281 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) 279 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
282 RemovableStorageNotifications* notifier = 280 RemovableStorageNotifications* notifier =
283 RemovableStorageNotifications::GetInstance(); 281 RemovableStorageNotifications::GetInstance();
284 found_device = notifier->GetDeviceInfoForPath(path, &device_info); 282 found_device = notifier->GetDeviceInfoForPath(path, &device_info);
285 #endif 283 #endif
286 284
287 #if defined(OS_LINUX) 285 #if defined(OS_LINUX)
288 if (!found_device) { 286 if (!found_device) {
289 MediaTransferProtocolDeviceObserverLinux* mtp_manager = 287 MediaTransferProtocolDeviceObserverLinux* mtp_manager =
290 MediaTransferProtocolDeviceObserverLinux::GetInstance(); 288 MediaTransferProtocolDeviceObserverLinux::GetInstance();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 DEVICE_INFO_BUCKET_BOUNDARY); 381 DEVICE_INFO_BUCKET_BOUNDARY);
384 } 382 }
385 383
386 // static 384 // static
387 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting( 385 void MediaStorageUtil::SetGetDeviceInfoFromPathFunctionForTesting(
388 GetDeviceInfoFromPathFunction function) { 386 GetDeviceInfoFromPathFunction function) {
389 g_test_get_device_info_from_path_function = function; 387 g_test_get_device_info_from_path_function = function;
390 } 388 }
391 389
392 } // namespace chrome 390 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698