OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 5 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include <sys/statvfs.h> | 10 #include <sys/statvfs.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 16 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 namespace disks { | 22 namespace disks { |
22 | 23 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 OnMountCompleted(MOUNT_ERROR_INTERNAL, source_path, type, ""); | 66 OnMountCompleted(MOUNT_ERROR_INTERNAL, source_path, type, ""); |
66 return; | 67 return; |
67 } | 68 } |
68 } | 69 } |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
70 cros_disks_client_->Mount( | 71 cros_disks_client_->Mount( |
71 source_path, | 72 source_path, |
72 type, | 73 type, |
73 // When succeeds, OnMountCompleted will be called by | 74 // When succeeds, OnMountCompleted will be called by |
74 // "MountCompleted" signal instead. | 75 // "MountCompleted" signal instead. |
75 base::Bind(&DoNothing), | 76 base::Bind(&base::DoNothing), |
76 base::Bind(&DiskMountManagerImpl::OnMountCompleted, | 77 base::Bind(&DiskMountManagerImpl::OnMountCompleted, |
77 weak_ptr_factory_.GetWeakPtr(), | 78 weak_ptr_factory_.GetWeakPtr(), |
78 MOUNT_ERROR_INTERNAL, | 79 MOUNT_ERROR_INTERNAL, |
79 source_path, | 80 source_path, |
80 type, | 81 type, |
81 "")); | 82 "")); |
82 } | 83 } |
83 | 84 |
84 // DiskMountManager override. | 85 // DiskMountManager override. |
85 virtual void UnmountPath(const std::string& mount_path) OVERRIDE { | 86 virtual void UnmountPath(const std::string& mount_path) OVERRIDE { |
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
87 cros_disks_client_->Unmount(mount_path, | 88 cros_disks_client_->Unmount(mount_path, |
88 base::Bind(&DiskMountManagerImpl::OnUnmountPath, | 89 base::Bind(&DiskMountManagerImpl::OnUnmountPath, |
89 weak_ptr_factory_.GetWeakPtr()), | 90 weak_ptr_factory_.GetWeakPtr()), |
90 base::Bind(&DoNothing)); | 91 base::Bind(&base::DoNothing)); |
91 } | 92 } |
92 | 93 |
93 // DiskMountManager override. | 94 // DiskMountManager override. |
94 virtual void GetSizeStatsOnFileThread(const std::string& mount_path, | 95 virtual void GetSizeStatsOnFileThread(const std::string& mount_path, |
95 size_t* total_size_kb, | 96 size_t* total_size_kb, |
96 size_t* remaining_size_kb) OVERRIDE { | 97 size_t* remaining_size_kb) OVERRIDE { |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
98 | 99 |
99 uint64_t total_size_in_bytes = 0; | 100 uint64_t total_size_in_bytes = 0; |
100 uint64_t remaining_size_in_bytes = 0; | 101 uint64_t remaining_size_in_bytes = 0; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 callback(user_data, false); | 213 callback(user_data, false); |
213 } | 214 } |
214 } | 215 } |
215 | 216 |
216 // DiskMountManager override. | 217 // DiskMountManager override. |
217 virtual void RequestMountInfoRefresh() OVERRIDE { | 218 virtual void RequestMountInfoRefresh() OVERRIDE { |
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
219 cros_disks_client_->EnumerateAutoMountableDevices( | 220 cros_disks_client_->EnumerateAutoMountableDevices( |
220 base::Bind(&DiskMountManagerImpl::OnRequestMountInfo, | 221 base::Bind(&DiskMountManagerImpl::OnRequestMountInfo, |
221 weak_ptr_factory_.GetWeakPtr()), | 222 weak_ptr_factory_.GetWeakPtr()), |
222 base::Bind(&DoNothing)); | 223 base::Bind(&base::DoNothing)); |
223 } | 224 } |
224 | 225 |
225 // DiskMountManager override. | 226 // DiskMountManager override. |
226 const DiskMap& disks() const OVERRIDE { return disks_; } | 227 const DiskMap& disks() const OVERRIDE { return disks_; } |
227 | 228 |
228 | 229 |
229 // DiskMountManager override. | 230 // DiskMountManager override. |
230 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } | 231 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } |
231 | 232 |
232 private: | 233 private: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 std::set<std::string> current_device_set; | 389 std::set<std::string> current_device_set; |
389 if (!devices.empty()) { | 390 if (!devices.empty()) { |
390 // Initiate properties fetch for all removable disks, | 391 // Initiate properties fetch for all removable disks, |
391 for (size_t i = 0; i < devices.size(); i++) { | 392 for (size_t i = 0; i < devices.size(); i++) { |
392 current_device_set.insert(devices[i]); | 393 current_device_set.insert(devices[i]); |
393 // Initiate disk property retrieval for each relevant device path. | 394 // Initiate disk property retrieval for each relevant device path. |
394 cros_disks_client_->GetDeviceProperties( | 395 cros_disks_client_->GetDeviceProperties( |
395 devices[i], | 396 devices[i], |
396 base::Bind(&DiskMountManagerImpl::OnGetDeviceProperties, | 397 base::Bind(&DiskMountManagerImpl::OnGetDeviceProperties, |
397 weak_ptr_factory_.GetWeakPtr()), | 398 weak_ptr_factory_.GetWeakPtr()), |
398 base::Bind(&DoNothing)); | 399 base::Bind(&base::DoNothing)); |
399 } | 400 } |
400 } | 401 } |
401 // Search and remove disks that are no longer present. | 402 // Search and remove disks that are no longer present. |
402 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { | 403 for (DiskMap::iterator iter = disks_.begin(); iter != disks_.end(); ) { |
403 if (current_device_set.find(iter->first) == current_device_set.end()) { | 404 if (current_device_set.find(iter->first) == current_device_set.end()) { |
404 Disk* disk = iter->second; | 405 Disk* disk = iter->second; |
405 NotifyDiskStatusUpdate(MOUNT_DISK_REMOVED, disk); | 406 NotifyDiskStatusUpdate(MOUNT_DISK_REMOVED, disk); |
406 delete iter->second; | 407 delete iter->second; |
407 disks_.erase(iter++); | 408 disks_.erase(iter++); |
408 } else { | 409 } else { |
409 ++iter; | 410 ++iter; |
410 } | 411 } |
411 } | 412 } |
412 } | 413 } |
413 | 414 |
414 // Callback to handle mount event signals. | 415 // Callback to handle mount event signals. |
415 void OnMountEvent(MountEventType event, const std::string& device_path_arg) { | 416 void OnMountEvent(MountEventType event, const std::string& device_path_arg) { |
416 // Take a copy of the argument so we can modify it below. | 417 // Take a copy of the argument so we can modify it below. |
417 std::string device_path = device_path_arg; | 418 std::string device_path = device_path_arg; |
418 DiskMountManagerEventType type = MOUNT_DEVICE_ADDED; | 419 DiskMountManagerEventType type = MOUNT_DEVICE_ADDED; |
419 switch (event) { | 420 switch (event) { |
420 case DISK_ADDED: { | 421 case DISK_ADDED: { |
421 cros_disks_client_->GetDeviceProperties( | 422 cros_disks_client_->GetDeviceProperties( |
422 device_path, | 423 device_path, |
423 base::Bind(&DiskMountManagerImpl::OnGetDeviceProperties, | 424 base::Bind(&DiskMountManagerImpl::OnGetDeviceProperties, |
424 weak_ptr_factory_.GetWeakPtr()), | 425 weak_ptr_factory_.GetWeakPtr()), |
425 base::Bind(&DoNothing)); | 426 base::Bind(&base::DoNothing)); |
426 return; | 427 return; |
427 } | 428 } |
428 case DISK_REMOVED: { | 429 case DISK_REMOVED: { |
429 // Search and remove disks that are no longer present. | 430 // Search and remove disks that are no longer present. |
430 DiskMountManager::DiskMap::iterator iter = disks_.find(device_path); | 431 DiskMountManager::DiskMap::iterator iter = disks_.find(device_path); |
431 if (iter != disks_.end()) { | 432 if (iter != disks_.end()) { |
432 Disk* disk = iter->second; | 433 Disk* disk = iter->second; |
433 NotifyDiskStatusUpdate(MOUNT_DISK_REMOVED, disk); | 434 NotifyDiskStatusUpdate(MOUNT_DISK_REMOVED, disk); |
434 delete iter->second; | 435 delete iter->second; |
435 disks_.erase(iter); | 436 disks_.erase(iter); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 for (SystemPathPrefixSet::const_iterator it = system_path_prefixes_.begin(); | 520 for (SystemPathPrefixSet::const_iterator it = system_path_prefixes_.begin(); |
520 it != system_path_prefixes_.end(); | 521 it != system_path_prefixes_.end(); |
521 ++it) { | 522 ++it) { |
522 const std::string& prefix = *it; | 523 const std::string& prefix = *it; |
523 if (StartsWithASCII(system_path, prefix, true)) | 524 if (StartsWithASCII(system_path, prefix, true)) |
524 return prefix; | 525 return prefix; |
525 } | 526 } |
526 return EmptyString(); | 527 return EmptyString(); |
527 } | 528 } |
528 | 529 |
529 // A function to be used as an empty callback. | |
530 static void DoNothing() { | |
531 } | |
532 | |
533 // Mount event change observers. | 530 // Mount event change observers. |
534 ObserverList<Observer> observers_; | 531 ObserverList<Observer> observers_; |
535 | 532 |
536 CrosDisksClient* cros_disks_client_; | 533 CrosDisksClient* cros_disks_client_; |
537 | 534 |
538 // The list of disks found. | 535 // The list of disks found. |
539 DiskMountManager::DiskMap disks_; | 536 DiskMountManager::DiskMap disks_; |
540 | 537 |
541 DiskMountManager::MountPointMap mount_points_; | 538 DiskMountManager::MountPointMap mount_points_; |
542 | 539 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 VLOG(1) << "DiskMountManager Shutdown completed"; | 663 VLOG(1) << "DiskMountManager Shutdown completed"; |
667 } | 664 } |
668 | 665 |
669 // static | 666 // static |
670 DiskMountManager* DiskMountManager::GetInstance() { | 667 DiskMountManager* DiskMountManager::GetInstance() { |
671 return g_disk_mount_manager; | 668 return g_disk_mount_manager; |
672 } | 669 } |
673 | 670 |
674 } // namespace disks | 671 } // namespace disks |
675 } // namespace chromeos | 672 } // namespace chromeos |
OLD | NEW |