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

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

Issue 15988011: Refine StorageMonitor storage device getter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 6 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
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 #include "chrome/browser/storage_monitor/media_storage_util.h" 5 #include "chrome/browser/storage_monitor/media_storage_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const base::FilePath& path, 43 const base::FilePath& path,
44 const MediaStorageUtil::BoolCallback& callback) { 44 const MediaStorageUtil::BoolCallback& callback) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
47 base::Bind(callback, file_util::PathExists(path))); 47 base::Bind(callback, file_util::PathExists(path)));
48 } 48 }
49 49
50 typedef std::vector<StorageInfo> StorageInfoList; 50 typedef std::vector<StorageInfo> StorageInfoList;
51 51
52 bool IsRemovableStorageAttached(const std::string& id) { 52 bool IsRemovableStorageAttached(const std::string& id) {
53 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); 53 StorageInfoList devices =
54 StorageMonitor::GetInstance()->GetAllAvailableStorages();
54 for (StorageInfoList::const_iterator it = devices.begin(); 55 for (StorageInfoList::const_iterator it = devices.begin();
55 it != devices.end(); ++it) { 56 it != devices.end(); ++it) {
56 if (it->device_id() == id) 57 if (it->device_id() == id && StorageInfo::IsRemovableDevice(id))
Lei Zhang 2013/06/06 10:15:09 Since |id| is known already, you can check if it i
Haojian Wu 2013/06/06 11:24:02 Done.
57 return true; 58 return true;
58 } 59 }
59 return false; 60 return false;
60 } 61 }
61 62
62 base::FilePath::StringType FindRemovableStorageLocationById( 63 base::FilePath::StringType FindRemovableStorageLocationById(
63 const std::string& device_id) { 64 const std::string& device_id) {
64 StorageInfoList devices = StorageMonitor::GetInstance()->GetAttachedStorage(); 65 StorageInfoList devices =
66 StorageMonitor::GetInstance()->GetAllAvailableStorages();
65 for (StorageInfoList::const_iterator it = devices.begin(); 67 for (StorageInfoList::const_iterator it = devices.begin();
66 it != devices.end(); ++it) { 68 it != devices.end(); ++it) {
67 if (it->device_id() == device_id) 69 if (it->device_id() == device_id
70 && StorageInfo::IsRemovableDevice(device_id))
68 return it->location(); 71 return it->location();
69 } 72 }
70 return base::FilePath::StringType(); 73 return base::FilePath::StringType();
71 } 74 }
72 75
73 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) { 76 void FilterAttachedDevicesOnFileThread(MediaStorageUtil::DeviceIdSet* devices) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
75 MediaStorageUtil::DeviceIdSet missing_devices; 78 MediaStorageUtil::DeviceIdSet missing_devices;
76 79
77 for (MediaStorageUtil::DeviceIdSet::const_iterator it = devices->begin(); 80 for (MediaStorageUtil::DeviceIdSet::const_iterator it = devices->begin();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 static_cast<enum DeviceInfoHistogramBuckets>(event_number); 246 static_cast<enum DeviceInfoHistogramBuckets>(event_number);
244 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { 247 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) {
245 NOTREACHED(); 248 NOTREACHED();
246 return; 249 return;
247 } 250 }
248 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, 251 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event,
249 DEVICE_INFO_BUCKET_BOUNDARY); 252 DEVICE_INFO_BUCKET_BOUNDARY);
250 } 253 }
251 254
252 } // namespace chrome 255 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698