| 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/prefs/public/pref_change_registrar.h" | 10 #include "base/prefs/public/pref_change_registrar.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 14 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 14 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| 16 #include "chrome/browser/chromeos/drive/drive_system_service.h" | 16 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
| 17 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" | 17 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" |
| 18 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 18 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
| 20 #include "chrome/browser/chromeos/login/screen_locker.h" | 20 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/browser/extensions/event_names.h" | 22 #include "chrome/browser/extensions/event_names.h" |
| 23 #include "chrome/browser/extensions/event_router.h" | 23 #include "chrome/browser/extensions/event_router.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/extensions/extension_system.h" |
| 25 #include "chrome/browser/google_apis/drive_service_interface.h" | 26 #include "chrome/browser/google_apis/drive_service_interface.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/profiles/profile_dependency_manager.h" | 29 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "content/public/browser/notification_source.h" | 32 #include "content/public/browser/notification_source.h" |
| 32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "webkit/fileapi/file_system_types.h" | 35 #include "webkit/fileapi/file_system_types.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 if (cache) { | 367 if (cache) { |
| 367 cache->SetMountedStateOnUIThread( | 368 cache->SetMountedStateOnUIThread( |
| 368 source_path, false, drive::ChangeCacheStateCallback()); | 369 source_path, false, drive::ChangeCacheStateCallback()); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 | 374 |
| 374 void FileBrowserEventRouter::OnNetworkManagerChanged( | 375 void FileBrowserEventRouter::OnNetworkManagerChanged( |
| 375 chromeos::NetworkLibrary* network_library) { | 376 chromeos::NetworkLibrary* network_library) { |
| 376 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 377 if (!profile_ || |
| 378 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
| 377 NOTREACHED(); | 379 NOTREACHED(); |
| 378 return; | 380 return; |
| 379 } | 381 } |
| 380 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 382 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 381 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, | 383 DispatchEventToRenderers( |
| 382 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); | 384 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, |
| 385 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); |
| 383 } | 386 } |
| 384 | 387 |
| 385 void FileBrowserEventRouter::Observe( | 388 void FileBrowserEventRouter::Observe( |
| 386 int type, | 389 int type, |
| 387 const content::NotificationSource& source, | 390 const content::NotificationSource& source, |
| 388 const content::NotificationDetails& details) { | 391 const content::NotificationDetails& details) { |
| 389 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 392 if (!profile_ || |
| 393 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
| 390 NOTREACHED(); | 394 NOTREACHED(); |
| 391 return; | 395 return; |
| 392 } | 396 } |
| 393 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 397 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 394 std::string* pref_name = content::Details<std::string>(details).ptr(); | 398 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 395 // If the policy just got disabled we have to unmount every device currently | 399 // If the policy just got disabled we have to unmount every device currently |
| 396 // mounted. The opposite is fine - we can let the user re-plug her device to | 400 // mounted. The opposite is fine - we can let the user re-plug her device to |
| 397 // make it available. | 401 // make it available. |
| 398 if (*pref_name == prefs::kExternalStorageDisabled && | 402 if (*pref_name == prefs::kExternalStorageDisabled && |
| 399 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { | 403 profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { |
| 400 DiskMountManager* manager = DiskMountManager::GetInstance(); | 404 DiskMountManager* manager = DiskMountManager::GetInstance(); |
| 401 DiskMountManager::MountPointMap mounts(manager->mount_points()); | 405 DiskMountManager::MountPointMap mounts(manager->mount_points()); |
| 402 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); | 406 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); |
| 403 it != mounts.end(); ++it) { | 407 it != mounts.end(); ++it) { |
| 404 LOG(INFO) << "Unmounting " << it->second.mount_path | 408 LOG(INFO) << "Unmounting " << it->second.mount_path |
| 405 << " because of policy."; | 409 << " because of policy."; |
| 406 manager->UnmountPath(it->second.mount_path, | 410 manager->UnmountPath(it->second.mount_path, |
| 407 chromeos::UNMOUNT_OPTIONS_NONE); | 411 chromeos::UNMOUNT_OPTIONS_NONE); |
| 408 } | 412 } |
| 409 return; | 413 return; |
| 410 } else if (*pref_name == prefs::kDisableDriveOverCellular || | 414 } else if (*pref_name == prefs::kDisableDriveOverCellular || |
| 411 *pref_name == prefs::kDisableDriveHostedFiles || | 415 *pref_name == prefs::kDisableDriveHostedFiles || |
| 412 *pref_name == prefs::kDisableDrive || | 416 *pref_name == prefs::kDisableDrive || |
| 413 *pref_name == prefs::kUse24HourClock) { | 417 *pref_name == prefs::kUse24HourClock) { |
| 414 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 418 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 415 extensions::event_names::kOnFileBrowserPreferencesChanged, | 419 DispatchEventToRenderers( |
| 416 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); | 420 extensions::event_names::kOnFileBrowserPreferencesChanged, |
| 421 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); |
| 417 } | 422 } |
| 418 } | 423 } |
| 419 } | 424 } |
| 420 | 425 |
| 421 void FileBrowserEventRouter::OnProgressUpdate( | 426 void FileBrowserEventRouter::OnProgressUpdate( |
| 422 const google_apis::OperationProgressStatusList& list) { | 427 const google_apis::OperationProgressStatusList& list) { |
| 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 424 | 429 |
| 425 scoped_ptr<ListValue> event_list( | 430 scoped_ptr<ListValue> event_list( |
| 426 file_manager_util::ProgressStatusVectorToListValue( | 431 file_manager_util::ProgressStatusVectorToListValue( |
| 427 profile_, | 432 profile_, |
| 428 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | 433 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
| 429 list)); | 434 list)); |
| 430 | 435 |
| 431 scoped_ptr<ListValue> args(new ListValue()); | 436 scoped_ptr<ListValue> args(new ListValue()); |
| 432 args->Append(event_list.release()); | 437 args->Append(event_list.release()); |
| 433 | 438 |
| 434 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 439 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 435 std::string(kFileBrowserDomain), | 440 DispatchEventToExtension( |
| 436 extensions::event_names::kOnFileTransfersUpdated, args.Pass(), NULL, | 441 std::string(kFileBrowserDomain), |
| 437 GURL()); | 442 extensions::event_names::kOnFileTransfersUpdated, args.Pass(), NULL, |
| 443 GURL()); |
| 438 } | 444 } |
| 439 | 445 |
| 440 void FileBrowserEventRouter::OnDirectoryChanged( | 446 void FileBrowserEventRouter::OnDirectoryChanged( |
| 441 const FilePath& directory_path) { | 447 const FilePath& directory_path) { |
| 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 443 HandleFileWatchNotification(directory_path, false); | 449 HandleFileWatchNotification(directory_path, false); |
| 444 } | 450 } |
| 445 | 451 |
| 446 void FileBrowserEventRouter::OnDocumentFeedFetched( | 452 void FileBrowserEventRouter::OnDocumentFeedFetched( |
| 447 int num_accumulated_entries) { | 453 int num_accumulated_entries) { |
| 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 449 | 455 |
| 450 scoped_ptr<ListValue> args(new ListValue()); | 456 scoped_ptr<ListValue> args(new ListValue()); |
| 451 args->Append(base::Value::CreateIntegerValue(num_accumulated_entries)); | 457 args->Append(base::Value::CreateIntegerValue(num_accumulated_entries)); |
| 452 | 458 |
| 453 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 459 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 454 std::string(kFileBrowserDomain), | 460 DispatchEventToExtension( |
| 455 extensions::event_names::kOnDocumentFeedFetched, args.Pass(), NULL, | 461 std::string(kFileBrowserDomain), |
| 456 GURL()); | 462 extensions::event_names::kOnDocumentFeedFetched, args.Pass(), NULL, |
| 463 GURL()); |
| 457 } | 464 } |
| 458 | 465 |
| 459 void FileBrowserEventRouter::OnFileSystemMounted() { | 466 void FileBrowserEventRouter::OnFileSystemMounted() { |
| 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 461 | 468 |
| 462 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. | 469 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. |
| 463 } | 470 } |
| 464 | 471 |
| 465 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { | 472 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { |
| 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, | 527 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, |
| 521 fileapi::kFileSystemTypeExternal); | 528 fileapi::kFileSystemTypeExternal); |
| 522 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); | 529 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); |
| 523 scoped_ptr<ListValue> args(new ListValue()); | 530 scoped_ptr<ListValue> args(new ListValue()); |
| 524 DictionaryValue* watch_info = new DictionaryValue(); | 531 DictionaryValue* watch_info = new DictionaryValue(); |
| 525 args->Append(watch_info); | 532 args->Append(watch_info); |
| 526 watch_info->SetString("fileUrl", target_file_url.spec()); | 533 watch_info->SetString("fileUrl", target_file_url.spec()); |
| 527 watch_info->SetString("eventType", | 534 watch_info->SetString("eventType", |
| 528 got_error ? kPathWatchError : kPathChanged); | 535 got_error ? kPathWatchError : kPathChanged); |
| 529 | 536 |
| 530 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 537 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 531 iter->first, extensions::event_names::kOnFileChanged, args.Pass(), NULL, | 538 DispatchEventToExtension(iter->first, |
| 532 GURL()); | 539 extensions::event_names::kOnFileChanged, args.Pass(), NULL, GURL()); |
| 533 } | 540 } |
| 534 } | 541 } |
| 535 | 542 |
| 536 // TODO(tbarzic): This is not used anymore. Remove it. | 543 // TODO(tbarzic): This is not used anymore. Remove it. |
| 537 void FileBrowserEventRouter::DispatchDiskEvent( | 544 void FileBrowserEventRouter::DispatchDiskEvent( |
| 538 const DiskMountManager::Disk* disk, bool added) { | 545 const DiskMountManager::Disk* disk, bool added) { |
| 539 if (!profile_) { | 546 if (!profile_) { |
| 540 NOTREACHED(); | 547 NOTREACHED(); |
| 541 return; | 548 return; |
| 542 } | 549 } |
| 543 | 550 |
| 544 scoped_ptr<ListValue> args(new ListValue()); | 551 scoped_ptr<ListValue> args(new ListValue()); |
| 545 DictionaryValue* mount_info = new DictionaryValue(); | 552 DictionaryValue* mount_info = new DictionaryValue(); |
| 546 args->Append(mount_info); | 553 args->Append(mount_info); |
| 547 mount_info->SetString("eventType", | 554 mount_info->SetString("eventType", |
| 548 added ? kDiskAddedEventType : kDiskRemovedEventType); | 555 added ? kDiskAddedEventType : kDiskRemovedEventType); |
| 549 DictionaryValue* disk_info = DiskToDictionaryValue(disk); | 556 DictionaryValue* disk_info = DiskToDictionaryValue(disk); |
| 550 mount_info->Set("volumeInfo", disk_info); | 557 mount_info->Set("volumeInfo", disk_info); |
| 551 | 558 |
| 552 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 559 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 553 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL, | 560 DispatchEventToRenderers( |
| 554 GURL()); | 561 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL, |
| 562 GURL()); |
| 555 } | 563 } |
| 556 | 564 |
| 557 void FileBrowserEventRouter::DispatchMountCompletedEvent( | 565 void FileBrowserEventRouter::DispatchMountCompletedEvent( |
| 558 DiskMountManager::MountEvent event, | 566 DiskMountManager::MountEvent event, |
| 559 chromeos::MountError error_code, | 567 chromeos::MountError error_code, |
| 560 const DiskMountManager::MountPointInfo& mount_info) { | 568 const DiskMountManager::MountPointInfo& mount_info) { |
| 561 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can | 569 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can |
| 562 // happen at shutdown. | 570 // happen at shutdown. |
| 563 if (!profile_) | 571 if (!profile_) |
| 564 return; | 572 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 mount_info_value->SetString("mountPath", | 605 mount_info_value->SetString("mountPath", |
| 598 "/" + relative_mount_path.value()); | 606 "/" + relative_mount_path.value()); |
| 599 relative_mount_path_set = true; | 607 relative_mount_path_set = true; |
| 600 } else { | 608 } else { |
| 601 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; | 609 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; |
| 602 mount_info_value->SetString("status", | 610 mount_info_value->SetString("status", |
| 603 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); | 611 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); |
| 604 } | 612 } |
| 605 } | 613 } |
| 606 | 614 |
| 607 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 615 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 608 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass(), NULL, | 616 DispatchEventToRenderers( |
| 609 GURL()); | 617 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass(), |
| 618 NULL, GURL()); |
| 610 | 619 |
| 611 // Do not attempt to open File Manager while the login is in progress or | 620 // Do not attempt to open File Manager while the login is in progress or |
| 612 // the screen is locked. | 621 // the screen is locked. |
| 613 if (chromeos::BaseLoginDisplayHost::default_host() || | 622 if (chromeos::BaseLoginDisplayHost::default_host() || |
| 614 chromeos::ScreenLocker::default_screen_locker()) | 623 chromeos::ScreenLocker::default_screen_locker()) |
| 615 return; | 624 return; |
| 616 | 625 |
| 617 if (relative_mount_path_set && | 626 if (relative_mount_path_set && |
| 618 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 627 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
| 619 !mount_info.mount_condition && | 628 !mount_info.mount_condition && |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 return scoped_refptr<RefcountedProfileKeyedService>( | 889 return scoped_refptr<RefcountedProfileKeyedService>( |
| 881 new FileBrowserEventRouter(profile)); | 890 new FileBrowserEventRouter(profile)); |
| 882 } | 891 } |
| 883 | 892 |
| 884 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { | 893 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { |
| 885 // Explicitly and always allow this router in guest login mode. see | 894 // Explicitly and always allow this router in guest login mode. see |
| 886 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 895 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
| 887 // for the details. | 896 // for the details. |
| 888 return true; | 897 return true; |
| 889 } | 898 } |
| OLD | NEW |