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_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 string16* storage_label, | 31 string16* storage_label, |
28 string16* vendor_name, | 32 string16* vendor_name, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (storage_size_in_bytes) | 100 if (storage_size_in_bytes) |
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 | 108 |
105 StorageMonitorCros::StorageMonitorCros() { | 109 StorageMonitorCros::StorageMonitorCros() { |
106 DCHECK(disks::DiskMountManager::GetInstance()); | |
107 disks::DiskMountManager::GetInstance()->AddObserver(this); | |
108 CheckExistingMountPointsOnUIThread(); | |
109 } | 110 } |
110 | 111 |
111 StorageMonitorCros::~StorageMonitorCros() { | 112 StorageMonitorCros::~StorageMonitorCros() { |
| 113 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 114 device::MediaTransferProtocolManager::Shutdown(); |
| 115 } |
| 116 |
112 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 117 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
113 if (manager) { | 118 if (manager) { |
114 manager->RemoveObserver(this); | 119 manager->RemoveObserver(this); |
115 } | 120 } |
116 } | 121 } |
117 | 122 |
| 123 void StorageMonitorCros::Init() { |
| 124 DCHECK(disks::DiskMountManager::GetInstance()); |
| 125 disks::DiskMountManager::GetInstance()->AddObserver(this); |
| 126 CheckExistingMountPointsOnUIThread(); |
| 127 |
| 128 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) { |
| 129 scoped_refptr<base::MessageLoopProxy> loop_proxy; |
| 130 device::MediaTransferProtocolManager::Initialize(loop_proxy); |
| 131 |
| 132 media_transfer_protocol_device_observer_.reset( |
| 133 new chrome::MediaTransferProtocolDeviceObserverLinux()); |
| 134 media_transfer_protocol_device_observer_->SetNotifications(receiver()); |
| 135 } |
| 136 } |
| 137 |
118 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { | 138 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { |
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 const disks::DiskMountManager::MountPointMap& mount_point_map = | 140 const disks::DiskMountManager::MountPointMap& mount_point_map = |
121 disks::DiskMountManager::GetInstance()->mount_points(); | 141 disks::DiskMountManager::GetInstance()->mount_points(); |
122 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 142 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
123 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 143 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
124 BrowserThread::PostTask( | 144 BrowserThread::PostTask( |
125 BrowserThread::FILE, FROM_HERE, | 145 BrowserThread::FILE, FROM_HERE, |
126 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, | 146 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, |
127 it->second)); | 147 it->second)); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 vendor_name, | 287 vendor_name, |
268 model_name, | 288 model_name, |
269 storage_size_in_bytes); | 289 storage_size_in_bytes); |
270 | 290 |
271 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 291 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
272 | 292 |
273 receiver()->ProcessAttach(object_info); | 293 receiver()->ProcessAttach(object_info); |
274 } | 294 } |
275 | 295 |
276 } // namespace chromeos | 296 } // namespace chromeos |
OLD | NEW |