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

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

Issue 160483004: Keep track of the list of currently mounted volumes in C++-side VolumeManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 6 years, 10 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 | Annotate | Revision Log
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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 base::FilePath new_path; 222 base::FilePath new_path;
223 if (!old_path.empty() && 223 if (!old_path.empty() &&
224 file_manager::util::MigratePathFromOldFormat(profile_, 224 file_manager::util::MigratePathFromOldFormat(profile_,
225 old_path, &new_path)) { 225 old_path, &new_path)) {
226 profile_->GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory, 226 profile_->GetPrefs()->SetFilePath(prefs::kSelectFileLastDirectory,
227 new_path); 227 new_path);
228 } 228 }
229 229
230 // Register 'Downloads' folder for the profile to the file system. 230 // Register 'Downloads' folder for the profile to the file system.
231 if (!chromeos::ProfileHelper::IsSigninProfile(profile_)) { 231 if (!chromeos::ProfileHelper::IsSigninProfile(profile_)) {
232 bool success = RegisterDownloadsMountPoint( 232 const base::FilePath downloads =
233 profile_, 233 file_manager::util::GetDownloadsFolderForProfile(profile_);
234 file_manager::util::GetDownloadsFolderForProfile(profile_)); 234 bool success = RegisterDownloadsMountPoint(profile_, downloads);
hirono 2014/02/13 05:09:06 nit: const?
kinaba 2014/02/13 06:25:46 Done.
235 DCHECK(success); 235 DCHECK(success);
236
237 DoMountEvent(chromeos::MOUNT_ERROR_NONE,
238 CreateDownloadsVolumeInfo(downloads),
239 false);
mtomasz 2014/02/13 05:22:50 nit: Can we add a comment what is this false?
kinaba 2014/02/13 06:26:14 Done.
236 } 240 }
237 241
238 // Subscribe to DriveIntegrationService. 242 // Subscribe to DriveIntegrationService.
239 if (drive_integration_service_) 243 if (drive_integration_service_) {
240 drive_integration_service_->AddObserver(this); 244 drive_integration_service_->AddObserver(this);
245 if (drive_integration_service_->IsMounted()) {
246 DoMountEvent(
247 chromeos::MOUNT_ERROR_NONE, CreateDriveVolumeInfo(profile_), false);
248 }
249 }
241 250
242 // Subscribe to DiskMountManager. 251 // Subscribe to DiskMountManager.
243 disk_mount_manager_->AddObserver(this); 252 disk_mount_manager_->AddObserver(this);
253
254 const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
255 disk_mount_manager_->mount_points();
256 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
257 mount_points.begin();
258 it != mount_points.end();
259 ++it) {
260 DoMountEvent(
261 chromeos::MOUNT_ERROR_NONE,
262 CreateVolumeInfoFromMountPointInfo(
263 it->second,
264 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)),
265 false);
266 }
267
244 disk_mount_manager_->RequestMountInfoRefresh(); 268 disk_mount_manager_->RequestMountInfoRefresh();
245 269
246 // Subscribe to Profile Preference change. 270 // Subscribe to Profile Preference change.
247 pref_change_registrar_.Init(profile_->GetPrefs()); 271 pref_change_registrar_.Init(profile_->GetPrefs());
248 pref_change_registrar_.Add( 272 pref_change_registrar_.Add(
249 prefs::kExternalStorageDisabled, 273 prefs::kExternalStorageDisabled,
250 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged, 274 base::Bind(&VolumeManager::OnExternalStorageDisabledChanged,
251 base::Unretained(this))); 275 base::Unretained(this)));
252 276
253 if (CommandLine::ForCurrentProcess()->HasSwitch( 277 if (CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 22 matching lines...) Expand all
276 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) { 300 void VolumeManager::RemoveObserver(VolumeManagerObserver* observer) {
277 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 301 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
278 DCHECK(observer); 302 DCHECK(observer);
279 observers_.RemoveObserver(observer); 303 observers_.RemoveObserver(observer);
280 } 304 }
281 305
282 std::vector<VolumeInfo> VolumeManager::GetVolumeInfoList() const { 306 std::vector<VolumeInfo> VolumeManager::GetVolumeInfoList() const {
283 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 307 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
284 308
285 std::vector<VolumeInfo> result; 309 std::vector<VolumeInfo> result;
286 310 for (std::map<std::string, VolumeInfo>::const_iterator iter =
287 // Adds "Drive" volume. 311 mounted_volumes_.begin();
288 if (drive_integration_service_ && drive_integration_service_->IsMounted()) 312 iter != mounted_volumes_.end();
289 result.push_back(CreateDriveVolumeInfo(profile_)); 313 ++iter) {
290 314 result.push_back(iter->second);
291 // Adds "Downloads".
292 // Usually, the path of the directory is where we registered in Initialize(),
293 // but in tests, the mount point may be overridden. To take it into account,
294 // here we explicitly retrieves the path from the file API mount points.
295 base::FilePath downloads;
296 if (FindDownloadsMountPointPath(profile_, &downloads))
297 result.push_back(CreateDownloadsVolumeInfo(downloads));
298
299 // Adds disks (both removable disks and zip archives).
300 const chromeos::disks::DiskMountManager::MountPointMap& mount_points =
301 disk_mount_manager_->mount_points();
302 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
303 mount_points.begin();
304 it != mount_points.end(); ++it) {
305 result.push_back(CreateVolumeInfoFromMountPointInfo(
306 it->second,
307 disk_mount_manager_->FindDiskBySourcePath(it->second.source_path)));
308 } 315 }
309
310 if (CommandLine::ForCurrentProcess()->HasSwitch(
311 switches::kEnablePrivetStorage)) {
312 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i =
313 privet_volume_lister_->volume_list().begin();
314 i != privet_volume_lister_->volume_list().end(); i++) {
315 result.push_back(CreatePrivetVolumeInfo(*i));
316 }
317 }
318
319 return result; 316 return result;
320 } 317 }
321 318
322 bool VolumeManager::FindVolumeInfoById(const std::string& volume_id, 319 bool VolumeManager::FindVolumeInfoById(const std::string& volume_id,
323 VolumeInfo* result) const { 320 VolumeInfo* result) const {
324 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 321 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
325 DCHECK(result); 322 DCHECK(result);
326 323
327 std::vector<VolumeInfo> info_list = GetVolumeInfoList(); 324 std::map<std::string, VolumeInfo>::const_iterator iter =
328 for (size_t i = 0; i < info_list.size(); ++i) { 325 mounted_volumes_.find(volume_id);
329 if (info_list[i].volume_id == volume_id) { 326 if (iter == mounted_volumes_.end())
330 *result = info_list[i]; 327 return false;
331 return true; 328 *result = iter->second;
332 } 329 return true;
333 }
334
335 return false;
336 } 330 }
337 331
338 bool VolumeManager::RegisterDownloadsDirectoryForTesting( 332 bool VolumeManager::RegisterDownloadsDirectoryForTesting(
339 const base::FilePath& path) { 333 const base::FilePath& path) {
340 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
341 return RegisterDownloadsMountPoint(profile_, path); 335
336 base::FilePath old_path;
337 if (FindDownloadsMountPointPath(profile_, &old_path)) {
338 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE,
339 CreateDownloadsVolumeInfo(old_path));
340 }
341
342 bool success = RegisterDownloadsMountPoint(profile_, path);
343 DoMountEvent(
344 success ? chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_INVALID_PATH,
345 CreateDownloadsVolumeInfo(path),
346 false);
347 return success;
342 } 348 }
343 349
344 void VolumeManager::OnFileSystemMounted() { 350 void VolumeManager::OnFileSystemMounted() {
345 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 351 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
346 352
347 // Raise mount event. 353 // Raise mount event.
348 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 354 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
349 // or network is unreachable. These two errors will be handled later. 355 // or network is unreachable. These two errors will be handled later.
350 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); 356 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_);
351 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 357 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false);
352 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE,
353 volume_info,
354 false)); // Not remounting.
355 } 358 }
356 359
357 void VolumeManager::OnFileSystemBeingUnmounted() { 360 void VolumeManager::OnFileSystemBeingUnmounted() {
358 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 361 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
359 362
360 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_); 363 VolumeInfo volume_info = CreateDriveVolumeInfo(profile_);
361 FOR_EACH_OBSERVER( 364 DoUnmountEvent(chromeos::MOUNT_ERROR_NONE, volume_info);
362 VolumeManagerObserver, observers_,
363 OnVolumeUnmounted(chromeos::MOUNT_ERROR_NONE, volume_info));
364 } 365 }
365 366
366 void VolumeManager::OnDiskEvent( 367 void VolumeManager::OnDiskEvent(
367 chromeos::disks::DiskMountManager::DiskEvent event, 368 chromeos::disks::DiskMountManager::DiskEvent event,
368 const chromeos::disks::DiskMountManager::Disk* disk) { 369 const chromeos::disks::DiskMountManager::Disk* disk) {
369 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 370 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
370 371
371 // Disregard hidden devices. 372 // Disregard hidden devices.
372 if (disk->is_hidden()) 373 if (disk->is_hidden())
373 return; 374 return;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 471
471 // Notify a mounting/unmounting event to observers. 472 // Notify a mounting/unmounting event to observers.
472 const chromeos::disks::DiskMountManager::Disk* disk = 473 const chromeos::disks::DiskMountManager::Disk* disk =
473 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path); 474 disk_mount_manager_->FindDiskBySourcePath(mount_info.source_path);
474 VolumeInfo volume_info = 475 VolumeInfo volume_info =
475 CreateVolumeInfoFromMountPointInfo(mount_info, disk); 476 CreateVolumeInfoFromMountPointInfo(mount_info, disk);
476 switch (event) { 477 switch (event) {
477 case chromeos::disks::DiskMountManager::MOUNTING: { 478 case chromeos::disks::DiskMountManager::MOUNTING: {
478 bool is_remounting = 479 bool is_remounting =
479 disk && mounted_disk_monitor_->DiskIsRemounting(*disk); 480 disk && mounted_disk_monitor_->DiskIsRemounting(*disk);
480 FOR_EACH_OBSERVER( 481 DoMountEvent(error_code, volume_info, is_remounting);
481 VolumeManagerObserver, observers_,
482 OnVolumeMounted(error_code, volume_info, is_remounting));
483 return; 482 return;
484 } 483 }
485 case chromeos::disks::DiskMountManager::UNMOUNTING: 484 case chromeos::disks::DiskMountManager::UNMOUNTING:
486 FOR_EACH_OBSERVER(VolumeManagerObserver, observers_, 485 DoUnmountEvent(error_code, volume_info);
487 OnVolumeUnmounted(error_code, volume_info));
488 return; 486 return;
489 } 487 }
490 NOTREACHED(); 488 NOTREACHED();
491 } 489 }
492 490
493 void VolumeManager::OnFormatEvent( 491 void VolumeManager::OnFormatEvent(
494 chromeos::disks::DiskMountManager::FormatEvent event, 492 chromeos::disks::DiskMountManager::FormatEvent event,
495 chromeos::FormatError error_code, 493 chromeos::FormatError error_code,
496 const std::string& device_path) { 494 const std::string& device_path) {
497 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 495 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 chromeos::disks::DiskMountManager::UnmountPathCallback()); 541 chromeos::disks::DiskMountManager::UnmountPathCallback());
544 } 542 }
545 } 543 }
546 } 544 }
547 545
548 void VolumeManager::OnPrivetVolumesAvailable( 546 void VolumeManager::OnPrivetVolumesAvailable(
549 const local_discovery::PrivetVolumeLister::VolumeList& volumes) { 547 const local_discovery::PrivetVolumeLister::VolumeList& volumes) {
550 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i = 548 for (local_discovery::PrivetVolumeLister::VolumeList::const_iterator i =
551 volumes.begin(); i != volumes.end(); i++) { 549 volumes.begin(); i != volumes.end(); i++) {
552 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i); 550 VolumeInfo volume_info = CreatePrivetVolumeInfo(*i);
553 551 DoMountEvent(chromeos::MOUNT_ERROR_NONE, volume_info, false);
554 FOR_EACH_OBSERVER(
555 VolumeManagerObserver, observers_,
556 OnVolumeMounted(chromeos::MOUNT_ERROR_NONE, volume_info, false));
557 } 552 }
558 } 553 }
559 554
555 void VolumeManager::DoMountEvent(chromeos::MountError error_code,
556 const VolumeInfo& volume_info,
557 bool is_remounting) {
558 // TODO(kinaba): filter zip.
559
560 if (error_code == chromeos::MOUNT_ERROR_NONE || volume_info.mount_condition)
561 mounted_volumes_[volume_info.volume_id] = volume_info;
562
563 FOR_EACH_OBSERVER(VolumeManagerObserver,
564 observers_,
565 OnVolumeMounted(error_code, volume_info, is_remounting));
566 }
567
568 void VolumeManager::DoUnmountEvent(chromeos::MountError error_code,
569 const VolumeInfo& volume_info) {
570 if (mounted_volumes_.find(volume_info.volume_id) == mounted_volumes_.end())
571 return;
572 if (error_code == chromeos::MOUNT_ERROR_NONE)
573 mounted_volumes_.erase(volume_info.volume_id);
574
575 FOR_EACH_OBSERVER(VolumeManagerObserver,
576 observers_,
577 OnVolumeUnmounted(error_code, volume_info));
578 }
579
560 } // namespace file_manager 580 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/volume_manager.h ('k') | chrome/browser/chromeos/file_manager/volume_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698