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

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 race condition in unit test. 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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h"
16 #include "chrome/browser/storage_monitor/media_storage_util.h" 15 #include "chrome/browser/storage_monitor/media_storage_util.h"
17 #include "chrome/browser/storage_monitor/removable_device_constants.h" 16 #include "chrome/browser/storage_monitor/removable_device_constants.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 18
20 namespace chromeos { 19 namespace chromeos {
21 20
22 namespace { 21 namespace {
23 22
24 // Constructs a device name using label or manufacturer (vendor and product) 23 // Constructs a device name using label or manufacturer (vendor and product)
25 // name details. 24 // name details.
(...skipping 17 matching lines...) Expand all
43 if (storage_label) 42 if (storage_label)
44 *storage_label = UTF8ToUTF16(device_label); 43 *storage_label = UTF8ToUTF16(device_label);
45 if (vendor_name) 44 if (vendor_name)
46 *vendor_name = UTF8ToUTF16(disk.vendor_name()); 45 *vendor_name = UTF8ToUTF16(disk.vendor_name());
47 if (model_name) 46 if (model_name)
48 *model_name = UTF8ToUTF16(disk.product_name()); 47 *model_name = UTF8ToUTF16(disk.product_name());
49 48
50 if (!device_label.empty() && IsStringUTF8(device_label)) 49 if (!device_label.empty() && IsStringUTF8(device_label))
51 return UTF8ToUTF16(device_label); 50 return UTF8ToUTF16(device_label);
52 51
53 return chrome::GetFullProductName(disk.vendor_name(), disk.product_name()); 52 return chrome::MediaStorageUtil::GetFullProductName(disk.vendor_name(),
53 disk.product_name());
54 } 54 }
55 55
56 // Constructs a device id using uuid or manufacturer (vendor and product) id 56 // Constructs a device id using uuid or manufacturer (vendor and product) id
57 // details. 57 // details.
58 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { 58 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
59 std::string uuid = disk.fs_uuid(); 59 std::string uuid = disk.fs_uuid();
60 if (!uuid.empty()) 60 if (!uuid.empty())
61 return chrome::kFSUniqueIdPrefix + uuid; 61 return chrome::kFSUniqueIdPrefix + uuid;
62 62
63 // If one of the vendor or product information is missing, its value in the 63 // If one of the vendor or product information is missing, its value in the
(...skipping 30 matching lines...) Expand all
94 vendor_name, model_name); 94 vendor_name, model_name);
95 95
96 if (storage_size_in_bytes) 96 if (storage_size_in_bytes)
97 *storage_size_in_bytes = disk->total_size_in_bytes(); 97 *storage_size_in_bytes = disk->total_size_in_bytes();
98 return true; 98 return true;
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 using content::BrowserThread; 103 using content::BrowserThread;
104 using chrome::StorageInfo;
104 105
105 StorageMonitorCros::StorageMonitorCros() { 106 StorageMonitorCros::StorageMonitorCros() {
106 DCHECK(disks::DiskMountManager::GetInstance()); 107 DCHECK(disks::DiskMountManager::GetInstance());
107 disks::DiskMountManager::GetInstance()->AddObserver(this); 108 disks::DiskMountManager::GetInstance()->AddObserver(this);
108 CheckExistingMountPointsOnUIThread(); 109 CheckExistingMountPointsOnUIThread();
109 } 110 }
110 111
111 StorageMonitorCros::~StorageMonitorCros() { 112 StorageMonitorCros::~StorageMonitorCros() {
112 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 113 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
113 if (manager) { 114 if (manager) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 179 }
179 180
180 void StorageMonitorCros::OnFormatEvent( 181 void StorageMonitorCros::OnFormatEvent(
181 disks::DiskMountManager::FormatEvent event, 182 disks::DiskMountManager::FormatEvent event,
182 FormatError error_code, 183 FormatError error_code,
183 const std::string& device_path) { 184 const std::string& device_path) {
184 } 185 }
185 186
186 bool StorageMonitorCros::GetStorageInfoForPath( 187 bool StorageMonitorCros::GetStorageInfoForPath(
187 const base::FilePath& path, 188 const base::FilePath& path,
188 chrome::StorageInfo* device_info) const { 189 StorageInfo* device_info) const {
189 if (!path.IsAbsolute()) 190 if (!path.IsAbsolute())
190 return false; 191 return false;
191 192
192 base::FilePath current = path; 193 base::FilePath current = path;
193 while (!ContainsKey(mount_map_, current.value()) && 194 while (!ContainsKey(mount_map_, current.value()) &&
194 current != current.DirName()) { 195 current != current.DirName()) {
195 current = current.DirName(); 196 current = current.DirName();
196 } 197 }
197 198
198 MountMap::const_iterator info_it = mount_map_.find(current.value()); 199 MountMap::const_iterator info_it = mount_map_.find(current.value());
199 if (info_it == mount_map_.end()) 200 if (info_it == mount_map_.end())
200 return false; 201 return false;
201 202
202 if (device_info) 203 if (device_info)
203 *device_info = info_it->second; 204 *device_info = info_it->second;
204 return true; 205 return true;
205 } 206 }
206 207
207 uint64 StorageMonitorCros::GetStorageSize( 208 uint64 StorageMonitorCros::GetStorageSize(
208 const std::string& device_location) const { 209 const std::string& device_location) const {
209 MountMap::const_iterator info_it = mount_map_.find(device_location); 210 MountMap::const_iterator info_it = mount_map_.find(device_location);
210 return (info_it != mount_map_.end()) ? 211 return (info_it != mount_map_.end()) ?
211 info_it->second.total_size_in_bytes : 0; 212 info_it->second.total_size_in_bytes : 0;
212 } 213 }
213 214
214 void StorageMonitorCros::CheckMountedPathOnFileThread( 215 void StorageMonitorCros::CheckMountedPathOnFileThread(
215 const disks::DiskMountManager::MountPointInfo& mount_info) { 216 const disks::DiskMountManager::MountPointInfo& mount_info) {
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
217 218
218 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); 219 bool has_dcim = chrome::MediaStorageUtil::HasDcim(mount_info.mount_path);
219 220
220 BrowserThread::PostTask( 221 BrowserThread::PostTask(
221 BrowserThread::UI, FROM_HERE, 222 BrowserThread::UI, FROM_HERE,
222 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this, 223 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this,
223 mount_info, has_dcim)); 224 mount_info, has_dcim));
224 } 225 }
225 226
226 void StorageMonitorCros::AddMountedPathOnUIThread( 227 void StorageMonitorCros::AddMountedPathOnUIThread(
227 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { 228 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 23 matching lines...) Expand all
252 device_label); 253 device_label);
253 if (unique_id.empty() || device_label.empty()) 254 if (unique_id.empty() || device_label.empty())
254 return; 255 return;
255 256
256 chrome::MediaStorageUtil::Type type = has_dcim ? 257 chrome::MediaStorageUtil::Type type = has_dcim ?
257 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 258 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
258 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 259 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
259 260
260 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 261 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
261 unique_id); 262 unique_id);
263
262 chrome::StorageInfo object_info( 264 chrome::StorageInfo object_info(
263 device_id, 265 device_id,
264 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), 266 chrome::MediaStorageUtil::GetDisplayNameForDevice(storage_size_in_bytes,
267 device_label),
265 mount_info.mount_path, 268 mount_info.mount_path,
266 storage_label, 269 storage_label,
267 vendor_name, 270 vendor_name,
268 model_name, 271 model_name,
269 storage_size_in_bytes); 272 storage_size_in_bytes);
270 273
271 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 274 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
272 275
273 receiver()->ProcessAttach(object_info); 276 receiver()->ProcessAttach(object_info);
274 } 277 }
275 278
276 } // namespace chromeos 279 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698