OLD | NEW |
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/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/storage_monitor/media_storage_util.h" | 16 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 17 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
16 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 18 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| 19 #include "chrome/common/chrome_switches.h" |
17 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
18 | 22 |
19 namespace chromeos { | 23 namespace chromeos { |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 // Constructs a device name using label or manufacturer (vendor and product) | 27 // Constructs a device name using label or manufacturer (vendor and product) |
24 // name details. | 28 // name details. |
25 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk, | 29 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk, |
26 string16* storage_label, | 30 string16* storage_label, |
27 string16* vendor_name, | 31 string16* vendor_name, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 *storage_size_in_bytes = disk->total_size_in_bytes(); | 101 *storage_size_in_bytes = disk->total_size_in_bytes(); |
98 return true; | 102 return true; |
99 } | 103 } |
100 | 104 |
101 } // namespace | 105 } // namespace |
102 | 106 |
103 using content::BrowserThread; | 107 using content::BrowserThread; |
104 using chrome::StorageInfo; | 108 using chrome::StorageInfo; |
105 | 109 |
106 StorageMonitorCros::StorageMonitorCros() { | 110 StorageMonitorCros::StorageMonitorCros() { |
107 DCHECK(disks::DiskMountManager::GetInstance()); | |
108 disks::DiskMountManager::GetInstance()->AddObserver(this); | |
109 CheckExistingMountPointsOnUIThread(); | |
110 } | 111 } |
111 | 112 |
112 StorageMonitorCros::~StorageMonitorCros() { | 113 StorageMonitorCros::~StorageMonitorCros() { |
| 114 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 115 device::MediaTransferProtocolManager::Shutdown(); |
| 116 } |
| 117 |
113 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 118 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
114 if (manager) { | 119 if (manager) { |
115 manager->RemoveObserver(this); | 120 manager->RemoveObserver(this); |
116 } | 121 } |
117 } | 122 } |
118 | 123 |
| 124 void StorageMonitorCros::Init() { |
| 125 DCHECK(disks::DiskMountManager::GetInstance()); |
| 126 disks::DiskMountManager::GetInstance()->AddObserver(this); |
| 127 CheckExistingMountPointsOnUIThread(); |
| 128 |
| 129 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 130 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
| 131 device::MediaTransferProtocolManager::Initialize(loop_proxy); |
| 132 |
| 133 media_transfer_protocol_device_observer_.reset( |
| 134 new chrome::MediaTransferProtocolDeviceObserverLinux()); |
| 135 media_transfer_protocol_device_observer_->SetNotifications(receiver()); |
| 136 } |
| 137 } |
| 138 |
119 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { | 139 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { |
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
121 const disks::DiskMountManager::MountPointMap& mount_point_map = | 141 const disks::DiskMountManager::MountPointMap& mount_point_map = |
122 disks::DiskMountManager::GetInstance()->mount_points(); | 142 disks::DiskMountManager::GetInstance()->mount_points(); |
123 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 143 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
124 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 144 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
125 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
126 BrowserThread::FILE, FROM_HERE, | 146 BrowserThread::FILE, FROM_HERE, |
127 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, | 147 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, |
128 it->second)); | 148 it->second)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 vendor_name, | 290 vendor_name, |
271 model_name, | 291 model_name, |
272 storage_size_in_bytes); | 292 storage_size_in_bytes); |
273 | 293 |
274 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)); |
275 | 295 |
276 receiver()->ProcessAttach(object_info); | 296 receiver()->ProcessAttach(object_info); |
277 } | 297 } |
278 | 298 |
279 } // namespace chromeos | 299 } // namespace chromeos |
OLD | NEW |