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::StorageMonitorCros implementation. |
6 | 6 |
7 #include "chrome/browser/storage_monitor/removable_device_notifications_chromeos
.h" | 7 #include "chrome/browser/storage_monitor/storage_monitor_chromeos.h" |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" | 15 #include "chrome/browser/storage_monitor/media_device_notifications_utils.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/removable_device_constants.h" | 17 #include "chrome/browser/storage_monitor/removable_device_constants.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 if (storage_size_in_bytes) | 80 if (storage_size_in_bytes) |
81 *storage_size_in_bytes = disk->total_size_in_bytes(); | 81 *storage_size_in_bytes = disk->total_size_in_bytes(); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 } // namespace | 85 } // namespace |
86 | 86 |
87 using content::BrowserThread; | 87 using content::BrowserThread; |
88 | 88 |
89 RemovableDeviceNotificationsCros::RemovableDeviceNotificationsCros() { | 89 StorageMonitorCros::StorageMonitorCros() { |
90 DCHECK(disks::DiskMountManager::GetInstance()); | 90 DCHECK(disks::DiskMountManager::GetInstance()); |
91 disks::DiskMountManager::GetInstance()->AddObserver(this); | 91 disks::DiskMountManager::GetInstance()->AddObserver(this); |
92 CheckExistingMountPointsOnUIThread(); | 92 CheckExistingMountPointsOnUIThread(); |
93 } | 93 } |
94 | 94 |
95 RemovableDeviceNotificationsCros::~RemovableDeviceNotificationsCros() { | 95 StorageMonitorCros::~StorageMonitorCros() { |
96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); | 96 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance(); |
97 if (manager) { | 97 if (manager) { |
98 manager->RemoveObserver(this); | 98 manager->RemoveObserver(this); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void RemovableDeviceNotificationsCros::CheckExistingMountPointsOnUIThread() { | 102 void StorageMonitorCros::CheckExistingMountPointsOnUIThread() { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
104 const disks::DiskMountManager::MountPointMap& mount_point_map = | 104 const disks::DiskMountManager::MountPointMap& mount_point_map = |
105 disks::DiskMountManager::GetInstance()->mount_points(); | 105 disks::DiskMountManager::GetInstance()->mount_points(); |
106 for (disks::DiskMountManager::MountPointMap::const_iterator it = | 106 for (disks::DiskMountManager::MountPointMap::const_iterator it = |
107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { | 107 mount_point_map.begin(); it != mount_point_map.end(); ++it) { |
108 BrowserThread::PostTask( | 108 BrowserThread::PostTask( |
109 BrowserThread::FILE, FROM_HERE, | 109 BrowserThread::FILE, FROM_HERE, |
110 base::Bind( | 110 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, |
111 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 111 it->second)); |
112 this, it->second)); | |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 void RemovableDeviceNotificationsCros::OnDiskEvent( | 115 void StorageMonitorCros::OnDiskEvent( |
117 disks::DiskMountManager::DiskEvent event, | 116 disks::DiskMountManager::DiskEvent event, |
118 const disks::DiskMountManager::Disk* disk) { | 117 const disks::DiskMountManager::Disk* disk) { |
119 } | 118 } |
120 | 119 |
121 void RemovableDeviceNotificationsCros::OnDeviceEvent( | 120 void StorageMonitorCros::OnDeviceEvent( |
122 disks::DiskMountManager::DeviceEvent event, | 121 disks::DiskMountManager::DeviceEvent event, |
123 const std::string& device_path) { | 122 const std::string& device_path) { |
124 } | 123 } |
125 | 124 |
126 void RemovableDeviceNotificationsCros::OnMountEvent( | 125 void StorageMonitorCros::OnMountEvent( |
127 disks::DiskMountManager::MountEvent event, | 126 disks::DiskMountManager::MountEvent event, |
128 MountError error_code, | 127 MountError error_code, |
129 const disks::DiskMountManager::MountPointInfo& mount_info) { | 128 const disks::DiskMountManager::MountPointInfo& mount_info) { |
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
131 | 130 |
132 // Ignore mount points that are not devices. | 131 // Ignore mount points that are not devices. |
133 if (mount_info.mount_type != MOUNT_TYPE_DEVICE) | 132 if (mount_info.mount_type != MOUNT_TYPE_DEVICE) |
134 return; | 133 return; |
135 // Ignore errors. | 134 // Ignore errors. |
136 if (error_code != MOUNT_ERROR_NONE) | 135 if (error_code != MOUNT_ERROR_NONE) |
137 return; | 136 return; |
138 if (mount_info.mount_condition != disks::MOUNT_CONDITION_NONE) | 137 if (mount_info.mount_condition != disks::MOUNT_CONDITION_NONE) |
139 return; | 138 return; |
140 | 139 |
141 switch (event) { | 140 switch (event) { |
142 case disks::DiskMountManager::MOUNTING: { | 141 case disks::DiskMountManager::MOUNTING: { |
143 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 142 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
144 NOTREACHED(); | 143 NOTREACHED(); |
145 return; | 144 return; |
146 } | 145 } |
147 | 146 |
148 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
149 BrowserThread::FILE, FROM_HERE, | 148 BrowserThread::FILE, FROM_HERE, |
150 base::Bind( | 149 base::Bind(&StorageMonitorCros::CheckMountedPathOnFileThread, this, |
151 &RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread, | 150 mount_info)); |
152 this, mount_info)); | |
153 break; | 151 break; |
154 } | 152 } |
155 case disks::DiskMountManager::UNMOUNTING: { | 153 case disks::DiskMountManager::UNMOUNTING: { |
156 MountMap::iterator it = mount_map_.find(mount_info.mount_path); | 154 MountMap::iterator it = mount_map_.find(mount_info.mount_path); |
157 if (it == mount_map_.end()) | 155 if (it == mount_map_.end()) |
158 return; | 156 return; |
159 receiver()->ProcessDetach(it->second.storage_info.device_id); | 157 receiver()->ProcessDetach(it->second.storage_info.device_id); |
160 mount_map_.erase(it); | 158 mount_map_.erase(it); |
161 break; | 159 break; |
162 } | 160 } |
163 } | 161 } |
164 } | 162 } |
165 | 163 |
166 void RemovableDeviceNotificationsCros::OnFormatEvent( | 164 void StorageMonitorCros::OnFormatEvent( |
167 disks::DiskMountManager::FormatEvent event, | 165 disks::DiskMountManager::FormatEvent event, |
168 FormatError error_code, | 166 FormatError error_code, |
169 const std::string& device_path) { | 167 const std::string& device_path) { |
170 } | 168 } |
171 | 169 |
172 bool RemovableDeviceNotificationsCros::GetStorageInfoForPath( | 170 bool StorageMonitorCros::GetStorageInfoForPath(const base::FilePath& path, |
173 const base::FilePath& path, | 171 StorageInfo* device_info) const { |
174 StorageInfo* device_info) const { | |
175 if (!path.IsAbsolute()) | 172 if (!path.IsAbsolute()) |
176 return false; | 173 return false; |
177 | 174 |
178 base::FilePath current = path; | 175 base::FilePath current = path; |
179 while (!ContainsKey(mount_map_, current.value()) && | 176 while (!ContainsKey(mount_map_, current.value()) && |
180 current != current.DirName()) { | 177 current != current.DirName()) { |
181 current = current.DirName(); | 178 current = current.DirName(); |
182 } | 179 } |
183 | 180 |
184 MountMap::const_iterator info_it = mount_map_.find(current.value()); | 181 MountMap::const_iterator info_it = mount_map_.find(current.value()); |
185 if (info_it == mount_map_.end()) | 182 if (info_it == mount_map_.end()) |
186 return false; | 183 return false; |
187 | 184 |
188 if (device_info) | 185 if (device_info) |
189 *device_info = info_it->second.storage_info; | 186 *device_info = info_it->second.storage_info; |
190 return true; | 187 return true; |
191 } | 188 } |
192 | 189 |
193 uint64 RemovableDeviceNotificationsCros::GetStorageSize( | 190 uint64 StorageMonitorCros::GetStorageSize( |
194 const std::string& device_location) const { | 191 const std::string& device_location) const { |
195 MountMap::const_iterator info_it = mount_map_.find(device_location); | 192 MountMap::const_iterator info_it = mount_map_.find(device_location); |
196 return (info_it != mount_map_.end()) ? | 193 return (info_it != mount_map_.end()) ? |
197 info_it->second.storage_size_in_bytes : 0; | 194 info_it->second.storage_size_in_bytes : 0; |
198 } | 195 } |
199 | 196 |
200 void RemovableDeviceNotificationsCros::CheckMountedPathOnFileThread( | 197 void StorageMonitorCros::CheckMountedPathOnFileThread( |
201 const disks::DiskMountManager::MountPointInfo& mount_info) { | 198 const disks::DiskMountManager::MountPointInfo& mount_info) { |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
203 | 200 |
204 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); | 201 bool has_dcim = chrome::IsMediaDevice(mount_info.mount_path); |
205 | 202 |
206 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
207 BrowserThread::UI, FROM_HERE, | 204 BrowserThread::UI, FROM_HERE, |
208 base::Bind(&RemovableDeviceNotificationsCros::AddMountedPathOnUIThread, | 205 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this, |
209 this, mount_info, has_dcim)); | 206 mount_info, has_dcim)); |
210 } | 207 } |
211 | 208 |
212 void RemovableDeviceNotificationsCros::AddMountedPathOnUIThread( | 209 void StorageMonitorCros::AddMountedPathOnUIThread( |
213 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { | 210 const disks::DiskMountManager::MountPointInfo& mount_info, bool has_dcim) { |
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
215 | 212 |
216 if (ContainsKey(mount_map_, mount_info.mount_path)) { | 213 if (ContainsKey(mount_map_, mount_info.mount_path)) { |
217 // CheckExistingMountPointsOnUIThread() added the mount point information | 214 // CheckExistingMountPointsOnUIThread() added the mount point information |
218 // in the map before the device attached handler is called. Therefore, an | 215 // in the map before the device attached handler is called. Therefore, an |
219 // entry for the device already exists in the map. | 216 // entry for the device already exists in the map. |
220 return; | 217 return; |
221 } | 218 } |
222 | 219 |
(...skipping 23 matching lines...) Expand all Loading... |
246 storage_size_in_bytes | 243 storage_size_in_bytes |
247 }; | 244 }; |
248 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); | 245 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); |
249 receiver()->ProcessAttach(StorageInfo( | 246 receiver()->ProcessAttach(StorageInfo( |
250 device_id, | 247 device_id, |
251 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), | 248 chrome::GetDisplayNameForDevice(storage_size_in_bytes, device_label), |
252 mount_info.mount_path)); | 249 mount_info.mount_path)); |
253 } | 250 } |
254 | 251 |
255 } // namespace chromeos | 252 } // namespace chromeos |
OLD | NEW |