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_manager/event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" | 23 #include "chrome/browser/chromeos/file_manager/mounted_disk_monitor.h" |
24 #include "chrome/browser/chromeos/file_manager/open_util.h" | 24 #include "chrome/browser/chromeos/file_manager/open_util.h" |
25 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 25 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
26 #include "chrome/browser/chromeos/login/screen_locker.h" | 26 #include "chrome/browser/chromeos/login/screen_locker.h" |
27 #include "chrome/browser/drive/drive_service_interface.h" | 27 #include "chrome/browser/drive/drive_service_interface.h" |
28 #include "chrome/browser/extensions/event_names.h" | 28 #include "chrome/browser/extensions/event_names.h" |
29 #include "chrome/browser/extensions/event_router.h" | 29 #include "chrome/browser/extensions/event_router.h" |
30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/extensions/extension_system.h" | 31 #include "chrome/browser/extensions/extension_system.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/common/extensions/api/file_browser_private.h" | |
33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
34 #include "chromeos/login/login_state.h" | 35 #include "chromeos/login/login_state.h" |
35 #include "chromeos/network/network_handler.h" | 36 #include "chromeos/network/network_handler.h" |
36 #include "chromeos/network/network_state_handler.h" | 37 #include "chromeos/network/network_state_handler.h" |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
39 #include "webkit/common/fileapi/file_system_types.h" | 40 #include "webkit/common/fileapi/file_system_types.h" |
40 #include "webkit/common/fileapi/file_system_util.h" | 41 #include "webkit/common/fileapi/file_system_util.h" |
41 | 42 |
42 using chromeos::disks::DiskMountManager; | 43 using chromeos::disks::DiskMountManager; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 | 203 |
203 for (size_t i = 0; i < arraysize(kGooglePlusPhotosIds); ++i) { | 204 for (size_t i = 0; i < arraysize(kGooglePlusPhotosIds); ++i) { |
204 if (service->GetExtensionById(kGooglePlusPhotosIds[i], | 205 if (service->GetExtensionById(kGooglePlusPhotosIds[i], |
205 false /* include_disable */) != NULL) | 206 false /* include_disable */) != NULL) |
206 return true; | 207 return true; |
207 } | 208 } |
208 | 209 |
209 return false; | 210 return false; |
210 } | 211 } |
211 | 212 |
213 // Sends an event named |event_name| with arguemtns |event_args| to extensions. | |
kinaba
2013/09/09 04:07:49
typo: arguments
hidehiko
2013/09/09 04:57:01
Done.
| |
214 void BroadcastEvent(Profile* profile, | |
215 const std::string& event_name, | |
216 scoped_ptr<base::ListValue> event_args) { | |
217 extensions::ExtensionSystem::Get(profile)->event_router()-> | |
218 BroadcastEvent(make_scoped_ptr( | |
219 new extensions::Event(event_name, event_args.Pass()))); | |
220 } | |
221 | |
212 } // namespace | 222 } // namespace |
213 | 223 |
214 // Pass dummy value to JobInfo's constructor for make it default constructible. | 224 // Pass dummy value to JobInfo's constructor for make it default constructible. |
215 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() | 225 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() |
216 : job_info(drive::TYPE_DOWNLOAD_FILE) { | 226 : job_info(drive::TYPE_DOWNLOAD_FILE) { |
217 } | 227 } |
218 | 228 |
219 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( | 229 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( |
220 const drive::JobInfo& info, const std::string& status) | 230 const drive::JobInfo& info, const std::string& status) |
221 : job_info(info), status(status) { | 231 : job_info(info), status(status) { |
222 } | 232 } |
223 | 233 |
224 EventRouter::EventRouter( | 234 EventRouter::EventRouter(Profile* profile) |
225 Profile* profile) | |
226 : notifications_(new DesktopNotifications(profile)), | 235 : notifications_(new DesktopNotifications(profile)), |
227 pref_change_registrar_(new PrefChangeRegistrar), | 236 pref_change_registrar_(new PrefChangeRegistrar), |
228 profile_(profile), | 237 profile_(profile), |
229 weak_factory_(this) { | 238 weak_factory_(this) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
231 } | 240 } |
232 | 241 |
233 EventRouter::~EventRouter() { | 242 EventRouter::~EventRouter() { |
234 } | 243 } |
235 | 244 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 if (iter == file_watchers_.end()) | 390 if (iter == file_watchers_.end()) |
382 return; | 391 return; |
383 // Remove the watcher if |watch_path| is no longer watched by any extensions. | 392 // Remove the watcher if |watch_path| is no longer watched by any extensions. |
384 iter->second->RemoveExtension(extension_id); | 393 iter->second->RemoveExtension(extension_id); |
385 if (iter->second->GetExtensionIds().empty()) { | 394 if (iter->second->GetExtensionIds().empty()) { |
386 delete iter->second; | 395 delete iter->second; |
387 file_watchers_.erase(iter); | 396 file_watchers_.erase(iter); |
388 } | 397 } |
389 } | 398 } |
390 | 399 |
400 void EventRouter::OnCopyCompleted( | |
401 int copy_id, const GURL& url, base::PlatformFileError error) { | |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
403 | |
404 using extensions::api::file_browser_private::CopyProgressStatus; | |
405 namespace OnCopyProgress = | |
406 extensions::api::file_browser_private::OnCopyProgress; | |
407 | |
408 CopyProgressStatus status; | |
409 if (error == base::PLATFORM_FILE_OK) { | |
410 // Send success event. | |
411 status.type = CopyProgressStatus::TYPE_SUCCESS; | |
412 status.url.reset(new std::string(url.spec())); | |
413 } else { | |
414 // Send error event. | |
415 status.type = CopyProgressStatus::TYPE_ERROR; | |
416 status.error.reset( | |
417 new int(fileapi::PlatformFileErrorToWebFileError(error))); | |
418 } | |
419 | |
420 BroadcastEvent( | |
421 profile_, | |
422 extensions::event_names::kOnFileBrowserCopyProgress, | |
423 OnCopyProgress::Create(copy_id, status)); | |
424 } | |
425 | |
391 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event, | 426 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event, |
392 const DiskMountManager::Disk* disk) { | 427 const DiskMountManager::Disk* disk) { |
393 // Disk event is dispatched by VolumeManager now. Do nothing. | 428 // Disk event is dispatched by VolumeManager now. Do nothing. |
394 } | 429 } |
395 | 430 |
396 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event, | 431 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event, |
397 const std::string& device_path) { | 432 const std::string& device_path) { |
398 // Device event is dispatched by VolumeManager now. Do nothing. | 433 // Device event is dispatched by VolumeManager now. Do nothing. |
399 } | 434 } |
400 | 435 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 const std::string& device_path) { | 489 const std::string& device_path) { |
455 // Format event is dispatched by VolumeManager now. Do nothing. | 490 // Format event is dispatched by VolumeManager now. Do nothing. |
456 } | 491 } |
457 | 492 |
458 void EventRouter::NetworkManagerChanged() { | 493 void EventRouter::NetworkManagerChanged() { |
459 if (!profile_ || | 494 if (!profile_ || |
460 !extensions::ExtensionSystem::Get(profile_)->event_router()) { | 495 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
461 NOTREACHED(); | 496 NOTREACHED(); |
462 return; | 497 return; |
463 } | 498 } |
464 scoped_ptr<extensions::Event> event(new extensions::Event( | 499 |
500 BroadcastEvent( | |
501 profile_, | |
465 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, | 502 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, |
466 scoped_ptr<ListValue>(new ListValue()))); | 503 make_scoped_ptr(new ListValue)); |
467 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
468 BroadcastEvent(event.Pass()); | |
469 } | 504 } |
470 | 505 |
471 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { | 506 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { |
472 NetworkManagerChanged(); | 507 NetworkManagerChanged(); |
473 } | 508 } |
474 | 509 |
475 void EventRouter::OnExternalStorageDisabledChanged() { | 510 void EventRouter::OnExternalStorageDisabledChanged() { |
476 // If the policy just got disabled we have to unmount every device currently | 511 // If the policy just got disabled we have to unmount every device currently |
477 // mounted. The opposite is fine - we can let the user re-plug her device to | 512 // mounted. The opposite is fine - we can let the user re-plug her device to |
478 // make it available. | 513 // make it available. |
(...skipping 11 matching lines...) Expand all Loading... | |
490 } | 525 } |
491 } | 526 } |
492 | 527 |
493 void EventRouter::OnFileManagerPrefsChanged() { | 528 void EventRouter::OnFileManagerPrefsChanged() { |
494 if (!profile_ || | 529 if (!profile_ || |
495 !extensions::ExtensionSystem::Get(profile_)->event_router()) { | 530 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
496 NOTREACHED(); | 531 NOTREACHED(); |
497 return; | 532 return; |
498 } | 533 } |
499 | 534 |
500 scoped_ptr<extensions::Event> event(new extensions::Event( | 535 BroadcastEvent( |
536 profile_, | |
501 extensions::event_names::kOnFileBrowserPreferencesChanged, | 537 extensions::event_names::kOnFileBrowserPreferencesChanged, |
502 scoped_ptr<ListValue>(new ListValue()))); | 538 make_scoped_ptr(new ListValue)); |
503 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
504 BroadcastEvent(event.Pass()); | |
505 } | 539 } |
506 | 540 |
507 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { | 541 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { |
508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
509 OnJobUpdated(job_info); | 543 OnJobUpdated(job_info); |
510 } | 544 } |
511 | 545 |
512 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) { | 546 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) { |
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
514 if (!drive::IsActiveFileTransferJobInfo(job_info)) | 548 if (!drive::IsActiveFileTransferJobInfo(job_info)) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, | 650 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, |
617 chromeos::disks::MOUNT_CONDITION_NONE); | 651 chromeos::disks::MOUNT_CONDITION_NONE); |
618 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, | 652 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, |
619 mount_info); | 653 mount_info); |
620 } | 654 } |
621 | 655 |
622 void EventRouter::OnRefreshTokenInvalid() { | 656 void EventRouter::OnRefreshTokenInvalid() { |
623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
624 | 658 |
625 // Raise a DriveConnectionStatusChanged event to notify the status offline. | 659 // Raise a DriveConnectionStatusChanged event to notify the status offline. |
626 scoped_ptr<extensions::Event> event(new extensions::Event( | 660 BroadcastEvent( |
661 profile_, | |
627 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, | 662 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, |
628 scoped_ptr<ListValue>(new ListValue()))); | 663 make_scoped_ptr(new ListValue)); |
629 extensions::ExtensionSystem::Get(profile_)->event_router()-> | |
630 BroadcastEvent(event.Pass()); | |
631 } | 664 } |
632 | 665 |
633 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, | 666 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, |
634 bool got_error) { | 667 bool got_error) { |
635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
636 | 669 |
637 WatcherMap::const_iterator iter = file_watchers_.find(local_path); | 670 WatcherMap::const_iterator iter = file_watchers_.find(local_path); |
638 if (iter == file_watchers_.end()) { | 671 if (iter == file_watchers_.end()) { |
639 return; | 672 return; |
640 } | 673 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 &relative_mount_path)) { | 745 &relative_mount_path)) { |
713 mount_info_value->SetString("mountPath", | 746 mount_info_value->SetString("mountPath", |
714 "/" + relative_mount_path.value()); | 747 "/" + relative_mount_path.value()); |
715 } else { | 748 } else { |
716 mount_info_value->SetString( | 749 mount_info_value->SetString( |
717 "status", | 750 "status", |
718 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); | 751 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); |
719 } | 752 } |
720 } | 753 } |
721 | 754 |
722 scoped_ptr<extensions::Event> extension_event(new extensions::Event( | 755 BroadcastEvent(profile_, |
723 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass())); | 756 extensions::event_names::kOnFileBrowserMountCompleted, |
724 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 757 args.Pass()); |
725 BroadcastEvent(extension_event.Pass()); | |
726 } | 758 } |
727 | 759 |
728 void EventRouter::ShowRemovableDeviceInFileManager( | 760 void EventRouter::ShowRemovableDeviceInFileManager( |
729 const DiskMountManager::Disk& disk, | 761 const DiskMountManager::Disk& disk, |
730 const base::FilePath& mount_path) { | 762 const base::FilePath& mount_path) { |
731 // Do not attempt to open File Manager while the login is in progress or | 763 // Do not attempt to open File Manager while the login is in progress or |
732 // the screen is locked. | 764 // the screen is locked. |
733 if (chromeos::LoginDisplayHostImpl::default_host() || | 765 if (chromeos::LoginDisplayHostImpl::default_host() || |
734 chromeos::ScreenLocker::default_screen_locker()) | 766 chromeos::ScreenLocker::default_screen_locker()) |
735 return; | 767 return; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
823 base::TimeDelta::FromSeconds(4)); | 855 base::TimeDelta::FromSeconds(4)); |
824 } else { | 856 } else { |
825 notifications_->HideNotification(DesktopNotifications::FORMAT_START, | 857 notifications_->HideNotification(DesktopNotifications::FORMAT_START, |
826 device_path); | 858 device_path); |
827 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, | 859 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, |
828 device_path); | 860 device_path); |
829 } | 861 } |
830 } | 862 } |
831 | 863 |
832 } // namespace file_manager | 864 } // namespace file_manager |
OLD | NEW |