| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 ListValue args; | 361 ListValue args; |
| 362 DictionaryValue* mount_info_value = new DictionaryValue(); | 362 DictionaryValue* mount_info_value = new DictionaryValue(); |
| 363 args.Append(mount_info_value); | 363 args.Append(mount_info_value); |
| 364 mount_info_value->SetString("eventType", | 364 mount_info_value->SetString("eventType", |
| 365 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); | 365 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); |
| 366 mount_info_value->SetString("status", MountErrorToString(error_code)); | 366 mount_info_value->SetString("status", MountErrorToString(error_code)); |
| 367 mount_info_value->SetString( | 367 mount_info_value->SetString( |
| 368 "mountType", | 368 "mountType", |
| 369 DiskMountManager::MountTypeToString(mount_info.mount_type)); | 369 DiskMountManager::MountTypeToString(mount_info.mount_type)); |
| 370 | 370 |
| 371 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE || | 371 // Add sourcePath to the event. |
| 372 mount_info.mount_type == chromeos::MOUNT_TYPE_GDATA) { | 372 mount_info_value->SetString("sourcePath", mount_info.source_path); |
| 373 GURL source_url; | |
| 374 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, | |
| 375 FilePath(mount_info.source_path), | |
| 376 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | |
| 377 &source_url)) { | |
| 378 mount_info_value->SetString("sourceUrl", source_url.spec()); | |
| 379 } else { | |
| 380 // If mounting of gdata moutn point failed, we may not be able to convert | |
| 381 // source path to source url, so let just send empty string. | |
| 382 DCHECK(mount_info.mount_type == chromeos::MOUNT_TYPE_GDATA && | |
| 383 error_code != chromeos::MOUNT_ERROR_NONE); | |
| 384 mount_info_value->SetString("sourceUrl", ""); | |
| 385 } | |
| 386 } else { | |
| 387 mount_info_value->SetString("sourceUrl", mount_info.source_path); | |
| 388 } | |
| 389 | 373 |
| 390 FilePath relative_mount_path; | 374 FilePath relative_mount_path; |
| 391 bool relative_mount_path_set = false; | 375 bool relative_mount_path_set = false; |
| 392 | 376 |
| 393 // If there were no error or some special conditions occured, add mountPath | 377 // If there were no error or some special conditions occured, add mountPath |
| 394 // to the event. | 378 // to the event. |
| 395 if (error_code == chromeos::MOUNT_ERROR_NONE || | 379 if (error_code == chromeos::MOUNT_ERROR_NONE || |
| 396 mount_info.mount_condition) { | 380 mount_info.mount_condition) { |
| 397 // Convert mount point path to relative path with the external file system | 381 // Convert mount point path to relative path with the external file system |
| 398 // exposed within File API. | 382 // exposed within File API. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 423 const DiskMountManager::Disk* disk) { | 407 const DiskMountManager::Disk* disk) { |
| 424 VLOG(1) << "Disk added: " << disk->device_path(); | 408 VLOG(1) << "Disk added: " << disk->device_path(); |
| 425 if (disk->device_path().empty()) { | 409 if (disk->device_path().empty()) { |
| 426 VLOG(1) << "Empty system path for " << disk->device_path(); | 410 VLOG(1) << "Empty system path for " << disk->device_path(); |
| 427 return; | 411 return; |
| 428 } | 412 } |
| 429 | 413 |
| 430 // If disk is not mounted yet and it has media, give it a try. | 414 // If disk is not mounted yet and it has media, give it a try. |
| 431 if (disk->mount_path().empty() && disk->has_media()) { | 415 if (disk->mount_path().empty() && disk->has_media()) { |
| 432 // Initiate disk mount operation. MountPath auto-detects the filesystem | 416 // Initiate disk mount operation. MountPath auto-detects the filesystem |
| 433 // format if the second argument is empty. | 417 // format if the second argument is empty. The third argument (mount label) |
| 418 // is not used in a disk mount operation. |
| 434 DiskMountManager::GetInstance()->MountPath( | 419 DiskMountManager::GetInstance()->MountPath( |
| 435 disk->device_path(), std::string(), chromeos::MOUNT_TYPE_DEVICE); | 420 disk->device_path(), std::string(), std::string(), |
| 421 chromeos::MOUNT_TYPE_DEVICE); |
| 436 } else { | 422 } else { |
| 437 // Either the disk was mounted or it has no media. In both cases we don't | 423 // Either the disk was mounted or it has no media. In both cases we don't |
| 438 // want the Scanning notification to persist. | 424 // want the Scanning notification to persist. |
| 439 notifications_->HideNotification(FileBrowserNotifications::DEVICE, | 425 notifications_->HideNotification(FileBrowserNotifications::DEVICE, |
| 440 disk->system_path_prefix()); | 426 disk->system_path_prefix()); |
| 441 } | 427 } |
| 442 DispatchDiskEvent(disk, true); | 428 DispatchDiskEvent(disk, true); |
| 443 } | 429 } |
| 444 | 430 |
| 445 void FileBrowserEventRouter::OnDiskRemoved( | 431 void FileBrowserEventRouter::OnDiskRemoved( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 const std::string& device_path, bool success) { | 478 const std::string& device_path, bool success) { |
| 493 if (success) { | 479 if (success) { |
| 494 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, | 480 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, |
| 495 device_path); | 481 device_path); |
| 496 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_SUCCESS, | 482 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_SUCCESS, |
| 497 device_path); | 483 device_path); |
| 498 // Hide it after a couple of seconds. | 484 // Hide it after a couple of seconds. |
| 499 notifications_->HideNotificationDelayed( | 485 notifications_->HideNotificationDelayed( |
| 500 FileBrowserNotifications::FORMAT_SUCCESS, device_path, 4000); | 486 FileBrowserNotifications::FORMAT_SUCCESS, device_path, 4000); |
| 501 // MountPath auto-detects filesystem format if second argument is empty. | 487 // MountPath auto-detects filesystem format if second argument is empty. |
| 488 // The third argument (mount label) is not used in a disk mount operation. |
| 502 DiskMountManager::GetInstance()->MountPath(device_path, std::string(), | 489 DiskMountManager::GetInstance()->MountPath(device_path, std::string(), |
| 490 std::string(), |
| 503 chromeos::MOUNT_TYPE_DEVICE); | 491 chromeos::MOUNT_TYPE_DEVICE); |
| 504 } else { | 492 } else { |
| 505 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, | 493 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, |
| 506 device_path); | 494 device_path); |
| 507 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_FAIL, | 495 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_FAIL, |
| 508 device_path); | 496 device_path); |
| 509 } | 497 } |
| 510 } | 498 } |
| 511 | 499 |
| 512 // FileBrowserEventRouter::WatcherDelegate methods. | 500 // FileBrowserEventRouter::WatcherDelegate methods. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return scoped_refptr<RefcountedProfileKeyedService>( | 621 return scoped_refptr<RefcountedProfileKeyedService>( |
| 634 new FileBrowserEventRouter(profile)); | 622 new FileBrowserEventRouter(profile)); |
| 635 } | 623 } |
| 636 | 624 |
| 637 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 625 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
| 638 // Explicitly and always allow this router in guest login mode. see | 626 // Explicitly and always allow this router in guest login mode. see |
| 639 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 627 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
| 640 // for the details. | 628 // for the details. |
| 641 return true; | 629 return true; |
| 642 } | 630 } |
| OLD | NEW |