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

Side by Side Diff: chrome/browser/chromeos/file_manager/volume_manager.cc

Issue 2717213002: Revert of Some linked_ptr removal in chromeos file_browser_handler. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/volume_manager.h" 5 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 is_read_only_removable_device_(false), 161 is_read_only_removable_device_(false),
162 has_media_(false), 162 has_media_(false),
163 configurable_(false), 163 configurable_(false),
164 watchable_(false) { 164 watchable_(false) {
165 } 165 }
166 166
167 Volume::~Volume() { 167 Volume::~Volume() {
168 } 168 }
169 169
170 // static 170 // static
171 std::unique_ptr<Volume> Volume::CreateForDrive(Profile* profile) { 171 Volume* Volume::CreateForDrive(Profile* profile) {
172 const base::FilePath& drive_path = 172 const base::FilePath& drive_path =
173 drive::util::GetDriveMountPointPath(profile); 173 drive::util::GetDriveMountPointPath(profile);
174 std::unique_ptr<Volume> volume(new Volume()); 174 Volume* const volume = new Volume;
175 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE; 175 volume->type_ = VOLUME_TYPE_GOOGLE_DRIVE;
176 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 176 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
177 volume->source_path_ = drive_path; 177 volume->source_path_ = drive_path;
178 volume->source_ = SOURCE_NETWORK; 178 volume->source_ = SOURCE_NETWORK;
179 volume->mount_path_ = drive_path; 179 volume->mount_path_ = drive_path;
180 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 180 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
181 volume->volume_id_ = GenerateVolumeId(*volume); 181 volume->volume_id_ = GenerateVolumeId(*volume);
182 volume->watchable_ = true; 182 volume->watchable_ = true;
183 return volume; 183 return volume;
184 } 184 }
185 185
186 // static 186 // static
187 std::unique_ptr<Volume> Volume::CreateForDownloads( 187 Volume* Volume::CreateForDownloads(const base::FilePath& downloads_path) {
188 const base::FilePath& downloads_path) { 188 Volume* const volume = new Volume;
189 std::unique_ptr<Volume> volume(new Volume());
190 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY; 189 volume->type_ = VOLUME_TYPE_DOWNLOADS_DIRECTORY;
191 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 190 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
192 // Keep source_path empty. 191 // Keep source_path empty.
193 volume->source_ = SOURCE_SYSTEM; 192 volume->source_ = SOURCE_SYSTEM;
194 volume->mount_path_ = downloads_path; 193 volume->mount_path_ = downloads_path;
195 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 194 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
196 volume->volume_id_ = GenerateVolumeId(*volume); 195 volume->volume_id_ = GenerateVolumeId(*volume);
197 volume->watchable_ = true; 196 volume->watchable_ = true;
198 return volume; 197 return volume;
199 } 198 }
200 199
201 // static 200 // static
202 std::unique_ptr<Volume> Volume::CreateForRemovable( 201 Volume* Volume::CreateForRemovable(
203 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point, 202 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point,
204 const chromeos::disks::DiskMountManager::Disk* disk) { 203 const chromeos::disks::DiskMountManager::Disk* disk) {
205 std::unique_ptr<Volume> volume(new Volume()); 204 Volume* const volume = new Volume;
206 volume->type_ = MountTypeToVolumeType(mount_point.mount_type); 205 volume->type_ = MountTypeToVolumeType(mount_point.mount_type);
207 volume->source_path_ = base::FilePath(mount_point.source_path); 206 volume->source_path_ = base::FilePath(mount_point.source_path);
208 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE 207 volume->source_ = mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE
209 ? SOURCE_FILE 208 ? SOURCE_FILE
210 : SOURCE_DEVICE; 209 : SOURCE_DEVICE;
211 volume->mount_path_ = base::FilePath(mount_point.mount_path); 210 volume->mount_path_ = base::FilePath(mount_point.mount_path);
212 volume->mount_condition_ = mount_point.mount_condition; 211 volume->mount_condition_ = mount_point.mount_condition;
213 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe(); 212 volume->volume_label_ = volume->mount_path().BaseName().AsUTF8Unsafe();
214 if (disk) { 213 if (disk) {
215 volume->device_type_ = disk->device_type(); 214 volume->device_type_ = disk->device_type();
216 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix()); 215 volume->system_path_prefix_ = base::FilePath(disk->system_path_prefix());
217 volume->is_parent_ = disk->is_parent(); 216 volume->is_parent_ = disk->is_parent();
218 volume->is_read_only_ = disk->is_read_only(); 217 volume->is_read_only_ = disk->is_read_only();
219 volume->is_read_only_removable_device_ = disk->is_read_only_hardware(); 218 volume->is_read_only_removable_device_ = disk->is_read_only_hardware();
220 volume->has_media_ = disk->has_media(); 219 volume->has_media_ = disk->has_media();
221 } else { 220 } else {
222 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 221 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
223 volume->is_read_only_ = 222 volume->is_read_only_ =
224 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE); 223 (mount_point.mount_type == chromeos::MOUNT_TYPE_ARCHIVE);
225 } 224 }
226 volume->volume_id_ = GenerateVolumeId(*volume); 225 volume->volume_id_ = GenerateVolumeId(*volume);
227 volume->watchable_ = true; 226 volume->watchable_ = true;
228 return volume; 227 return volume;
229 } 228 }
230 229
231 // static 230 // static
232 std::unique_ptr<Volume> Volume::CreateForProvidedFileSystem( 231 Volume* Volume::CreateForProvidedFileSystem(
233 const chromeos::file_system_provider::ProvidedFileSystemInfo& 232 const chromeos::file_system_provider::ProvidedFileSystemInfo&
234 file_system_info, 233 file_system_info,
235 MountContext mount_context) { 234 MountContext mount_context) {
236 std::unique_ptr<Volume> volume(new Volume()); 235 Volume* const volume = new Volume;
237 volume->file_system_id_ = file_system_info.file_system_id(); 236 volume->file_system_id_ = file_system_info.file_system_id();
238 volume->extension_id_ = file_system_info.extension_id(); 237 volume->extension_id_ = file_system_info.extension_id();
239 switch (file_system_info.source()) { 238 switch (file_system_info.source()) {
240 case extensions::SOURCE_FILE: 239 case extensions::SOURCE_FILE:
241 volume->source_ = SOURCE_FILE; 240 volume->source_ = SOURCE_FILE;
242 break; 241 break;
243 case extensions::SOURCE_DEVICE: 242 case extensions::SOURCE_DEVICE:
244 volume->source_ = SOURCE_DEVICE; 243 volume->source_ = SOURCE_DEVICE;
245 break; 244 break;
246 case extensions::SOURCE_NETWORK: 245 case extensions::SOURCE_NETWORK:
247 volume->source_ = SOURCE_NETWORK; 246 volume->source_ = SOURCE_NETWORK;
248 break; 247 break;
249 } 248 }
250 volume->volume_label_ = file_system_info.display_name(); 249 volume->volume_label_ = file_system_info.display_name();
251 volume->type_ = VOLUME_TYPE_PROVIDED; 250 volume->type_ = VOLUME_TYPE_PROVIDED;
252 volume->mount_path_ = file_system_info.mount_path(); 251 volume->mount_path_ = file_system_info.mount_path();
253 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 252 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
254 volume->mount_context_ = mount_context; 253 volume->mount_context_ = mount_context;
255 volume->is_parent_ = true; 254 volume->is_parent_ = true;
256 volume->is_read_only_ = !file_system_info.writable(); 255 volume->is_read_only_ = !file_system_info.writable();
257 volume->configurable_ = file_system_info.configurable(); 256 volume->configurable_ = file_system_info.configurable();
258 volume->watchable_ = file_system_info.watchable(); 257 volume->watchable_ = file_system_info.watchable();
259 volume->volume_id_ = GenerateVolumeId(*volume); 258 volume->volume_id_ = GenerateVolumeId(*volume);
260 return volume; 259 return volume;
261 } 260 }
262 261
263 // static 262 // static
264 std::unique_ptr<Volume> Volume::CreateForMTP(const base::FilePath& mount_path, 263 Volume* Volume::CreateForMTP(const base::FilePath& mount_path,
265 const std::string& label, 264 const std::string& label,
266 bool read_only) { 265 bool read_only) {
267 std::unique_ptr<Volume> volume(new Volume()); 266 Volume* const volume = new Volume;
268 volume->type_ = VOLUME_TYPE_MTP; 267 volume->type_ = VOLUME_TYPE_MTP;
269 volume->mount_path_ = mount_path; 268 volume->mount_path_ = mount_path;
270 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 269 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
271 volume->is_parent_ = true; 270 volume->is_parent_ = true;
272 volume->is_read_only_ = read_only; 271 volume->is_read_only_ = read_only;
273 volume->volume_id_ = kMtpVolumeIdPrefix + label; 272 volume->volume_id_ = kMtpVolumeIdPrefix + label;
274 volume->volume_label_ = label; 273 volume->volume_label_ = label;
275 volume->source_path_ = mount_path; 274 volume->source_path_ = mount_path;
276 volume->source_ = SOURCE_DEVICE; 275 volume->source_ = SOURCE_DEVICE;
277 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE; 276 volume->device_type_ = chromeos::DEVICE_TYPE_MOBILE;
278 return volume; 277 return volume;
279 } 278 }
280 279
281 // static 280 // static
282 std::unique_ptr<Volume> Volume::CreateForMediaView( 281 Volume* Volume::CreateForMediaView(const std::string& root_document_id) {
283 const std::string& root_document_id) { 282 Volume* const volume = new Volume;
284 std::unique_ptr<Volume> volume(new Volume());
285 volume->type_ = VOLUME_TYPE_MEDIA_VIEW; 283 volume->type_ = VOLUME_TYPE_MEDIA_VIEW;
286 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN; 284 volume->device_type_ = chromeos::DEVICE_TYPE_UNKNOWN;
287 volume->source_ = SOURCE_SYSTEM; 285 volume->source_ = SOURCE_SYSTEM;
288 volume->mount_path_ = arc::GetDocumentsProviderMountPath( 286 volume->mount_path_ = arc::GetDocumentsProviderMountPath(
289 arc::kMediaDocumentsProviderAuthority, root_document_id); 287 arc::kMediaDocumentsProviderAuthority, root_document_id);
290 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 288 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
291 volume->volume_label_ = root_document_id; 289 volume->volume_label_ = root_document_id;
292 volume->is_read_only_ = true; 290 volume->is_read_only_ = true;
293 volume->watchable_ = false; 291 volume->watchable_ = false;
294 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id); 292 volume->volume_id_ = arc::GetMediaViewVolumeId(root_document_id);
295 return volume; 293 return volume;
296 } 294 }
297 295
298 // static 296 // static
299 std::unique_ptr<Volume> Volume::CreateForTesting( 297 Volume* Volume::CreateForTesting(const base::FilePath& path,
300 const base::FilePath& path, 298 VolumeType volume_type,
301 VolumeType volume_type, 299 chromeos::DeviceType device_type,
302 chromeos::DeviceType device_type, 300 bool read_only) {
303 bool read_only) { 301 Volume* const volume = new Volume;
304 std::unique_ptr<Volume> volume(new Volume());
305 volume->type_ = volume_type; 302 volume->type_ = volume_type;
306 volume->device_type_ = device_type; 303 volume->device_type_ = device_type;
307 // Keep source_path empty. 304 // Keep source_path empty.
308 volume->source_ = SOURCE_DEVICE; 305 volume->source_ = SOURCE_DEVICE;
309 volume->mount_path_ = path; 306 volume->mount_path_ = path;
310 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE; 307 volume->mount_condition_ = chromeos::disks::MOUNT_CONDITION_NONE;
311 volume->is_read_only_ = read_only; 308 volume->is_read_only_ = read_only;
312 volume->volume_id_ = GenerateVolumeId(*volume); 309 volume->volume_id_ = GenerateVolumeId(*volume);
313 return volume; 310 return volume;
314 } 311 }
315 312
316 // static 313 // static
317 std::unique_ptr<Volume> Volume::CreateForTesting( 314 Volume* Volume::CreateForTesting(const base::FilePath& device_path,
318 const base::FilePath& device_path, 315 const base::FilePath& mount_path) {
319 const base::FilePath& mount_path) { 316 Volume* const volume = new Volume;
320 std::unique_ptr<Volume> volume(new Volume());
321 volume->system_path_prefix_ = device_path; 317 volume->system_path_prefix_ = device_path;
322 volume->mount_path_ = mount_path; 318 volume->mount_path_ = mount_path;
323 return volume; 319 return volume;
324 } 320 }
325 321
326 VolumeManager::VolumeManager( 322 VolumeManager::VolumeManager(
327 Profile* profile, 323 Profile* profile,
328 drive::DriveIntegrationService* drive_integration_service, 324 drive::DriveIntegrationService* drive_integration_service,
329 chromeos::PowerManagerClient* power_manager_client, 325 chromeos::PowerManagerClient* power_manager_client,
330 chromeos::disks::DiskMountManager* disk_mount_manager, 326 chromeos::disks::DiskMountManager* disk_mount_manager,
(...skipping 21 matching lines...) Expand all
352 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) 348 if (chromeos::ProfileHelper::IsSigninProfile(profile_))
353 return; 349 return;
354 350
355 // Register 'Downloads' folder for the profile to the file system. 351 // Register 'Downloads' folder for the profile to the file system.
356 const base::FilePath downloads = 352 const base::FilePath downloads =
357 file_manager::util::GetDownloadsFolderForProfile(profile_); 353 file_manager::util::GetDownloadsFolderForProfile(profile_);
358 const bool success = RegisterDownloadsMountPoint(profile_, downloads); 354 const bool success = RegisterDownloadsMountPoint(profile_, downloads);
359 DCHECK(success); 355 DCHECK(success);
360 356
361 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 357 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
362 Volume::CreateForDownloads(downloads)); 358 make_linked_ptr(Volume::CreateForDownloads(downloads)));
363 359
364 // Subscribe to DriveIntegrationService. 360 // Subscribe to DriveIntegrationService.
365 if (drive_integration_service_) { 361 if (drive_integration_service_) {
366 drive_integration_service_->AddObserver(this); 362 drive_integration_service_->AddObserver(this);
367 if (drive_integration_service_->IsMounted()) { 363 if (drive_integration_service_->IsMounted()) {
368 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 364 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
369 Volume::CreateForDrive(profile_)); 365 make_linked_ptr(Volume::CreateForDrive(profile_)));
370 } 366 }
371 } 367 }
372 368
373 // Subscribe to DiskMountManager. 369 // Subscribe to DiskMountManager.
374 disk_mount_manager_->AddObserver(this); 370 disk_mount_manager_->AddObserver(this);
375 disk_mount_manager_->EnsureMountInfoRefreshed( 371 disk_mount_manager_->EnsureMountInfoRefreshed(
376 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed, 372 base::Bind(&VolumeManager::OnDiskMountManagerRefreshed,
377 weak_ptr_factory_.GetWeakPtr()), 373 weak_ptr_factory_.GetWeakPtr()),
378 false /* force */); 374 false /* force */);
379 375
380 // Subscribe to FileSystemProviderService and register currently mounted 376 // Subscribe to FileSystemProviderService and register currently mounted
381 // volumes for the profile. 377 // volumes for the profile.
382 if (file_system_provider_service_) { 378 if (file_system_provider_service_) {
383 using chromeos::file_system_provider::ProvidedFileSystemInfo; 379 using chromeos::file_system_provider::ProvidedFileSystemInfo;
384 file_system_provider_service_->AddObserver(this); 380 file_system_provider_service_->AddObserver(this);
385 381
386 std::vector<ProvidedFileSystemInfo> file_system_info_list = 382 std::vector<ProvidedFileSystemInfo> file_system_info_list =
387 file_system_provider_service_->GetProvidedFileSystemInfoList(); 383 file_system_provider_service_->GetProvidedFileSystemInfoList();
388 for (size_t i = 0; i < file_system_info_list.size(); ++i) { 384 for (size_t i = 0; i < file_system_info_list.size(); ++i) {
389 std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem( 385 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem(
390 file_system_info_list[i], MOUNT_CONTEXT_AUTO); 386 file_system_info_list[i], MOUNT_CONTEXT_AUTO));
391 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); 387 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
392 } 388 }
393 } 389 }
394 390
395 // Subscribe to Profile Preference change. 391 // Subscribe to Profile Preference change.
396 pref_change_registrar_.Init(profile_->GetPrefs()); 392 pref_change_registrar_.Init(profile_->GetPrefs());
397 pref_change_registrar_.Add( 393 pref_change_registrar_.Add(
398 prefs::kExternalStorageDisabled, 394 prefs::kExternalStorageDisabled,
399 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, 395 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged,
400 weak_ptr_factory_.GetWeakPtr())); 396 weak_ptr_factory_.GetWeakPtr()));
401 pref_change_registrar_.Add( 397 pref_change_registrar_.Add(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 450 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
455 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 451 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
456 DCHECK(observer); 452 DCHECK(observer);
457 observers_.RemoveObserver(observer); 453 observers_.RemoveObserver(observer);
458 } 454 }
459 455
460 std::vector<base::WeakPtr<Volume>> VolumeManager::GetVolumeList() { 456 std::vector<base::WeakPtr<Volume>> VolumeManager::GetVolumeList() {
461 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 457 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
462 458
463 std::vector<base::WeakPtr<Volume>> result; 459 std::vector<base::WeakPtr<Volume>> result;
464 result.reserve(mounted_volumes_.size());
465 for (const auto& pair : mounted_volumes_) { 460 for (const auto& pair : mounted_volumes_) {
466 result.push_back(pair.second->AsWeakPtr()); 461 result.push_back(pair.second->AsWeakPtr());
467 } 462 }
468 return result; 463 return result;
469 } 464 }
470 465
471 base::WeakPtr<Volume> VolumeManager::FindVolumeById( 466 base::WeakPtr<Volume> VolumeManager::FindVolumeById(
472 const std::string& volume_id) { 467 const std::string& volume_id) {
473 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 468 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
474 469
475 const auto it = mounted_volumes_.find(volume_id); 470 const auto it = mounted_volumes_.find(volume_id);
476 if (it != mounted_volumes_.end()) 471 if (it != mounted_volumes_.end())
477 return it->second->AsWeakPtr(); 472 return it->second->AsWeakPtr();
478 return base::WeakPtr<Volume>(); 473 return base::WeakPtr<Volume>();
479 } 474 }
480 475
481 bool VolumeManager::RegisterDownloadsDirectoryForTesting( 476 bool VolumeManager::RegisterDownloadsDirectoryForTesting(
482 const base::FilePath& path) { 477 const base::FilePath& path) {
483 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 478 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
484 479
485 base::FilePath old_path; 480 base::FilePath old_path;
486 if (FindDownloadsMountPointPath(profile_, &old_path)) { 481 if (FindDownloadsMountPointPath(profile_, &old_path)) {
487 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, 482 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
488 *Volume::CreateForDownloads(old_path)); 483 make_linked_ptr(Volume::CreateForDownloads(old_path)));
489 } 484 }
490 485
491 bool success = RegisterDownloadsMountPoint(profile_, path); 486 bool success = RegisterDownloadsMountPoint(profile_, path);
492 DoMountEvent( 487 DoMountEvent(
493 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH, 488 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH,
494 Volume::CreateForDownloads(path)); 489 make_linked_ptr(Volume::CreateForDownloads(path)));
495 return success; 490 return success;
496 } 491 }
497 492
498 void VolumeManager::AddVolumeForTesting(const base::FilePath& path, 493 void VolumeManager::AddVolumeForTesting(const base::FilePath& path,
499 VolumeType volume_type, 494 VolumeType volume_type,
500 chromeos::DeviceType device_type, 495 chromeos::DeviceType device_type,
501 bool read_only) { 496 bool read_only) {
502 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 497 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
503 DoMountEvent( 498 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
504 chromeos::MOUNT_ERROR_NONE, 499 make_linked_ptr(Volume::CreateForTesting(
505 Volume::CreateForTesting(path, volume_type, device_type, read_only)); 500 path, volume_type, device_type, read_only)));
506 } 501 }
507 502
508 void VolumeManager::AddVolumeForTesting(std::unique_ptr<Volume> volume) { 503 void VolumeManager::AddVolumeForTesting(const linked_ptr<Volume>& volume) {
509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 504 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
510 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); 505 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
511 } 506 }
512 507
513 void VolumeManager::OnFileSystemMounted() { 508 void VolumeManager::OnFileSystemMounted() {
514 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 509 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
515 510
516 // Raise mount event. 511 // Raise mount event.
517 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 512 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
518 // or network is unreachable. These two errors will be handled later. 513 // or network is unreachable. These two errors will be handled later.
519 DoMountEvent(chromeos::MOUNT_ERROR_NONE, Volume::CreateForDrive(profile_)); 514 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
515 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
520 } 516 }
521 517
522 void VolumeManager::OnFileSystemBeingUnmounted() { 518 void VolumeManager::OnFileSystemBeingUnmounted() {
523 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
524 520
525 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *Volume::CreateForDrive(profile_)); 521 linked_ptr<Volume> volume(Volume::CreateForDrive(profile_));
522 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume);
526 } 523 }
527 524
528 void VolumeManager::OnDiskEvent( 525 void VolumeManager::OnDiskEvent(
529 chromeos::disks::DiskMountManager::DiskEvent event, 526 chromeos::disks::DiskMountManager::DiskEvent event,
530 const chromeos::disks::DiskMountManager::Disk* disk) { 527 const chromeos::disks::DiskMountManager::Disk* disk) {
531 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 528 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
532 529
533 // Disregard hidden devices. 530 // Disregard hidden devices.
534 if (disk->is_hidden()) 531 if (disk->is_hidden())
535 return; 532 return;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 file_system->MarkCacheFileAsUnmounted( 622 file_system->MarkCacheFileAsUnmounted(
626 base::FilePath(mount_info.source_path), 623 base::FilePath(mount_info.source_path),
627 base::Bind(&drive::util::EmptyFileOperationCallback)); 624 base::Bind(&drive::util::EmptyFileOperationCallback));
628 } 625 }
629 } 626 }
630 } 627 }
631 628
632 // Notify a mounting/unmounting event to observers. 629 // Notify a mounting/unmounting event to observers.
633 const chromeos::disks::DiskMountManager::Disk* const disk = 630 const chromeos::disks::DiskMountManager::Disk* const disk =
634 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); 631 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path);
635 std::unique_ptr<Volume> volume = Volume::CreateForRemovable(mount_info, disk); 632 linked_ptr<Volume> volume(Volume::CreateForRemovable(mount_info, disk));
636 switch (event) { 633 switch (event) {
637 case chromeos::disks::DiskMountManager::MOUNTING: { 634 case chromeos::disks::DiskMountManager::MOUNTING: {
638 DoMountEvent(error_code, std::move(volume)); 635 DoMountEvent(error_code, volume);
639 return; 636 return;
640 } 637 }
641 case chromeos::disks::DiskMountManager::UNMOUNTING: 638 case chromeos::disks::DiskMountManager::UNMOUNTING:
642 DoUnmountEvent(error_code, *volume); 639 DoUnmountEvent(error_code, volume);
643 return; 640 return;
644 } 641 }
645 NOTREACHED(); 642 NOTREACHED();
646 } 643 }
647 644
648 void VolumeManager::OnFormatEvent( 645 void VolumeManager::OnFormatEvent(
649 chromeos::disks::DiskMountManager::FormatEvent event, 646 chromeos::disks::DiskMountManager::FormatEvent event,
650 chromeos::FormatError error_code, 647 chromeos::FormatError error_code,
651 const std::string& device_path) { 648 const std::string& device_path) {
652 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 649 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 MountContext volume_context = MOUNT_CONTEXT_UNKNOWN; 687 MountContext volume_context = MOUNT_CONTEXT_UNKNOWN;
691 switch (context) { 688 switch (context) {
692 case chromeos::file_system_provider::MOUNT_CONTEXT_USER: 689 case chromeos::file_system_provider::MOUNT_CONTEXT_USER:
693 volume_context = MOUNT_CONTEXT_USER; 690 volume_context = MOUNT_CONTEXT_USER;
694 break; 691 break;
695 case chromeos::file_system_provider::MOUNT_CONTEXT_RESTORE: 692 case chromeos::file_system_provider::MOUNT_CONTEXT_RESTORE:
696 volume_context = MOUNT_CONTEXT_AUTO; 693 volume_context = MOUNT_CONTEXT_AUTO;
697 break; 694 break;
698 } 695 }
699 696
700 std::unique_ptr<Volume> volume = 697 linked_ptr<Volume> volume(
701 Volume::CreateForProvidedFileSystem(file_system_info, volume_context); 698 Volume::CreateForProvidedFileSystem(file_system_info, volume_context));
702 699
703 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, 700 // TODO(mtomasz): Introduce own type, and avoid using MountError internally,
704 // since it is related to cros disks only. 701 // since it is related to cros disks only.
705 chromeos::MountError mount_error; 702 chromeos::MountError mount_error;
706 switch (error) { 703 switch (error) {
707 case base::File::FILE_OK: 704 case base::File::FILE_OK:
708 mount_error = chromeos::MOUNT_ERROR_NONE; 705 mount_error = chromeos::MOUNT_ERROR_NONE;
709 break; 706 break;
710 case base::File::FILE_ERROR_EXISTS: 707 case base::File::FILE_ERROR_EXISTS:
711 mount_error = chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED; 708 mount_error = chromeos::MOUNT_ERROR_PATH_ALREADY_MOUNTED;
712 break; 709 break;
713 default: 710 default:
714 mount_error = chromeos::MOUNT_ERROR_UNKNOWN; 711 mount_error = chromeos::MOUNT_ERROR_UNKNOWN;
715 break; 712 break;
716 } 713 }
717 714
718 DoMountEvent(mount_error, std::move(volume)); 715 DoMountEvent(mount_error, volume);
719 } 716 }
720 717
721 void VolumeManager::OnProvidedFileSystemUnmount( 718 void VolumeManager::OnProvidedFileSystemUnmount(
722 const chromeos::file_system_provider::ProvidedFileSystemInfo& 719 const chromeos::file_system_provider::ProvidedFileSystemInfo&
723 file_system_info, 720 file_system_info,
724 base::File::Error error) { 721 base::File::Error error) {
725 // TODO(mtomasz): Introduce own type, and avoid using MountError internally, 722 // TODO(mtomasz): Introduce own type, and avoid using MountError internally,
726 // since it is related to cros disks only. 723 // since it is related to cros disks only.
727 const chromeos::MountError mount_error = error == base::File::FILE_OK 724 const chromeos::MountError mount_error = error == base::File::FILE_OK
728 ? chromeos::MOUNT_ERROR_NONE 725 ? chromeos::MOUNT_ERROR_NONE
729 : chromeos::MOUNT_ERROR_UNKNOWN; 726 : chromeos::MOUNT_ERROR_UNKNOWN;
730 std::unique_ptr<Volume> volume = Volume::CreateForProvidedFileSystem( 727 linked_ptr<Volume> volume(Volume::CreateForProvidedFileSystem(
731 file_system_info, MOUNT_CONTEXT_UNKNOWN); 728 file_system_info, MOUNT_CONTEXT_UNKNOWN));
732 DoUnmountEvent(mount_error, *volume); 729 DoUnmountEvent(mount_error, volume);
733 } 730 }
734 731
735 void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback( 732 void VolumeManager::OnExternalStorageDisabledChangedUnmountCallback(
736 chromeos::MountError error_code) { 733 chromeos::MountError error_code) {
737 if (disk_mount_manager_->mount_points().empty()) 734 if (disk_mount_manager_->mount_points().empty())
738 return; 735 return;
739 // Repeat until unmount all paths 736 // Repeat until unmount all paths
740 const std::string& mount_path = 737 const std::string& mount_path =
741 disk_mount_manager_->mount_points().begin()->second.mount_path; 738 disk_mount_manager_->mount_points().begin()->second.mount_path;
742 disk_mount_manager_->UnmountPath( 739 disk_mount_manager_->UnmountPath(
743 mount_path, chromeos::UNMOUNT_OPTIONS_NONE, 740 mount_path, chromeos::UNMOUNT_OPTIONS_NONE,
744 base::Bind( 741 base::Bind(
745 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback, 742 &VolumeManager::OnExternalStorageDisabledChangedUnmountCallback,
746 weak_ptr_factory_.GetWeakPtr())); 743 weak_ptr_factory_.GetWeakPtr()));
747 } 744 }
748 745
749 void VolumeManager::OnArcPlayStoreEnabledChanged(bool enabled) { 746 void VolumeManager::OnArcPlayStoreEnabledChanged(bool enabled) {
750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 747 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
751 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature)); 748 DCHECK(base::FeatureList::IsEnabled(arc::kMediaViewFeature));
752 DCHECK(arc::IsArcAllowedForProfile(profile_)); 749 DCHECK(arc::IsArcAllowedForProfile(profile_));
753 750
754 if (enabled == arc_volumes_mounted_) 751 if (enabled == arc_volumes_mounted_)
755 return; 752 return;
756 753
757 if (enabled) { 754 if (enabled) {
758 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 755 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
759 Volume::CreateForMediaView(arc::kImagesRootDocumentId)); 756 linked_ptr<Volume>(
757 Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
760 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 758 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
761 Volume::CreateForMediaView(arc::kVideosRootDocumentId)); 759 linked_ptr<Volume>(
760 Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
762 DoMountEvent(chromeos::MOUNT_ERROR_NONE, 761 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
763 Volume::CreateForMediaView(arc::kAudioRootDocumentId)); 762 linked_ptr<Volume>(
763 Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
764 } else { 764 } else {
765 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, 765 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
766 *Volume::CreateForMediaView(arc::kImagesRootDocumentId)); 766 linked_ptr<Volume>(
767 Volume::CreateForMediaView(arc::kImagesRootDocumentId)));
767 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, 768 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
768 *Volume::CreateForMediaView(arc::kVideosRootDocumentId)); 769 linked_ptr<Volume>(
770 Volume::CreateForMediaView(arc::kVideosRootDocumentId)));
769 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, 771 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
770 *Volume::CreateForMediaView(arc::kAudioRootDocumentId)); 772 linked_ptr<Volume>(
773 Volume::CreateForMediaView(arc::kAudioRootDocumentId)));
771 } 774 }
772 775
773 arc_volumes_mounted_ = enabled; 776 arc_volumes_mounted_ = enabled;
774 } 777 }
775 778
776 void VolumeManager::OnExternalStorageDisabledChanged() { 779 void VolumeManager::OnExternalStorageDisabledChanged() {
777 // If the policy just got disabled we have to unmount every device currently 780 // If the policy just got disabled we have to unmount every device currently
778 // mounted. The opposite is fine - we can let the user re-plug their device to 781 // mounted. The opposite is fine - we can let the user re-plug their device to
779 // make it available. 782 // make it available.
780 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 783 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 kFilesystemTypeGenericHierarchical || 851 kFilesystemTypeGenericHierarchical ||
849 GetExternalStorageAccessMode(profile_) == 852 GetExternalStorageAccessMode(profile_) ==
850 chromeos::MOUNT_ACCESS_MODE_READ_ONLY; 853 chromeos::MOUNT_ACCESS_MODE_READ_ONLY;
851 854
852 content::BrowserThread::PostTask( 855 content::BrowserThread::PostTask(
853 content::BrowserThread::IO, FROM_HERE, 856 content::BrowserThread::IO, FROM_HERE,
854 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem, 857 base::Bind(&MTPDeviceMapService::RegisterMTPFileSystem,
855 base::Unretained(MTPDeviceMapService::GetInstance()), 858 base::Unretained(MTPDeviceMapService::GetInstance()),
856 info.location(), fsid, read_only)); 859 info.location(), fsid, read_only));
857 860
858 std::unique_ptr<Volume> volume = Volume::CreateForMTP(path, label, read_only); 861 linked_ptr<Volume> volume(Volume::CreateForMTP(path, label, read_only));
859 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(volume)); 862 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume);
860 } 863 }
861 864
862 void VolumeManager::OnRemovableStorageDetached( 865 void VolumeManager::OnRemovableStorageDetached(
863 const storage_monitor::StorageInfo& info) { 866 const storage_monitor::StorageInfo& info) {
864 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id())) 867 if (!storage_monitor::StorageInfo::IsMTPDevice(info.device_id()))
865 return; 868 return;
866 869
867 for (const auto& mounted_volume : mounted_volumes_) { 870 for (const auto mounted_volume : mounted_volumes_) {
868 if (mounted_volume.second->source_path().value() == info.location()) { 871 if (mounted_volume.second->source_path().value() == info.location()) {
869 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, *mounted_volume.second.get()); 872 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, mounted_volume.second);
870 873
871 const std::string fsid = GetMountPointNameForMediaStorage(info); 874 const std::string fsid = GetMountPointNameForMediaStorage(info);
872 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid); 875 storage::ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(fsid);
873 content::BrowserThread::PostTask( 876 content::BrowserThread::PostTask(
874 content::BrowserThread::IO, FROM_HERE, base::Bind( 877 content::BrowserThread::IO, FROM_HERE, base::Bind(
875 &MTPDeviceMapService::RevokeMTPFileSystem, 878 &MTPDeviceMapService::RevokeMTPFileSystem,
876 base::Unretained(MTPDeviceMapService::GetInstance()), 879 base::Unretained(MTPDeviceMapService::GetInstance()),
877 fsid)); 880 fsid));
878 return; 881 return;
879 } 882 }
880 } 883 }
881 } 884 }
882 885
883 void VolumeManager::OnDiskMountManagerRefreshed(bool success) { 886 void VolumeManager::OnDiskMountManagerRefreshed(bool success) {
884 if (!success) { 887 if (!success) {
885 LOG(ERROR) << "Failed to refresh disk mount manager"; 888 LOG(ERROR) << "Failed to refresh disk mount manager";
886 return; 889 return;
887 } 890 }
888 891
889 std::vector<std::unique_ptr<Volume>> archives; 892 std::vector<linked_ptr<Volume>> archives;
890 893
891 const chromeos::disks::DiskMountManager::MountPointMap& mount_points = 894 const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
892 disk_mount_manager_->mount_points(); 895 disk_mount_manager_->mount_points();
893 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = 896 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
894 mount_points.begin(); 897 mount_points.begin();
895 it != mount_points.end(); 898 it != mount_points.end();
896 ++it) { 899 ++it) {
897 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 900 if (it->second.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
898 // Archives are mounted after other types of volume. See below. 901 // Archives are mounted after other types of volume. See below.
899 archives.push_back(Volume::CreateForRemovable(it->second, nullptr)); 902 archives.push_back(
903 make_linked_ptr(Volume::CreateForRemovable(it->second, NULL)));
900 continue; 904 continue;
901 } 905 }
902 DoMountEvent( 906 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
903 chromeos::MOUNT_ERROR_NONE, 907 make_linked_ptr(Volume::CreateForRemovable(
904 Volume::CreateForRemovable( 908 it->second, disk_mount_manager_->FindDiskBySourcePath(
905 it->second, 909 it->second.source_path))));
906 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)));
907 } 910 }
908 911
909 // We mount archives only if they are opened from currently mounted volumes. 912 // We mount archives only if they are opened from currently mounted volumes.
910 // To check the condition correctly in DoMountEvent, we care about the order. 913 // To check the condition correctly in DoMountEvent, we care about the order.
911 std::vector<bool> done(archives.size(), false); 914 std::vector<bool> done(archives.size(), false);
912 for (size_t i = 0; i < archives.size(); ++i) { 915 for (size_t i = 0; i < archives.size(); ++i) {
913 if (done[i]) 916 if (done[i])
914 continue; 917 continue;
915 918
916 std::vector<std::unique_ptr<Volume>> chain; 919 std::vector<linked_ptr<Volume>> chain;
917 // done[x] = true means archives[x] is null and that volume is in |chain|.
918 done[i] = true; 920 done[i] = true;
919 chain.push_back(std::move(archives[i])); 921 chain.push_back(archives[i]);
920 922
921 // If archives[i]'s source_path is in another archive, mount it first. 923 // If archives[i]'s source_path is in another archive, mount it first.
922 for (size_t parent = i + 1; parent < archives.size(); ++parent) { 924 for (size_t parent = i + 1; parent < archives.size(); ++parent) {
923 if (!done[parent] && 925 if (!done[parent] &&
924 archives[parent]->mount_path().IsParent( 926 archives[parent]->mount_path().IsParent(
925 chain.back()->source_path())) { 927 chain.back()->source_path())) {
926 // done[parent] started false, so archives[parent] is non-null.
927 done[parent] = true; 928 done[parent] = true;
928 chain.push_back(std::move(archives[parent])); 929 chain.push_back(archives[parent]);
929 parent = i + 1; // Search archives[parent]'s parent from the beginning. 930 parent = i + 1; // Search archives[parent]'s parent from the beginning.
930 } 931 }
931 } 932 }
932 933
933 // Mount from the tail of chain. 934 // Mount from the tail of chain.
934 for (size_t i = chain.size(); i > 0; --i) { 935 for (size_t i = chain.size(); i > 0; --i) {
935 DoMountEvent(chromeos::MOUNT_ERROR_NONE, std::move(chain[i - 1])); 936 DoMountEvent(chromeos::MOUNT_ERROR_NONE, chain[i - 1]);
936 } 937 }
937 } 938 }
938 } 939 }
939 940
940 void VolumeManager::OnStorageMonitorInitialized() { 941 void VolumeManager::OnStorageMonitorInitialized() {
941 std::vector<storage_monitor::StorageInfo> storages = 942 std::vector<storage_monitor::StorageInfo> storages =
942 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages(); 943 storage_monitor::StorageMonitor::GetInstance()->GetAllAvailableStorages();
943 for (size_t i = 0; i < storages.size(); ++i) 944 for (size_t i = 0; i < storages.size(); ++i)
944 OnRemovableStorageAttached(storages[i]); 945 OnRemovableStorageAttached(storages[i]);
945 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this); 946 storage_monitor::StorageMonitor::GetInstance()->AddObserver(this);
946 } 947 }
947 948
948 void VolumeManager::DoMountEvent(chromeos::MountError error_code, 949 void VolumeManager::DoMountEvent(chromeos::MountError error_code,
949 std::unique_ptr<Volume> volume) { 950 const linked_ptr<Volume>& volume) {
950 // Archive files are mounted globally in system. We however don't want to show 951 // Archive files are mounted globally in system. We however don't want to show
951 // archives from profile-specific folders (Drive/Downloads) of other users in 952 // archives from profile-specific folders (Drive/Downloads) of other users in
952 // multi-profile session. To this end, we filter out archives not on the 953 // multi-profile session. To this end, we filter out archives not on the
953 // volumes already mounted on this VolumeManager instance. 954 // volumes already mounted on this VolumeManager instance.
954 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) { 955 if (volume->type() == VOLUME_TYPE_MOUNTED_ARCHIVE_FILE) {
955 // Source may be in Drive cache folder under the current profile directory. 956 // Source may be in Drive cache folder under the current profile directory.
956 bool from_current_profile = 957 bool from_current_profile =
957 profile_->GetPath().IsParent(volume->source_path()); 958 profile_->GetPath().IsParent(volume->source_path());
958 for (const auto& mounted_volume : mounted_volumes_) { 959 for (const auto& mounted_volume : mounted_volumes_) {
959 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) { 960 if (mounted_volume.second->mount_path().IsParent(volume->source_path())) {
960 from_current_profile = true; 961 from_current_profile = true;
961 break; 962 break;
962 } 963 }
963 } 964 }
964 if (!from_current_profile) 965 if (!from_current_profile)
965 return; 966 return;
966 } 967 }
967 968
968 // Filter out removable disks if forbidden by policy for this profile. 969 // Filter out removable disks if forbidden by policy for this profile.
969 if (volume->type() == VOLUME_TYPE_REMOVABLE_DISK_PARTITION && 970 if (volume->type() == VOLUME_TYPE_REMOVABLE_DISK_PARTITION &&
970 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 971 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
971 return; 972 return;
972 } 973 }
973 974
974 Volume* raw_volume = volume.get();
975 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) { 975 if (error_code == chromeos::MOUNT_ERROR_NONE || volume->mount_condition()) {
976 mounted_volumes_[volume->volume_id()] = std::move(volume); 976 mounted_volumes_[volume->volume_id()] = volume;
977 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", raw_volume->type(), 977 UMA_HISTOGRAM_ENUMERATION("FileBrowser.VolumeType", volume->type(),
978 NUM_VOLUME_TYPE); 978 NUM_VOLUME_TYPE);
979 } 979 }
980 980
981 for (auto& observer : observers_) 981 for (auto& observer : observers_)
982 observer.OnVolumeMounted(error_code, *raw_volume); 982 observer.OnVolumeMounted(error_code, *volume);
983 } 983 }
984 984
985 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code, 985 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code,
986 const Volume& volume) { 986 const linked_ptr<Volume>& volume) {
987 auto iter = mounted_volumes_.find(volume.volume_id()); 987 if (mounted_volumes_.find(volume->volume_id()) == mounted_volumes_.end())
988 if (iter == mounted_volumes_.end())
989 return; 988 return;
990 if (error_code == chromeos::MOUNT_ERROR_NONE) 989 if (error_code == chromeos::MOUNT_ERROR_NONE)
991 mounted_volumes_.erase(iter); 990 mounted_volumes_.erase(volume->volume_id());
992 991
993 for (auto& observer : observers_) 992 for (auto& observer : observers_)
994 observer.OnVolumeUnmounted(error_code, volume); 993 observer.OnVolumeUnmounted(error_code, *volume.get());
995 } 994 }
996 995
997 } // namespace file_manager 996 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698