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

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

Issue 23727009: Cleanup: Remove chrome namespace for storage monitor and media galleries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 7 years, 3 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 // 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"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 namespace { 24 namespace {
25 25
26 // Constructs a device id using uuid or manufacturer (vendor and product) id 26 // Constructs a device id using uuid or manufacturer (vendor and product) id
27 // details. 27 // details.
28 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) { 28 std::string MakeDeviceUniqueId(const disks::DiskMountManager::Disk& disk) {
29 std::string uuid = disk.fs_uuid(); 29 std::string uuid = disk.fs_uuid();
30 if (!uuid.empty()) 30 if (!uuid.empty())
31 return chrome::kFSUniqueIdPrefix + uuid; 31 return kFSUniqueIdPrefix + uuid;
32 32
33 // If one of the vendor or product information is missing, its value in the 33 // If one of the vendor or product information is missing, its value in the
34 // string is empty. 34 // string is empty.
35 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo 35 // Format: VendorModelSerial:VendorInfo:ModelInfo:SerialInfo
36 // TODO(kmadhusu) Extract serial information for the disks and append it to 36 // TODO(kmadhusu) Extract serial information for the disks and append it to
37 // the device unique id. 37 // the device unique id.
38 const std::string& vendor = disk.vendor_id(); 38 const std::string& vendor = disk.vendor_id();
39 const std::string& product = disk.product_id(); 39 const std::string& product = disk.product_id();
40 if (vendor.empty() && product.empty()) 40 if (vendor.empty() && product.empty())
41 return std::string(); 41 return std::string();
42 return chrome::kVendorModelSerialPrefix + vendor + ":" + product + ":"; 42 return kVendorModelSerialPrefix + vendor + ":" + product + ":";
43 } 43 }
44 44
45 // Returns true if the requested device is valid, else false. On success, fills 45 // Returns true if the requested device is valid, else false. On success, fills
46 // in |info|. 46 // in |info|.
47 bool GetDeviceInfo(const disks::DiskMountManager::MountPointInfo& mount_info, 47 bool GetDeviceInfo(const disks::DiskMountManager::MountPointInfo& mount_info,
48 bool has_dcim, 48 bool has_dcim,
49 chrome::StorageInfo* info) { 49 StorageInfo* info) {
50 DCHECK(info); 50 DCHECK(info);
51 std::string source_path = mount_info.source_path; 51 std::string source_path = mount_info.source_path;
52 52
53 const disks::DiskMountManager::Disk* disk = 53 const disks::DiskMountManager::Disk* disk =
54 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path); 54 disks::DiskMountManager::GetInstance()->FindDiskBySourcePath(source_path);
55 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN) 55 if (!disk || disk->device_type() == DEVICE_TYPE_UNKNOWN)
56 return false; 56 return false;
57 57
58 std::string unique_id = MakeDeviceUniqueId(*disk); 58 std::string unique_id = MakeDeviceUniqueId(*disk);
59 // Keep track of device uuid and label, to see how often we receive empty 59 // Keep track of device uuid and label, to see how often we receive empty
60 // values. 60 // values.
61 string16 device_label = UTF8ToUTF16(disk->device_label()); 61 string16 device_label = UTF8ToUTF16(disk->device_label());
62 chrome::MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, 62 MediaStorageUtil::RecordDeviceInfoHistogram(true, unique_id, device_label);
63 device_label);
64 if (unique_id.empty()) 63 if (unique_id.empty())
65 return false; 64 return false;
66 65
67 chrome::StorageInfo::Type type = has_dcim ? 66 StorageInfo::Type type = has_dcim ?
68 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM : 67 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM :
69 chrome::StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM; 68 StorageInfo::REMOVABLE_MASS_STORAGE_NO_DCIM;
70 69
71 *info = chrome::StorageInfo( 70 *info = StorageInfo(
72 chrome::StorageInfo::MakeDeviceId(type, unique_id), 71 StorageInfo::MakeDeviceId(type, unique_id),
vandebo (ex-Chrome) 2013/09/12 20:37:23 nit: this could go up to the previous line, with i
Lei Zhang 2013/09/12 20:40:06 Done.
73 string16(), 72 string16(),
74 mount_info.mount_path, 73 mount_info.mount_path,
75 device_label, 74 device_label,
76 UTF8ToUTF16(disk->vendor_name()), 75 UTF8ToUTF16(disk->vendor_name()),
77 UTF8ToUTF16(disk->product_name()), 76 UTF8ToUTF16(disk->product_name()),
78 disk->total_size_in_bytes()); 77 disk->total_size_in_bytes());
79 return true; 78 return true;
80 } 79 }
81 80
82 // Returns whether the mount point in |mount_info| is a media device or not. 81 // Returns whether the mount point in |mount_info| is a media device or not.
83 bool CheckMountedPathOnFileThread( 82 bool CheckMountedPathOnFileThread(
84 const disks::DiskMountManager::MountPointInfo& mount_info) { 83 const disks::DiskMountManager::MountPointInfo& mount_info) {
85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
86 return chrome::MediaStorageUtil::HasDcim( 85 return MediaStorageUtil::HasDcim(base::FilePath(mount_info.mount_path));
87 base::FilePath(mount_info.mount_path));
88 } 86 }
89 87
90 } // namespace 88 } // namespace
91 89
92 using content::BrowserThread; 90 using content::BrowserThread;
93 using chrome::StorageInfo;
94 91
95 StorageMonitorCros::StorageMonitorCros() 92 StorageMonitorCros::StorageMonitorCros()
96 : weak_ptr_factory_(this) { 93 : weak_ptr_factory_(this) {
97 } 94 }
98 95
99 StorageMonitorCros::~StorageMonitorCros() { 96 StorageMonitorCros::~StorageMonitorCros() {
100 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); 97 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
101 if (manager) { 98 if (manager) {
102 manager->RemoveObserver(this); 99 manager->RemoveObserver(this);
103 } 100 }
104 } 101 }
105 102
106 void StorageMonitorCros::Init() { 103 void StorageMonitorCros::Init() {
107 DCHECK(disks::DiskMountManager::GetInstance()); 104 DCHECK(disks::DiskMountManager::GetInstance());
108 disks::DiskMountManager::GetInstance()->AddObserver(this); 105 disks::DiskMountManager::GetInstance()->AddObserver(this);
109 CheckExistingMountPoints(); 106 CheckExistingMountPoints();
110 107
111 if (!media_transfer_protocol_manager_) { 108 if (!media_transfer_protocol_manager_) {
112 scoped_refptr<base::MessageLoopProxy> loop_proxy; 109 scoped_refptr<base::MessageLoopProxy> loop_proxy;
113 media_transfer_protocol_manager_.reset( 110 media_transfer_protocol_manager_.reset(
114 device::MediaTransferProtocolManager::Initialize(loop_proxy)); 111 device::MediaTransferProtocolManager::Initialize(loop_proxy));
115 } 112 }
116 113
117 media_transfer_protocol_device_observer_.reset( 114 media_transfer_protocol_device_observer_.reset(
118 new chrome::MediaTransferProtocolDeviceObserverLinux( 115 new MediaTransferProtocolDeviceObserverLinux(
119 receiver(), media_transfer_protocol_manager_.get())); 116 receiver(), media_transfer_protocol_manager_.get()));
120 } 117 }
121 118
122 void StorageMonitorCros::CheckExistingMountPoints() { 119 void StorageMonitorCros::CheckExistingMountPoints() {
123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
124 const disks::DiskMountManager::MountPointMap& mount_point_map = 121 const disks::DiskMountManager::MountPointMap& mount_point_map =
125 disks::DiskMountManager::GetInstance()->mount_points(); 122 disks::DiskMountManager::GetInstance()->mount_points();
126 for (disks::DiskMountManager::MountPointMap::const_iterator it = 123 for (disks::DiskMountManager::MountPointMap::const_iterator it =
127 mount_point_map.begin(); it != mount_point_map.end(); ++it) { 124 mount_point_map.begin(); it != mount_point_map.end(); ++it) {
128 BrowserThread::PostTaskAndReplyWithResult( 125 BrowserThread::PostTaskAndReplyWithResult(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (info_it == mount_map_.end()) 226 if (info_it == mount_map_.end())
230 return false; 227 return false;
231 228
232 *device_info = info_it->second; 229 *device_info = info_it->second;
233 return true; 230 return true;
234 } 231 }
235 232
236 // Callback executed when the unmount call is run by DiskMountManager. 233 // Callback executed when the unmount call is run by DiskMountManager.
237 // Forwards result to |EjectDevice| caller. 234 // Forwards result to |EjectDevice| caller.
238 void NotifyUnmountResult( 235 void NotifyUnmountResult(
239 base::Callback<void(chrome::StorageMonitor::EjectStatus)> callback, 236 base::Callback<void(StorageMonitor::EjectStatus)> callback,
240 chromeos::MountError error_code) { 237 chromeos::MountError error_code) {
241 if (error_code == MOUNT_ERROR_NONE) 238 if (error_code == MOUNT_ERROR_NONE)
242 callback.Run(chrome::StorageMonitor::EJECT_OK); 239 callback.Run(StorageMonitor::EJECT_OK);
243 else 240 else
244 callback.Run(chrome::StorageMonitor::EJECT_FAILURE); 241 callback.Run(StorageMonitor::EJECT_FAILURE);
245 } 242 }
246 243
247 void StorageMonitorCros::EjectDevice( 244 void StorageMonitorCros::EjectDevice(
248 const std::string& device_id, 245 const std::string& device_id,
249 base::Callback<void(EjectStatus)> callback) { 246 base::Callback<void(EjectStatus)> callback) {
250 StorageInfo::Type type; 247 StorageInfo::Type type;
251 if (!StorageInfo::CrackDeviceId(device_id, &type, NULL)) { 248 if (!StorageInfo::CrackDeviceId(device_id, &type, NULL)) {
252 callback.Run(EJECT_FAILURE); 249 callback.Run(EJECT_FAILURE);
253 return; 250 return;
254 } 251 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
291 288
292 if (ContainsKey(mount_map_, mount_info.mount_path)) { 289 if (ContainsKey(mount_map_, mount_info.mount_path)) {
293 // CheckExistingMountPointsOnUIThread() added the mount point information 290 // CheckExistingMountPointsOnUIThread() added the mount point information
294 // in the map before the device attached handler is called. Therefore, an 291 // in the map before the device attached handler is called. Therefore, an
295 // entry for the device already exists in the map. 292 // entry for the device already exists in the map.
296 return; 293 return;
297 } 294 }
298 295
299 // Get the media device uuid and label if exists. 296 // Get the media device uuid and label if exists.
300 chrome::StorageInfo info; 297 StorageInfo info;
301 if (!GetDeviceInfo(mount_info, has_dcim, &info)) 298 if (!GetDeviceInfo(mount_info, has_dcim, &info))
302 return; 299 return;
303 300
304 if (info.device_id().empty()) 301 if (info.device_id().empty())
305 return; 302 return;
306 303
307 mount_map_.insert(std::make_pair(mount_info.mount_path, info)); 304 mount_map_.insert(std::make_pair(mount_info.mount_path, info));
308 305
309 receiver()->ProcessAttach(info); 306 receiver()->ProcessAttach(info);
310 } 307 }
311 308
312 } // namespace chromeos 309 } // namespace chromeos
313 310
314 namespace chrome {
315
316 StorageMonitor* StorageMonitor::Create() { 311 StorageMonitor* StorageMonitor::Create() {
317 return new chromeos::StorageMonitorCros(); 312 return new chromeos::StorageMonitorCros();
318 } 313 }
319
320 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698