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

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

Issue 12544005: Consolidate storage_monitor/MediaDeviceNotificationsUtils into MediaStorageUtil. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac apply patch Created 7 years, 9 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 // chromeos::StorageMonitorCros implementation. 5 // chromeos::StorageMonitorCros implementation.
6 6
7 #include "chrome/browser/storage_monitor/storage_monitor_chromeos.h" 7 #include "chrome/browser/storage_monitor/storage_monitor_chromeos.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h"
17 #include "chrome/browser/storage_monitor/media_storage_util.h" 16 #include "chrome/browser/storage_monitor/media_storage_util.h"
18 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h" 17 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h"
19 #include "chrome/browser/storage_monitor/removable_device_constants.h" 18 #include "chrome/browser/storage_monitor/removable_device_constants.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
22 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" 21 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h"
23 22
24 namespace chromeos { 23 namespace chromeos {
25 24
26 namespace { 25 namespace {
(...skipping 20 matching lines...) Expand all
47 if (storage_label) 46 if (storage_label)
48 *storage_label = UTF8ToUTF16(device_label); 47 *storage_label = UTF8ToUTF16(device_label);
49 if (vendor_name) 48 if (vendor_name)
50 *vendor_name = UTF8ToUTF16(disk.vendor_name()); 49 *vendor_name = UTF8ToUTF16(disk.vendor_name());
51 if (model_name) 50 if (model_name)
52 *model_name = UTF8ToUTF16(disk.product_name()); 51 *model_name = UTF8ToUTF16(disk.product_name());
53 52
54 if (!device_label.empty() && IsStringUTF8(device_label)) 53 if (!device_label.empty() && IsStringUTF8(device_label))
55 return UTF8ToUTF16(device_label); 54 return UTF8ToUTF16(device_label);
56 55
57 return chrome::GetFullProductName(disk.vendor_name(), disk.product_name()); 56 return chrome::MediaStorageUtil::GetFullProductName(disk.vendor_name(),
57 disk.product_name());
58 } 58 }
59 59
60 // Constructs a device id using uuid or manufacturer (vendor and product) id 60 // Constructs a device id using uuid or manufacturer (vendor and product) id
61 // details. 61 // details.
62 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { 62 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
63 std::string uuid = disk.fs_uuid(); 63 std::string uuid = disk.fs_uuid();
64 if (!uuid.empty()) 64 if (!uuid.empty())
65 return chrome::kFSUniqueIdPrefix + uuid; 65 return chrome::kFSUniqueIdPrefix + uuid;
66 66
67 // If one of the vendor or product information is missing, its value in the 67 // If one of the vendor or product information is missing, its value in the
(...skipping 30 matching lines...) Expand all
98 vendor_name, model_name); 98 vendor_name, model_name);
99 99
100 if (storage_size_in_bytes) 100 if (storage_size_in_bytes)
101 *storage_size_in_bytes = disk->total_size_in_bytes(); 101 *storage_size_in_bytes = disk->total_size_in_bytes();
102 return true; 102 return true;
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 using content::BrowserThread; 107 using content::BrowserThread;
108 using chrome::StorageInfo;
108 109
109 StorageMonitorCros::StorageMonitorCros() { 110 StorageMonitorCros::StorageMonitorCros() {
110 } 111 }
111 112
112 StorageMonitorCros::~StorageMonitorCros() { 113 StorageMonitorCros::~StorageMonitorCros() {
113 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { 114 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
114 device::MediaTransferProtocolManager::Shutdown(); 115 device::MediaTransferProtocolManager::Shutdown();
115 } 116 }
116 117
117 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 118 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 199 }
199 200
200 void StorageMonitorCros::OnFormatEvent( 201 void StorageMonitorCros::OnFormatEvent(
201 disks::DiskMountManager::FormatEvent event, 202 disks::DiskMountManager::FormatEvent event,
202 FormatError error_code, 203 FormatError error_code,
203 const std::string& device_path) { 204 const std::string& device_path) {
204 } 205 }
205 206
206 bool StorageMonitorCros::GetStorageInfoForPath( 207 bool StorageMonitorCros::GetStorageInfoForPath(
207 const base::FilePath& path, 208 const base::FilePath& path,
208 chrome::StorageInfo* device_info) const { 209 StorageInfo* device_info) const {
209 if (!path.IsAbsolute()) 210 if (!path.IsAbsolute())
210 return false; 211 return false;
211 212
212 base::FilePath current = path; 213 base::FilePath current = path;
213 while (!ContainsKey(mount_map_, current.value()) && 214 while (!ContainsKey(mount_map_, current.value()) &&
214 current != current.DirName()) { 215 current != current.DirName()) {
215 current = current.DirName(); 216 current = current.DirName();
216 } 217 }
217 218
218 MountMap::const_iterator info_it = mount_map_.find(current.value()); 219 MountMap::const_iterator info_it = mount_map_.find(current.value());
219 if (info_it == mount_map_.end()) 220 if (info_it == mount_map_.end())
220 return false; 221 return false;
221 222
222 if (device_info) 223 if (device_info)
223 *device_info = info_it->second; 224 *device_info = info_it->second;
224 return true; 225 return true;
225 } 226 }
226 227
227 uint64 StorageMonitorCros::GetStorageSize( 228 uint64 StorageMonitorCros::GetStorageSize(
228 const std::string& device_location) const { 229 const std::string& device_location) const {
229 MountMap::const_iterator info_it = mount_map_.find(device_location); 230 MountMap::const_iterator info_it = mount_map_.find(device_location);
230 return (info_it != mount_map_.end()) ? 231 return (info_it != mount_map_.end()) ?
231 info_it->second.total_size_in_bytes : 0; 232 info_it->second.total_size_in_bytes : 0;
232 } 233 }
233 234
234 void StorageMonitorCros::CheckMountedPathOnFileThread( 235 void StorageMonitorCros::CheckMountedPathOnFileThread(
235 const disks::DiskMountManager::MountPointInfo& mount_info) { 236 const disks::DiskMountManager::MountPointInfo& mount_info) {
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
237 238
238 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); 239 bool has_dcim = chrome::MediaStorageUtil::HasDcim(mount_info.mount_path);
239 240
240 BrowserThread::PostTask( 241 BrowserThread::PostTask(
241 BrowserThread::UI, FROM_HERE, 242 BrowserThread::UI, FROM_HERE,
242 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this, 243 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this,
243 mount_info, has_dcim)); 244 mount_info, has_dcim));
244 } 245 }
245 246
246 void StorageMonitorCros::AddMountedPathOnUIThread( 247 void StorageMonitorCros::AddMountedPathOnUIThread(
247 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { 248 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) {
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 23 matching lines...) Expand all
272 device_label); 273 device_label);
273 if (unique_id.empty() || device_label.empty()) 274 if (unique_id.empty() || device_label.empty())
274 return; 275 return;
275 276
276 chrome::MediaStorageUtil::Type type = has_dcim ? 277 chrome::MediaStorageUtil::Type type = has_dcim ?
277 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 278 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
278 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 279 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
279 280
280 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 281 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
281 unique_id); 282 unique_id);
283
282 chrome::StorageInfo object_info( 284 chrome::StorageInfo object_info(
283 device_id, 285 device_id,
284 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), 286 chrome::MediaStorageUtil::GetDisplayNameForDevice(storage_size_in_bytes,
287 device_label),
285 mount_info.mount_path, 288 mount_info.mount_path,
286 storage_label, 289 storage_label,
287 vendor_name, 290 vendor_name,
288 model_name, 291 model_name,
289 storage_size_in_bytes); 292 storage_size_in_bytes);
290 293
291 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 294 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
292 295
293 receiver()->ProcessAttach(object_info); 296 receiver()->ProcessAttach(object_info);
294 } 297 }
295 298
296 } // namespace chromeos 299 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/storage_monitor/media_storage_util_unittest.cc ('k') | chrome/browser/storage_monitor/storage_monitor_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698