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/extensions/file_manager/volume_manager.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager_factory
.h" | 13 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager_factory
.h" |
13 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager_observe
r.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager_observe
r.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/pref_names.h" |
14 #include "chromeos/dbus/cros_disks_client.h" | 17 #include "chromeos/dbus/cros_disks_client.h" |
15 #include "chromeos/disks/disk_mount_manager.h" | 18 #include "chromeos/disks/disk_mount_manager.h" |
16 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
17 | 20 |
18 namespace file_manager { | 21 namespace file_manager { |
19 namespace { | 22 namespace { |
20 | 23 |
21 VolumeType MountTypeToVolumeType( | 24 VolumeType MountTypeToVolumeType( |
22 chromeos::MountType type) { | 25 chromeos::MountType type) { |
23 switch (type) { | 26 switch (type) { |
(...skipping 24 matching lines...) Expand all Loading... |
48 volume_info.type = MountTypeToVolumeType(mount_point.mount_type); | 51 volume_info.type = MountTypeToVolumeType(mount_point.mount_type); |
49 volume_info.source_path = base::FilePath(mount_point.source_path); | 52 volume_info.source_path = base::FilePath(mount_point.source_path); |
50 volume_info.mount_path = base::FilePath(mount_point.mount_path); | 53 volume_info.mount_path = base::FilePath(mount_point.mount_path); |
51 volume_info.mount_condition = mount_point.mount_condition; | 54 volume_info.mount_condition = mount_point.mount_condition; |
52 return volume_info; | 55 return volume_info; |
53 } | 56 } |
54 | 57 |
55 } // namespace | 58 } // namespace |
56 | 59 |
57 VolumeManager::VolumeManager( | 60 VolumeManager::VolumeManager( |
| 61 Profile* profile, |
58 chromeos::disks::DiskMountManager* disk_mount_manager) | 62 chromeos::disks::DiskMountManager* disk_mount_manager) |
59 : disk_mount_manager_(disk_mount_manager) { | 63 : profile_(profile), |
| 64 disk_mount_manager_(disk_mount_manager) { |
60 DCHECK(disk_mount_manager); | 65 DCHECK(disk_mount_manager); |
61 } | 66 } |
62 | 67 |
63 VolumeManager::~VolumeManager() { | 68 VolumeManager::~VolumeManager() { |
64 } | 69 } |
65 | 70 |
66 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { | 71 VolumeManager* VolumeManager::Get(content::BrowserContext* context) { |
67 return VolumeManagerFactory::Get(context); | 72 return VolumeManagerFactory::Get(context); |
68 } | 73 } |
69 | 74 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) | 117 it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) |
113 result.push_back(CreateVolumeInfoFromMountPointInfo(it->second)); | 118 result.push_back(CreateVolumeInfoFromMountPointInfo(it->second)); |
114 } | 119 } |
115 | 120 |
116 return result; | 121 return result; |
117 } | 122 } |
118 | 123 |
119 void VolumeManager::OnDiskEvent( | 124 void VolumeManager::OnDiskEvent( |
120 chromeos::disks::DiskMountManager::DiskEvent event, | 125 chromeos::disks::DiskMountManager::DiskEvent event, |
121 const chromeos::disks::DiskMountManager::Disk* disk) { | 126 const chromeos::disks::DiskMountManager::Disk* disk) { |
122 // TODO(hidehiko): Move the implementation from EventRouter. | 127 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 128 |
| 129 // Disregard hidden devices. |
| 130 if (disk->is_hidden()) |
| 131 return; |
| 132 |
| 133 switch (event) { |
| 134 case chromeos::disks::DiskMountManager::DISK_ADDED: { |
| 135 if (disk->device_path().empty()) { |
| 136 DVLOG(1) << "Empty system path for " << disk->device_path(); |
| 137 return; |
| 138 } |
| 139 |
| 140 bool mounting = false; |
| 141 if (disk->mount_path().empty() && disk->has_media() && |
| 142 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 143 // If disk is not mounted yet and it has media and there is no policy |
| 144 // forbidding external storage, give it a try. |
| 145 // Initiate disk mount operation. MountPath auto-detects the filesystem |
| 146 // format if the second argument is empty. The third argument (mount |
| 147 // label) is not used in a disk mount operation. |
| 148 disk_mount_manager_->MountPath( |
| 149 disk->device_path(), std::string(), std::string(), |
| 150 chromeos::MOUNT_TYPE_DEVICE); |
| 151 mounting = true; |
| 152 } |
| 153 |
| 154 // Notify to observers. |
| 155 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 156 OnDiskAdded(*disk, mounting)); |
| 157 return; |
| 158 } |
| 159 |
| 160 case chromeos::disks::DiskMountManager::DISK_REMOVED: |
| 161 // If the disk is already mounted, unmount it. |
| 162 if (!disk->mount_path().empty()) { |
| 163 disk_mount_manager_->UnmountPath( |
| 164 disk->mount_path(), |
| 165 chromeos::UNMOUNT_OPTIONS_LAZY, |
| 166 chromeos::disks::DiskMountManager::UnmountPathCallback()); |
| 167 } |
| 168 |
| 169 // Notify to observers. |
| 170 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, |
| 171 OnDiskRemoved(*disk)); |
| 172 return; |
| 173 |
| 174 case chromeos::disks::DiskMountManager::DISK_CHANGED: |
| 175 DVLOG(1) << "Ignore CHANGED event."; |
| 176 return; |
| 177 } |
| 178 NOTREACHED(); |
123 } | 179 } |
124 | 180 |
125 void VolumeManager::OnDeviceEvent( | 181 void VolumeManager::OnDeviceEvent( |
126 chromeos::disks::DiskMountManager::DeviceEvent event, | 182 chromeos::disks::DiskMountManager::DeviceEvent event, |
127 const std::string& device_path) { | 183 const std::string& device_path) { |
128 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 184 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
129 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; | 185 DVLOG(1) << "OnDeviceEvent: " << event << ", " << device_path; |
130 | 186 |
131 switch (event) { | 187 switch (event) { |
132 case chromeos::disks::DiskMountManager::DEVICE_ADDED: | 188 case chromeos::disks::DiskMountManager::DEVICE_ADDED: |
(...skipping 15 matching lines...) Expand all Loading... |
148 chromeos::disks::DiskMountManager::MountEvent event, | 204 chromeos::disks::DiskMountManager::MountEvent event, |
149 chromeos::MountError error_code, | 205 chromeos::MountError error_code, |
150 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { | 206 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) { |
151 // TODO(hidehiko): Move the implementation from EventRouter. | 207 // TODO(hidehiko): Move the implementation from EventRouter. |
152 } | 208 } |
153 | 209 |
154 void VolumeManager::OnFormatEvent( | 210 void VolumeManager::OnFormatEvent( |
155 chromeos::disks::DiskMountManager::FormatEvent event, | 211 chromeos::disks::DiskMountManager::FormatEvent event, |
156 chromeos::FormatError error_code, | 212 chromeos::FormatError error_code, |
157 const std::string& device_path) { | 213 const std::string& device_path) { |
158 // TODO(hidehiko): Move the implementation from EventRouter. | 214 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 215 DVLOG(1) << "OnDeviceEvent: " << event << ", " << error_code |
| 216 << ", " << device_path; |
| 217 |
| 218 switch (event) { |
| 219 case chromeos::disks::DiskMountManager::FORMAT_STARTED: |
| 220 FOR_EACH_OBSERVER( |
| 221 VolumeManagerObserver, observers_, |
| 222 OnFormatStarted(device_path, |
| 223 error_code == chromeos::FORMAT_ERROR_NONE)); |
| 224 return; |
| 225 case chromeos::disks::DiskMountManager::FORMAT_COMPLETED: |
| 226 if (error_code == chromeos::FORMAT_ERROR_NONE) { |
| 227 // If format is completed successfully, try to mount the device. |
| 228 // MountPath auto-detects filesystem format if second argument is |
| 229 // empty. The third argument (mount label) is not used in a disk mount |
| 230 // operation. |
| 231 disk_mount_manager_->MountPath( |
| 232 device_path, std::string(), std::string(), |
| 233 chromeos::MOUNT_TYPE_DEVICE); |
| 234 } |
| 235 |
| 236 FOR_EACH_OBSERVER( |
| 237 VolumeManagerObserver, observers_, |
| 238 OnFormatCompleted(device_path, |
| 239 error_code == chromeos::FORMAT_ERROR_NONE)); |
| 240 |
| 241 return; |
| 242 } |
| 243 NOTREACHED(); |
159 } | 244 } |
160 | 245 |
161 } // namespace file_manager | 246 } // namespace file_manager |
OLD | NEW |