Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor_chromeos.cc

Issue 12596010: Eject support for ChromeOS (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change callback name Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return true; 205 return true;
206 } 206 }
207 207
208 uint64 StorageMonitorCros::GetStorageSize( 208 uint64 StorageMonitorCros::GetStorageSize(
209 const std::string& device_location) const { 209 const std::string& device_location) const {
210 MountMap::const_iterator info_it = mount_map_.find(device_location); 210 MountMap::const_iterator info_it = mount_map_.find(device_location);
211 return (info_it != mount_map_.end()) ? 211 return (info_it != mount_map_.end()) ?
212 info_it->second.total_size_in_bytes : 0; 212 info_it->second.total_size_in_bytes : 0;
213 } 213 }
214 214
215 // Callback executed when the unmount call is run by DiskMountManager.
216 // Forwards result to |EjectDevice| caller.
217 void NotifyUnmountResult(
218 base::Callback<void(chrome::StorageMonitor::EjectStatus)> callback,
219 chromeos::MountError error_code) {
220 if (error_code == MOUNT_ERROR_NONE)
221 callback.Run(chrome::StorageMonitor::EJECT_OK);
222 else
223 callback.Run(chrome::StorageMonitor::EJECT_FAILURE);
224 }
225
226 void StorageMonitorCros::EjectDevice(
227 const std::string& device_id,
228 base::Callback<void(EjectStatus)> callback) {
229 std::string mount_path;
230 for (MountMap::const_iterator info_it = mount_map_.begin();
231 info_it != mount_map_.end(); ++info_it) {
232 if (info_it->second.device_id == device_id)
233 mount_path = info_it->first;
234 }
235
236 if (mount_path.empty()) {
237 callback.Run(EJECT_NO_SUCH_DEVICE);
238 return;
239 }
240
241 disks::DiskMountManager* manager = disks::DiskMountManager::GetInstance();
242 if (!manager) {
243 callback.Run(EJECT_FAILURE);
244 return;
245 }
246
247 manager->UnmountPath(mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
248 base::Bind(NotifyUnmountResult, callback));
249 }
250
215 void StorageMonitorCros::CheckMountedPathOnFileThread( 251 void StorageMonitorCros::CheckMountedPathOnFileThread(
216 const disks::DiskMountManager::MountPointInfo& mount_info) { 252 const disks::DiskMountManager::MountPointInfo& mount_info) {
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
218 254
219 bool has_dcim = chrome::MediaStorageUtil::HasDcim(mount_info.mount_path); 255 bool has_dcim = chrome::MediaStorageUtil::HasDcim(mount_info.mount_path);
220 256
221 BrowserThread::PostTask( 257 BrowserThread::PostTask(
222 BrowserThread::UI, FROM_HERE, 258 BrowserThread::UI, FROM_HERE,
223 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this, 259 base::Bind(&StorageMonitorCros::AddMountedPathOnUIThread, this,
224 mount_info, has_dcim)); 260 mount_info, has_dcim));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 vendor_name, 306 vendor_name,
271 model_name, 307 model_name,
272 storage_size_in_bytes); 308 storage_size_in_bytes);
273 309
274 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info)); 310 mount_map_.insert(std::make_pair(mount_info.mount_path, object_info));
275 311
276 receiver()->ProcessAttach(object_info); 312 receiver()->ProcessAttach(object_info);
277 } 313 }
278 314
279 } // namespace chromeos 315 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698