OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_manager/mounted_disk_monitor.h" | 5 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chromeos/dbus/dbus_thread_manager.h" | |
9 #include "chromeos/dbus/power_manager_client.h" | 8 #include "chromeos/dbus/power_manager_client.h" |
10 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
11 | 10 |
12 using chromeos::DBusThreadManager; | |
13 using chromeos::disks::DiskMountManager; | 11 using chromeos::disks::DiskMountManager; |
14 | 12 |
15 namespace file_manager { | 13 namespace file_manager { |
16 namespace { | 14 namespace { |
17 | 15 |
18 // Time span of the resuming process. All unmount events sent during this | 16 // Time span of the resuming process. All unmount events sent during this |
19 // time are considered as being part of remounting process, since remounting | 17 // time are considered as being part of remounting process, since remounting |
20 // is done just after resuming. | 18 // is done just after resuming. |
21 const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); | 19 const base::TimeDelta kResumingTimeSpan = base::TimeDelta::FromSeconds(5); |
22 | 20 |
23 } // namespace | 21 } // namespace |
24 | 22 |
25 MountedDiskMonitor::MountedDiskMonitor() | 23 MountedDiskMonitor::MountedDiskMonitor( |
26 : is_resuming_(false), | 24 chromeos::PowerManagerClient* power_manager_client, |
| 25 chromeos::disks::DiskMountManager* disk_mount_manager) |
| 26 : power_manager_client_(power_manager_client), |
| 27 disk_mount_manager_(disk_mount_manager), |
| 28 is_resuming_(false), |
| 29 resuming_time_span_(kResumingTimeSpan), |
27 weak_factory_(this) { | 30 weak_factory_(this) { |
28 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 31 DCHECK(power_manager_client_); |
29 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 32 DCHECK(disk_mount_manager_); |
30 if (disk_mount_manager) { | 33 power_manager_client_->AddObserver(this); |
31 disk_mount_manager->AddObserver(this); | 34 disk_mount_manager_->AddObserver(this); |
32 disk_mount_manager->RequestMountInfoRefresh(); | 35 disk_mount_manager_->RequestMountInfoRefresh(); |
33 } | |
34 } | 36 } |
35 | 37 |
36 MountedDiskMonitor::~MountedDiskMonitor() { | 38 MountedDiskMonitor::~MountedDiskMonitor() { |
37 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 39 disk_mount_manager_->RemoveObserver(this); |
38 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 40 power_manager_client_->RemoveObserver(this); |
39 if (disk_mount_manager) | |
40 disk_mount_manager->RemoveObserver(this); | |
41 } | 41 } |
42 | 42 |
43 void MountedDiskMonitor::SuspendImminent() { | 43 void MountedDiskMonitor::SuspendImminent() { |
44 is_resuming_ = false; | 44 is_resuming_ = false; |
45 weak_factory_.InvalidateWeakPtrs(); | 45 weak_factory_.InvalidateWeakPtrs(); |
46 } | 46 } |
47 | 47 |
48 void MountedDiskMonitor::SystemResumed( | 48 void MountedDiskMonitor::SystemResumed( |
49 const base::TimeDelta& sleep_duration) { | 49 const base::TimeDelta& sleep_duration) { |
50 is_resuming_ = true; | 50 is_resuming_ = true; |
51 // Undo any previous resets. | 51 // Undo any previous resets. |
52 weak_factory_.InvalidateWeakPtrs(); | 52 weak_factory_.InvalidateWeakPtrs(); |
53 base::MessageLoopProxy::current()->PostDelayedTask( | 53 base::MessageLoopProxy::current()->PostDelayedTask( |
54 FROM_HERE, | 54 FROM_HERE, |
55 base::Bind(&MountedDiskMonitor::Reset, | 55 base::Bind(&MountedDiskMonitor::Reset, |
56 weak_factory_.GetWeakPtr()), | 56 weak_factory_.GetWeakPtr()), |
57 kResumingTimeSpan); | 57 resuming_time_span_); |
58 } | 58 } |
59 | 59 |
60 bool MountedDiskMonitor::DiskIsRemounting( | 60 bool MountedDiskMonitor::DiskIsRemounting( |
61 const DiskMountManager::Disk& disk) const { | 61 const DiskMountManager::Disk& disk) const { |
62 return unmounted_while_resuming_.count(disk.fs_uuid()) > 0; | 62 return unmounted_while_resuming_.count(disk.fs_uuid()) > 0; |
63 } | 63 } |
64 | 64 |
65 void MountedDiskMonitor::OnMountEvent( | 65 void MountedDiskMonitor::OnMountEvent( |
66 chromeos::disks::DiskMountManager::MountEvent event, | 66 chromeos::disks::DiskMountManager::MountEvent event, |
67 chromeos::MountError error_code, | 67 chromeos::MountError error_code, |
68 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | 68 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { |
69 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) | 69 if (mount_info.mount_type != chromeos::MOUNT_TYPE_DEVICE) |
70 return; | 70 return; |
71 | 71 |
72 switch (event) { | 72 switch (event) { |
73 case DiskMountManager::MOUNTING: { | 73 case DiskMountManager::MOUNTING: { |
74 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | |
75 const DiskMountManager::Disk* disk = | 74 const DiskMountManager::Disk* disk = |
76 disk_mount_manager->FindDiskBySourcePath(mount_info.source_path); | 75 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); |
77 if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) | 76 if (!disk || error_code != chromeos::MOUNT_ERROR_NONE) |
78 return; | 77 return; |
79 mounted_disks_[mount_info.source_path] = disk->fs_uuid(); | 78 mounted_disks_[mount_info.source_path] = disk->fs_uuid(); |
80 break; | 79 break; |
81 } | 80 } |
82 | 81 |
83 case DiskMountManager::UNMOUNTING: { | 82 case DiskMountManager::UNMOUNTING: { |
84 DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); | 83 DiskMap::iterator it = mounted_disks_.find(mount_info.source_path); |
85 if (it == mounted_disks_.end()) | 84 if (it == mounted_disks_.end()) |
86 return; | 85 return; |
(...skipping 21 matching lines...) Expand all Loading... |
108 chromeos::FormatError error_code, | 107 chromeos::FormatError error_code, |
109 const std::string& device_path) { | 108 const std::string& device_path) { |
110 } | 109 } |
111 | 110 |
112 void MountedDiskMonitor::Reset() { | 111 void MountedDiskMonitor::Reset() { |
113 unmounted_while_resuming_.clear(); | 112 unmounted_while_resuming_.clear(); |
114 is_resuming_ = false; | 113 is_resuming_ = false; |
115 } | 114 } |
116 | 115 |
117 } // namespace file_manager | 116 } // namespace file_manager |
OLD | NEW |