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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 23604042: Implement startCopy and cancelCopy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 3 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 (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 13 matching lines...) Expand all
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/file_manager/volume_manager.h" 25 #include "chrome/browser/chromeos/file_manager/volume_manager.h"
26 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 26 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
27 #include "chrome/browser/chromeos/login/screen_locker.h" 27 #include "chrome/browser/chromeos/login/screen_locker.h"
28 #include "chrome/browser/drive/drive_service_interface.h" 28 #include "chrome/browser/drive/drive_service_interface.h"
29 #include "chrome/browser/extensions/event_names.h" 29 #include "chrome/browser/extensions/event_names.h"
30 #include "chrome/browser/extensions/event_router.h" 30 #include "chrome/browser/extensions/event_router.h"
31 #include "chrome/browser/extensions/extension_service.h" 31 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/extensions/extension_system.h" 32 #include "chrome/browser/extensions/extension_system.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/common/extensions/api/file_browser_private.h"
34 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
35 #include "chromeos/login/login_state.h" 36 #include "chromeos/login/login_state.h"
36 #include "chromeos/network/network_handler.h" 37 #include "chromeos/network/network_handler.h"
37 #include "chromeos/network/network_state_handler.h" 38 #include "chromeos/network/network_state_handler.h"
38 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
39 #include "content/public/browser/notification_source.h" 40 #include "content/public/browser/notification_source.h"
40 #include "webkit/common/fileapi/file_system_types.h" 41 #include "webkit/common/fileapi/file_system_types.h"
41 #include "webkit/common/fileapi/file_system_util.h" 42 #include "webkit/common/fileapi/file_system_util.h"
42 43
43 using chromeos::disks::DiskMountManager; 44 using chromeos::disks::DiskMountManager;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return util::VolumeTypeToStringEnum(VOLUME_TYPE_REMOVABLE_DISK_PARTITION); 221 return util::VolumeTypeToStringEnum(VOLUME_TYPE_REMOVABLE_DISK_PARTITION);
221 case chromeos::MOUNT_TYPE_ARCHIVE: 222 case chromeos::MOUNT_TYPE_ARCHIVE:
222 return util::VolumeTypeToStringEnum(VOLUME_TYPE_MOUNTED_ARCHIVE_FILE); 223 return util::VolumeTypeToStringEnum(VOLUME_TYPE_MOUNTED_ARCHIVE_FILE);
223 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: 224 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE:
224 return util::VolumeTypeToStringEnum(VOLUME_TYPE_GOOGLE_DRIVE); 225 return util::VolumeTypeToStringEnum(VOLUME_TYPE_GOOGLE_DRIVE);
225 } 226 }
226 NOTREACHED(); 227 NOTREACHED();
227 return ""; 228 return "";
228 } 229 }
229 230
231 // Sends an event named |event_name| with arguments |event_args| to extensions.
232 void BroadcastEvent(Profile* profile,
233 const std::string& event_name,
234 scoped_ptr<base::ListValue> event_args) {
235 extensions::ExtensionSystem::Get(profile)->event_router()->
236 BroadcastEvent(make_scoped_ptr(
237 new extensions::Event(event_name, event_args.Pass())));
238 }
239
230 } // namespace 240 } // namespace
231 241
232 // Pass dummy value to JobInfo's constructor for make it default constructible. 242 // Pass dummy value to JobInfo's constructor for make it default constructible.
233 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() 243 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus()
234 : job_info(drive::TYPE_DOWNLOAD_FILE) { 244 : job_info(drive::TYPE_DOWNLOAD_FILE) {
235 } 245 }
236 246
237 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( 247 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus(
238 const drive::JobInfo& info, const std::string& status) 248 const drive::JobInfo& info, const std::string& status)
239 : job_info(info), status(status) { 249 : job_info(info), status(status) {
240 } 250 }
241 251
242 EventRouter::EventRouter( 252 EventRouter::EventRouter(Profile* profile)
243 Profile* profile)
244 : notifications_(new DesktopNotifications(profile)), 253 : notifications_(new DesktopNotifications(profile)),
245 pref_change_registrar_(new PrefChangeRegistrar), 254 pref_change_registrar_(new PrefChangeRegistrar),
246 profile_(profile), 255 profile_(profile),
247 weak_factory_(this) { 256 weak_factory_(this) {
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
249 } 258 }
250 259
251 EventRouter::~EventRouter() { 260 EventRouter::~EventRouter() {
252 } 261 }
253 262
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 if (iter == file_watchers_.end()) 408 if (iter == file_watchers_.end())
400 return; 409 return;
401 // Remove the watcher if |watch_path| is no longer watched by any extensions. 410 // Remove the watcher if |watch_path| is no longer watched by any extensions.
402 iter->second->RemoveExtension(extension_id); 411 iter->second->RemoveExtension(extension_id);
403 if (iter->second->GetExtensionIds().empty()) { 412 if (iter->second->GetExtensionIds().empty()) {
404 delete iter->second; 413 delete iter->second;
405 file_watchers_.erase(iter); 414 file_watchers_.erase(iter);
406 } 415 }
407 } 416 }
408 417
418 void EventRouter::OnCopyCompleted(
419 int copy_id, const GURL& url, base::PlatformFileError error) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
421
422 using extensions::api::file_browser_private::CopyProgressStatus;
423 namespace OnCopyProgress =
424 extensions::api::file_browser_private::OnCopyProgress;
425
426 CopyProgressStatus status;
427 if (error == base::PLATFORM_FILE_OK) {
428 // Send success event.
429 status.type = CopyProgressStatus::TYPE_SUCCESS;
430 status.url.reset(new std::string(url.spec()));
431 } else {
432 // Send error event.
433 status.type = CopyProgressStatus::TYPE_ERROR;
434 status.error.reset(
435 new int(fileapi::PlatformFileErrorToWebFileError(error)));
436 }
437
438 BroadcastEvent(
439 profile_,
440 extensions::event_names::kOnFileBrowserCopyProgress,
441 OnCopyProgress::Create(copy_id, status));
442 }
443
409 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event, 444 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event,
410 const DiskMountManager::Disk* disk) { 445 const DiskMountManager::Disk* disk) {
411 // Disk event is dispatched by VolumeManager now. Do nothing. 446 // Disk event is dispatched by VolumeManager now. Do nothing.
412 } 447 }
413 448
414 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event, 449 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event,
415 const std::string& device_path) { 450 const std::string& device_path) {
416 // Device event is dispatched by VolumeManager now. Do nothing. 451 // Device event is dispatched by VolumeManager now. Do nothing.
417 } 452 }
418 453
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 const std::string& device_path) { 507 const std::string& device_path) {
473 // Format event is dispatched by VolumeManager now. Do nothing. 508 // Format event is dispatched by VolumeManager now. Do nothing.
474 } 509 }
475 510
476 void EventRouter::NetworkManagerChanged() { 511 void EventRouter::NetworkManagerChanged() {
477 if (!profile_ || 512 if (!profile_ ||
478 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 513 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
479 NOTREACHED(); 514 NOTREACHED();
480 return; 515 return;
481 } 516 }
482 scoped_ptr<extensions::Event> event(new extensions::Event( 517
518 BroadcastEvent(
519 profile_,
483 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 520 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
484 scoped_ptr<ListValue>(new ListValue()))); 521 make_scoped_ptr(new ListValue));
485 extensions::ExtensionSystem::Get(profile_)->event_router()->
486 BroadcastEvent(event.Pass());
487 } 522 }
488 523
489 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { 524 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) {
490 NetworkManagerChanged(); 525 NetworkManagerChanged();
491 } 526 }
492 527
493 void EventRouter::OnExternalStorageDisabledChanged() { 528 void EventRouter::OnExternalStorageDisabledChanged() {
494 // If the policy just got disabled we have to unmount every device currently 529 // If the policy just got disabled we have to unmount every device currently
495 // mounted. The opposite is fine - we can let the user re-plug her device to 530 // mounted. The opposite is fine - we can let the user re-plug her device to
496 // make it available. 531 // make it available.
(...skipping 11 matching lines...) Expand all
508 } 543 }
509 } 544 }
510 545
511 void EventRouter::OnFileManagerPrefsChanged() { 546 void EventRouter::OnFileManagerPrefsChanged() {
512 if (!profile_ || 547 if (!profile_ ||
513 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 548 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
514 NOTREACHED(); 549 NOTREACHED();
515 return; 550 return;
516 } 551 }
517 552
518 scoped_ptr<extensions::Event> event(new extensions::Event( 553 BroadcastEvent(
554 profile_,
519 extensions::event_names::kOnFileBrowserPreferencesChanged, 555 extensions::event_names::kOnFileBrowserPreferencesChanged,
520 scoped_ptr<ListValue>(new ListValue()))); 556 make_scoped_ptr(new ListValue));
521 extensions::ExtensionSystem::Get(profile_)->event_router()->
522 BroadcastEvent(event.Pass());
523 } 557 }
524 558
525 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { 559 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) {
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
527 OnJobUpdated(job_info); 561 OnJobUpdated(job_info);
528 } 562 }
529 563
530 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) { 564 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) {
531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
532 if (!drive::IsActiveFileTransferJobInfo(job_info)) 566 if (!drive::IsActiveFileTransferJobInfo(job_info))
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, 668 chromeos::MOUNT_TYPE_GOOGLE_DRIVE,
635 chromeos::disks::MOUNT_CONDITION_NONE); 669 chromeos::disks::MOUNT_CONDITION_NONE);
636 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, 670 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
637 mount_info); 671 mount_info);
638 } 672 }
639 673
640 void EventRouter::OnRefreshTokenInvalid() { 674 void EventRouter::OnRefreshTokenInvalid() {
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
642 676
643 // Raise a DriveConnectionStatusChanged event to notify the status offline. 677 // Raise a DriveConnectionStatusChanged event to notify the status offline.
644 scoped_ptr<extensions::Event> event(new extensions::Event( 678 BroadcastEvent(
679 profile_,
645 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 680 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
646 scoped_ptr<ListValue>(new ListValue()))); 681 make_scoped_ptr(new ListValue));
647 extensions::ExtensionSystem::Get(profile_)->event_router()->
648 BroadcastEvent(event.Pass());
649 } 682 }
650 683
651 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, 684 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path,
652 bool got_error) { 685 bool got_error) {
653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
654 687
655 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 688 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
656 if (iter == file_watchers_.end()) { 689 if (iter == file_watchers_.end()) {
657 return; 690 return;
658 } 691 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 &relative_mount_path)) { 762 &relative_mount_path)) {
730 mount_info_value->SetString("mountPath", 763 mount_info_value->SetString("mountPath",
731 "/" + relative_mount_path.value()); 764 "/" + relative_mount_path.value());
732 } else { 765 } else {
733 mount_info_value->SetString( 766 mount_info_value->SetString(
734 "status", 767 "status",
735 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); 768 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED));
736 } 769 }
737 } 770 }
738 771
739 scoped_ptr<extensions::Event> extension_event(new extensions::Event( 772 BroadcastEvent(profile_,
740 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass())); 773 extensions::event_names::kOnFileBrowserMountCompleted,
741 extensions::ExtensionSystem::Get(profile_)->event_router()-> 774 args.Pass());
742 BroadcastEvent(extension_event.Pass());
743 } 775 }
744 776
745 void EventRouter::ShowRemovableDeviceInFileManager( 777 void EventRouter::ShowRemovableDeviceInFileManager(
746 const DiskMountManager::Disk& disk, 778 const DiskMountManager::Disk& disk,
747 const base::FilePath& mount_path) { 779 const base::FilePath& mount_path) {
748 // Do not attempt to open File Manager while the login is in progress or 780 // Do not attempt to open File Manager while the login is in progress or
749 // the screen is locked. 781 // the screen is locked.
750 if (chromeos::LoginDisplayHostImpl::default_host() || 782 if (chromeos::LoginDisplayHostImpl::default_host() ||
751 chromeos::ScreenLocker::default_screen_locker()) 783 chromeos::ScreenLocker::default_screen_locker())
752 return; 784 return;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 base::TimeDelta::FromSeconds(4)); 872 base::TimeDelta::FromSeconds(4));
841 } else { 873 } else {
842 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 874 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
843 device_path); 875 device_path);
844 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, 876 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL,
845 device_path); 877 device_path);
846 } 878 }
847 } 879 }
848 880
849 } // namespace file_manager 881 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698