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::RemovableDeviceNotificationsCros implementation. | 5 // chromeos::RemovableDeviceNotificationsCros implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/removable_device_notifications_chromeos
.h" | 7 #include "chrome/browser/storage_monitor/removable_device_notifications_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_device_notifications_utils.h" | 16 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" |
16 #include "chrome/browser/storage_monitor/media_storage_util.h" | 17 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 18 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer
_linux.h" |
17 #include "chrome/browser/storage_monitor/removable_device_constants.h" | 19 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
| 20 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "device/media_transfer_protocol/media_transfer_protocol_manager.h" |
19 | 23 |
20 namespace chromeos { | 24 namespace chromeos { |
21 | 25 |
22 namespace { | 26 namespace { |
23 | 27 |
24 // Constructs a device name using label or manufacturer (vendor and product) | 28 // Constructs a device name using label or manufacturer (vendor and product) |
25 // name details. | 29 // name details. |
26 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { | 30 string16 GetDeviceName(const disks::DiskMountManager::Disk& disk) { |
27 if (disk.device_type() == DEVICE_TYPE_SD) { | 31 if (disk.device_type() == DEVICE_TYPE_SD) { |
28 // Mount path of an SD card will be one of the following: | 32 // Mount path of an SD card will be one of the following: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 if (storage_size_in_bytes) | 84 if (storage_size_in_bytes) |
81 *storage_size_in_bytes = disk->total_size_in_bytes(); | 85 *storage_size_in_bytes = disk->total_size_in_bytes(); |
82 return true; | 86 return true; |
83 } | 87 } |
84 | 88 |
85 } // namespace | 89 } // namespace |
86 | 90 |
87 using content::BrowserThread; | 91 using content::BrowserThread; |
88 | 92 |
89 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { | 93 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { |
90 DCHECK(disks::DiskMountManager::GetInstance()); | |
91 disks::DiskMountManager::GetInstance()->AddObserver(this); | |
92 CheckExistingMountPointsOnUIThread(); | |
93 } | 94 } |
94 | 95 |
95 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { | 96 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { |
| 97 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 98 device::MediaTransferProtocolManager::Shutdown(); |
| 99 } |
| 100 |
96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 101 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
97 if (manager) { | 102 if (manager) { |
98 manager->RemoveObserver(this); | 103 manager->RemoveObserver(this); |
99 } | 104 } |
100 } | 105 } |
101 | 106 |
| 107 void RemovableDeviceNotificationsCros::Init() { |
| 108 DCHECK(disks::DiskMountManager::GetInstance()); |
| 109 disks::DiskMountManager::GetInstance()->AddObserver(this); |
| 110 CheckExistingMountPointsOnUIThread(); |
| 111 |
| 112 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 113 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
| 114 device::MediaTransferProtocolManager::Initialize(loop_proxy); |
| 115 |
| 116 media_transfer_protocol_device_observer_.reset( |
| 117 new chrome::MediaTransferProtocolDeviceObserverLinux()); |
| 118 media_transfer_protocol_device_observer_->SetNotifications(receiver()); |
| 119 } |
| 120 } |
| 121 |
| 122 |
102 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { | 123 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
104 const disks::DiskMountManager::MountPointMap& mount_point_map = | 125 const disks::DiskMountManager::MountPointMap& mount_point_map = |
105 disks::DiskMountManager::GetInstance()->mount_points(); | 126 disks::DiskMountManager::GetInstance()->mount_points(); |
106 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 127 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 128 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
108 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
109 BrowserThread::FILE, FROM_HERE, | 130 BrowserThread::FILE, FROM_HERE, |
110 base::Bind( | 131 base::Bind( |
111 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 132 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 storage_size_in_bytes | 267 storage_size_in_bytes |
247 }; | 268 }; |
248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 269 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
249 receiver()->ProcessAttach(StorageInfo( | 270 receiver()->ProcessAttach(StorageInfo( |
250 device_id, | 271 device_id, |
251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), | 272 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), |
252 mount_info.mount_path)); | 273 mount_info.mount_path)); |
253 } | 274 } |
254 | 275 |
255 } // namespace chromeos | 276 } // namespace chromeos |
OLD | NEW |