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/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_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" | 17 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
18 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 18 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| 19 #include "chrome/browser/storage_monitor/test_media_transfer_protocol_manager_li
nux.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" | 22 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
22 | 23 |
23 namespace chromeos { | 24 namespace chromeos { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Constructs a device name using label or manufacturer (vendor and product) | 28 // Constructs a device name using label or manufacturer (vendor and product) |
28 // name details. | 29 // name details. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 base::FilePath(mount_info.mount_path)); | 111 base::FilePath(mount_info.mount_path)); |
111 } | 112 } |
112 | 113 |
113 } // namespace | 114 } // namespace |
114 | 115 |
115 using content::BrowserThread; | 116 using content::BrowserThread; |
116 using chrome::StorageInfo; | 117 using chrome::StorageInfo; |
117 | 118 |
118 StorageMonitorCros::StorageMonitorCros() | 119 StorageMonitorCros::StorageMonitorCros() |
119 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 120 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 121 // TODO(thestig) Do not do this here. Do it in TestingBrowserProcess when |
| 122 // BrowserProcess owns StorageMonitor. |
| 123 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 124 SetMediaTransferProtocolManagerForTest( |
| 125 new chrome::TestMediaTransferProtocolManagerLinux()); |
| 126 } |
120 } | 127 } |
121 | 128 |
122 StorageMonitorCros::~StorageMonitorCros() { | 129 StorageMonitorCros::~StorageMonitorCros() { |
123 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | |
124 device::MediaTransferProtocolManager::Shutdown(); | |
125 } | |
126 | |
127 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 130 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
128 if (manager) { | 131 if (manager) { |
129 manager->RemoveObserver(this); | 132 manager->RemoveObserver(this); |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
133 void StorageMonitorCros::Init() { | 136 void StorageMonitorCros::Init() { |
134 DCHECK(disks::DiskMountManager::GetInstance()); | 137 DCHECK(disks::DiskMountManager::GetInstance()); |
135 disks::DiskMountManager::GetInstance()->AddObserver(this); | 138 disks::DiskMountManager::GetInstance()->AddObserver(this); |
136 CheckExistingMountPoints(); | 139 CheckExistingMountPoints(); |
137 | 140 |
138 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { | 141 if (!media_transfer_protocol_manager_) { |
139 scoped_refptr<base::MessageLoopProxy> loop_proxy; | 142 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
140 device::MediaTransferProtocolManager::Initialize(loop_proxy); | 143 media_transfer_protocol_manager_.reset( |
| 144 device::MediaTransferProtocolManager::Initialize(loop_proxy)); |
| 145 } |
141 | 146 |
142 media_transfer_protocol_device_observer_.reset( | 147 media_transfer_protocol_device_observer_.reset( |
143 new chrome::MediaTransferProtocolDeviceObserverLinux(receiver())); | 148 new chrome::MediaTransferProtocolDeviceObserverLinux(receiver())); |
144 } | |
145 } | 149 } |
146 | 150 |
147 void StorageMonitorCros::CheckExistingMountPoints() { | 151 void StorageMonitorCros::CheckExistingMountPoints() { |
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
149 const disks::DiskMountManager::MountPointMap& mount_point_map = | 153 const disks::DiskMountManager::MountPointMap& mount_point_map = |
150 disks::DiskMountManager::GetInstance()->mount_points(); | 154 disks::DiskMountManager::GetInstance()->mount_points(); |
151 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 155 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
152 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 156 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
153 BrowserThread::PostTaskAndReplyWithResult( | 157 BrowserThread::PostTaskAndReplyWithResult( |
154 BrowserThread::FILE, FROM_HERE, | 158 BrowserThread::FILE, FROM_HERE, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 211 } |
208 } | 212 } |
209 } | 213 } |
210 | 214 |
211 void StorageMonitorCros::OnFormatEvent( | 215 void StorageMonitorCros::OnFormatEvent( |
212 disks::DiskMountManager::FormatEvent event, | 216 disks::DiskMountManager::FormatEvent event, |
213 FormatError error_code, | 217 FormatError error_code, |
214 const std::string& device_path) { | 218 const std::string& device_path) { |
215 } | 219 } |
216 | 220 |
| 221 void StorageMonitorCros::SetMediaTransferProtocolManagerForTest( |
| 222 device::MediaTransferProtocolManager* test_manager) { |
| 223 DCHECK(!media_transfer_protocol_manager_); |
| 224 media_transfer_protocol_manager_.reset(test_manager); |
| 225 } |
| 226 |
| 227 |
217 bool StorageMonitorCros::GetStorageInfoForPath( | 228 bool StorageMonitorCros::GetStorageInfoForPath( |
218 const base::FilePath& path, | 229 const base::FilePath& path, |
219 StorageInfo* device_info) const { | 230 StorageInfo* device_info) const { |
220 // TODO(thestig) |media_transfer_protocol_device_observer_| should always be | 231 if (media_transfer_protocol_device_observer_->GetStorageInfoForPath( |
221 // valid. | |
222 if (media_transfer_protocol_device_observer_ && | |
223 media_transfer_protocol_device_observer_->GetStorageInfoForPath( | |
224 path, device_info)) { | 232 path, device_info)) { |
225 return true; | 233 return true; |
226 } | 234 } |
227 | 235 |
228 if (!path.IsAbsolute()) | 236 if (!path.IsAbsolute()) |
229 return false; | 237 return false; |
230 | 238 |
231 base::FilePath current = path; | 239 base::FilePath current = path; |
232 while (!ContainsKey(mount_map_, current.value()) && | 240 while (!ContainsKey(mount_map_, current.value()) && |
233 current != current.DirName()) { | 241 current != current.DirName()) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 280 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
273 if (!manager) { | 281 if (!manager) { |
274 callback.Run(EJECT_FAILURE); | 282 callback.Run(EJECT_FAILURE); |
275 return; | 283 return; |
276 } | 284 } |
277 | 285 |
278 manager->UnmountPath(mount_path, chromeos::UNMOUNT_OPTIONS_NONE, | 286 manager->UnmountPath(mount_path, chromeos::UNMOUNT_OPTIONS_NONE, |
279 base::Bind(NotifyUnmountResult, callback)); | 287 base::Bind(NotifyUnmountResult, callback)); |
280 } | 288 } |
281 | 289 |
| 290 device::MediaTransferProtocolManager* |
| 291 StorageMonitorCros::media_transfer_protocol_manager() { |
| 292 return media_transfer_protocol_manager_.get(); |
| 293 } |
| 294 |
282 void StorageMonitorCros::AddMountedPath( | 295 void StorageMonitorCros::AddMountedPath( |
283 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { | 296 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { |
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
285 | 298 |
286 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 299 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
287 // CheckExistingMountPointsOnUIThread() added the mount point information | 300 // CheckExistingMountPointsOnUIThread() added the mount point information |
288 // in the map before the device attached handler is called. Therefore, an | 301 // in the map before the device attached handler is called. Therefore, an |
289 // entry for the device already exists in the map. | 302 // entry for the device already exists in the map. |
290 return; | 303 return; |
291 } | 304 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 vendor_name, | 338 vendor_name, |
326 model_name, | 339 model_name, |
327 storage_size_in_bytes); | 340 storage_size_in_bytes); |
328 | 341 |
329 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 342 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
330 | 343 |
331 receiver()->ProcessAttach(object_info); | 344 receiver()->ProcessAttach(object_info); |
332 } | 345 } |
333 | 346 |
334 } // namespace chromeos | 347 } // namespace chromeos |
OLD | NEW |