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

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: another chromeos fix 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.
26 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { 25 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) {
27 if (disk.device_type() == DEVICE_TYPE_SD) { 26 if (disk.device_type() == DEVICE_TYPE_SD) {
28 // Mount path of an SD card will be one of the following: 27 // Mount path of an SD card will be one of the following:
29 // (1) /media/removable/<volume_label> 28 // (1) /media/removable/<volume_label>
30 // (2) /media/removable/SD Card 29 // (2) /media/removable/SD Card
31 // If the volume label is available, mount path will be (1) else (2). 30 // If the volume label is available, mount path will be (1) else (2).
32 base::FilePath mount_point(disk.mount_path()); 31 base::FilePath mount_point(disk.mount_path());
33 const string16 display_name(mount_point.BaseName().LossyDisplayName()); 32 const string16 display_name(mount_point.BaseName().LossyDisplayName());
34 if (!display_name.empty()) 33 if (!display_name.empty())
35 return display_name; 34 return display_name;
36 } 35 }
37 36
38 const std::string& device_label = disk.device_label(); 37 const std::string& device_label = disk.device_label();
39 if (!device_label.empty() && IsStringUTF8(device_label)) 38 if (!device_label.empty() && IsStringUTF8(device_label))
40 return UTF8ToUTF16(device_label); 39 return UTF8ToUTF16(device_label);
41 return chrome::GetFullProductName(disk.vendor_name(), disk.product_name()); 40 return chrome::MediaStorageUtil::GetFullProductName(disk.vendor_name(),
41 disk.product_name());
42 } 42 }
43 43
44 // Constructs a device id using uuid or manufacturer (vendor and product) id 44 // Constructs a device id using uuid or manufacturer (vendor and product) id
45 // details. 45 // details.
46 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { 46 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
47 std::string uuid = disk.fs_uuid(); 47 std::string uuid = disk.fs_uuid();
48 if (!uuid.empty()) 48 if (!uuid.empty())
49 return chrome::kFSUniqueIdPrefix + uuid; 49 return chrome::kFSUniqueIdPrefix + uuid;
50 50
51 // If one of the vendor or product information is missing, its value in the 51 // If one of the vendor or product information is missing, its value in the
(...skipping 26 matching lines...) Expand all
78 *device_label = GetDeviceName(*disk); 78 *device_label = GetDeviceName(*disk);
79 79
80 if (storage_size_in_bytes) 80 if (storage_size_in_bytes)
81 *storage_size_in_bytes = disk->total_size_in_bytes(); 81 *storage_size_in_bytes = disk->total_size_in_bytes();
82 return true; 82 return true;
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 using content::BrowserThread; 87 using content::BrowserThread;
88 using chrome::StorageInfo;
88 89
89 StorageMonitorCros::StorageMonitorCros() { 90 StorageMonitorCros::StorageMonitorCros() {
90 DCHECK(disks::DiskMountManager::GetInstance()); 91 DCHECK(disks::DiskMountManager::GetInstance());
91 disks::DiskMountManager::GetInstance()->AddObserver(this); 92 disks::DiskMountManager::GetInstance()->AddObserver(this);
92 CheckExistingMountPointsOnUIThread(); 93 CheckExistingMountPointsOnUIThread();
93 } 94 }
94 95
95 StorageMonitorCros::~StorageMonitorCros() { 96 StorageMonitorCros::~StorageMonitorCros() {
96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 97 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
97 if (manager) { 98 if (manager) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 163 }
163 164
164 void StorageMonitorCros::OnFormatEvent( 165 void StorageMonitorCros::OnFormatEvent(
165 disks::DiskMountManager::FormatEvent event, 166 disks::DiskMountManager::FormatEvent event,
166 FormatError error_code, 167 FormatError error_code,
167 const std::string& device_path) { 168 const std::string& device_path) {
168 } 169 }
169 170
170 bool StorageMonitorCros::GetStorageInfoForPath( 171 bool StorageMonitorCros::GetStorageInfoForPath(
171 const base::FilePath& path, 172 const base::FilePath& path,
172 chrome::StorageInfo* device_info) const { 173 StorageInfo* device_info) const {
173 if (!path.IsAbsolute()) 174 if (!path.IsAbsolute())
174 return false; 175 return false;
175 176
176 base::FilePath current = path; 177 base::FilePath current = path;
177 while (!ContainsKey(mount_map_, current.value()) && 178 while (!ContainsKey(mount_map_, current.value()) &&
178 current != current.DirName()) { 179 current != current.DirName()) {
179 current = current.DirName(); 180 current = current.DirName();
180 } 181 }
181 182
182 MountMap::const_iterator info_it = mount_map_.find(current.value()); 183 MountMap::const_iterator info_it = mount_map_.find(current.value());
183 if (info_it == mount_map_.end()) 184 if (info_it == mount_map_.end())
184 return false; 185 return false;
185 186
186 if (device_info) 187 if (device_info)
187 *device_info = info_it->second.storage_info; 188 *device_info = info_it->second.storage_info;
188 return true; 189 return true;
189 } 190 }
190 191
191 uint64 StorageMonitorCros::GetStorageSize( 192 uint64 StorageMonitorCros::GetStorageSize(
192 const std::string& device_location) const { 193 const std::string& device_location) const {
193 MountMap::const_iterator info_it = mount_map_.find(device_location); 194 MountMap::const_iterator info_it = mount_map_.find(device_location);
194 return (info_it != mount_map_.end()) ? 195 return (info_it != mount_map_.end()) ?
195 info_it->second.storage_size_in_bytes : 0; 196 info_it->second.storage_size_in_bytes : 0;
196 } 197 }
197 198
198 void StorageMonitorCros::CheckMountedPathOnFileThread( 199 void StorageMonitorCros::CheckMountedPathOnFileThread(
199 const disks::DiskMountManager::MountPointInfo& mount_info) { 200 const disks::DiskMountManager::MountPointInfo& mount_info) {
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
201 202
202 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); 203 bool has_dcim = chrome::MediaStorageUtil::HasDcim(mount_info.mount_path);
203 204
204 BrowserThread::PostTask( 205 BrowserThread::PostTask(
205 BrowserThread::UI, FROM_HERE, 206 BrowserThread::UI, FROM_HERE,
206 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this, 207 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this,
207 mount_info, has_dcim)); 208 mount_info, has_dcim));
208 } 209 }
209 210
210 void StorageMonitorCros::AddMountedPathOnUIThread( 211 void StorageMonitorCros::AddMountedPathOnUIThread(
211 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { 212 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) {
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 20 matching lines...) Expand all
233 if (unique_id.empty() || device_label.empty()) 234 if (unique_id.empty() || device_label.empty())
234 return; 235 return;
235 236
236 chrome::MediaStorageUtil::Type type = has_dcim ? 237 chrome::MediaStorageUtil::Type type = has_dcim ?
237 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM : 238 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_WITH_DCIM :
238 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM; 239 chrome::MediaStorageUtil::REMOVABLE_MASS_STORAGE_NO_DCIM;
239 240
240 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type, 241 std::string device_id = chrome::MediaStorageUtil::MakeDeviceId(type,
241 unique_id); 242 unique_id);
242 StorageObjectInfo object_info = { 243 StorageObjectInfo object_info = {
243 chrome::StorageInfo(device_id, device_label, mount_info.mount_path), 244 StorageInfo(device_id, device_label, mount_info.mount_path),
244 storage_size_in_bytes 245 storage_size_in_bytes
245 }; 246 };
246 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 247 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
247 receiver()->ProcessAttach(chrome::StorageInfo( 248
248 device_id, 249 string16 display_name = chrome::MediaStorageUtil::GetDisplayNameForDevice(
249 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), 250 storage_size_in_bytes,
250 mount_info.mount_path)); 251 device_label);
252
253 StorageInfo storage_info(device_id, display_name, mount_info.mount_path);
254 receiver()->ProcessAttach(storage_info);
251 } 255 }
252 256
253 } // namespace chromeos 257 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698