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 // RemovableDeviceNotificationsLinux implementation. | 5 // RemovableDeviceNotificationsLinux implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/removable_device_notifications_linux.h" | 7 #include "chrome/browser/storage_monitor/removable_device_notifications_linux.h" |
8 | 8 |
9 #include <mntent.h> | 9 #include <mntent.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 23 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
23 #include "chrome/browser/storage_monitor/media_storage_util.h" | 24 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 25 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
24 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 26 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
25 #include "chrome/browser/storage_monitor/udev_util_linux.h" | 27 #include "chrome/browser/storage_monitor/udev_util_linux.h" |
| 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
26 | 30 |
27 namespace chrome { | 31 namespace chrome { |
28 | 32 |
29 using content::BrowserThread; | 33 using content::BrowserThread; |
30 | 34 |
31 namespace { | 35 namespace { |
32 | 36 |
33 // List of file systems we care about. | 37 // List of file systems we care about. |
34 const char* const kKnownFileSystems[] = { | 38 const char* const kKnownFileSystems[] = { |
35 "ext2", | 39 "ext2", |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( | 238 RemovableDeviceNotificationsLinux::RemovableDeviceNotificationsLinux( |
235 const base::FilePath& path, | 239 const base::FilePath& path, |
236 GetDeviceInfoFunc get_device_info_func) | 240 GetDeviceInfoFunc get_device_info_func) |
237 : initialized_(false), | 241 : initialized_(false), |
238 mtab_path_(path), | 242 mtab_path_(path), |
239 get_device_info_func_(get_device_info_func) { | 243 get_device_info_func_(get_device_info_func) { |
240 } | 244 } |
241 | 245 |
242 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() { | 246 RemovableDeviceNotificationsLinux::~RemovableDeviceNotificationsLinux() { |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 248 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 249 device::MediaTransferProtocolManager::Shutdown(); |
| 250 } |
244 } | 251 } |
245 | 252 |
246 void RemovableDeviceNotificationsLinux::Init() { | 253 void RemovableDeviceNotificationsLinux::Init() { |
247 DCHECK(!mtab_path_.empty()); | 254 DCHECK(!mtab_path_.empty()); |
248 | 255 |
249 // Put |kKnownFileSystems| in std::set to get O(log N) access time. | 256 // Put |kKnownFileSystems| in std::set to get O(log N) access time. |
250 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) | 257 for (size_t i = 0; i < arraysize(kKnownFileSystems); ++i) |
251 known_file_systems_.insert(kKnownFileSystems[i]); | 258 known_file_systems_.insert(kKnownFileSystems[i]); |
252 | 259 |
253 BrowserThread::PostTask( | 260 BrowserThread::PostTask( |
254 BrowserThread::FILE, FROM_HERE, | 261 BrowserThread::FILE, FROM_HERE, |
255 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); | 262 base::Bind(&RemovableDeviceNotificationsLinux::InitOnFileThread, this)); |
| 263 |
| 264 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 265 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
| 266 loop_proxy = content::BrowserThread::GetMessageLoopProxyForThread( |
| 267 content::BrowserThread::FILE); |
| 268 device::MediaTransferProtocolManager::Initialize(loop_proxy); |
| 269 |
| 270 media_transfer_protocol_device_observer_.reset( |
| 271 new MediaTransferProtocolDeviceObserverLinux()); |
| 272 media_transfer_protocol_device_observer_->SetNotifications(receiver()); |
| 273 } |
256 } | 274 } |
257 | 275 |
258 bool RemovableDeviceNotificationsLinux::GetStorageInfoForPath( | 276 bool RemovableDeviceNotificationsLinux::GetStorageInfoForPath( |
259 const base::FilePath& path, | 277 const base::FilePath& path, |
260 StorageInfo* device_info) const { | 278 StorageInfo* device_info) const { |
261 if (!path.IsAbsolute()) | 279 if (!path.IsAbsolute()) |
262 return false; | 280 return false; |
263 | 281 |
264 base::FilePath current = path; | 282 base::FilePath current = path; |
265 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) | 283 while (!ContainsKey(mount_info_map_, current) && current != current.DirName()) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 mount_priority_map_[mount_device][mount_point] = removable; | 473 mount_priority_map_[mount_device][mount_point] = removable; |
456 | 474 |
457 if (removable) { | 475 if (removable) { |
458 receiver()->ProcessAttach(StorageInfo( | 476 receiver()->ProcessAttach(StorageInfo( |
459 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), | 477 device_id, GetDisplayNameForDevice(partition_size_in_bytes, name), |
460 mount_point.value())); | 478 mount_point.value())); |
461 } | 479 } |
462 } | 480 } |
463 | 481 |
464 } // namespace chrome | 482 } // namespace chrome |
OLD | NEW |