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

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

Issue 1036723003: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/chromeos/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 EventRouter::EventRouter(Profile* profile) 339 EventRouter::EventRouter(Profile* profile)
340 : pref_change_registrar_(new PrefChangeRegistrar), 340 : pref_change_registrar_(new PrefChangeRegistrar),
341 profile_(profile), 341 profile_(profile),
342 device_event_router_(new DeviceEventRouterImpl(profile)), 342 device_event_router_(new DeviceEventRouterImpl(profile)),
343 job_event_router_(new JobEventRouterImpl(profile)), 343 job_event_router_(new JobEventRouterImpl(profile)),
344 dispatch_directory_change_event_impl_( 344 dispatch_directory_change_event_impl_(
345 base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl, 345 base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl,
346 base::Unretained(this))), 346 base::Unretained(this))),
347 weak_factory_(this) { 347 weak_factory_(this) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 348 DCHECK_CURRENTLY_ON(BrowserThread::UI);
349 ObserveEvents(); 349 ObserveEvents();
350 } 350 }
351 351
352 EventRouter::~EventRouter() { 352 EventRouter::~EventRouter() {
353 } 353 }
354 354
355 void EventRouter::Shutdown() { 355 void EventRouter::Shutdown() {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
357 357
358 DLOG_IF(WARNING, !file_watchers_.empty()) 358 DLOG_IF(WARNING, !file_watchers_.empty())
359 << "Not all file watchers are " 359 << "Not all file watchers are "
360 << "removed. This can happen when Files.app is open during shutdown."; 360 << "removed. This can happen when Files.app is open during shutdown.";
361 STLDeleteValues(&file_watchers_); 361 STLDeleteValues(&file_watchers_);
362 if (!profile_) { 362 if (!profile_) {
363 NOTREACHED(); 363 NOTREACHED();
364 return; 364 return;
365 } 365 }
366 366
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 439 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
440 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 440 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
441 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 441 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
442 } 442 }
443 443
444 // File watch setup routines. 444 // File watch setup routines.
445 void EventRouter::AddFileWatch(const base::FilePath& local_path, 445 void EventRouter::AddFileWatch(const base::FilePath& local_path,
446 const base::FilePath& virtual_path, 446 const base::FilePath& virtual_path,
447 const std::string& extension_id, 447 const std::string& extension_id,
448 const BoolCallback& callback) { 448 const BoolCallback& callback) {
449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 449 DCHECK_CURRENTLY_ON(BrowserThread::UI);
450 DCHECK(!callback.is_null()); 450 DCHECK(!callback.is_null());
451 451
452 base::FilePath watch_path = local_path; 452 base::FilePath watch_path = local_path;
453 bool is_on_drive = drive::util::IsUnderDriveMountPoint(watch_path); 453 bool is_on_drive = drive::util::IsUnderDriveMountPoint(watch_path);
454 // Tweak watch path for remote sources - we need to drop leading /special 454 // Tweak watch path for remote sources - we need to drop leading /special
455 // directory from there in order to be able to pair these events with 455 // directory from there in order to be able to pair these events with
456 // their change notifications. 456 // their change notifications.
457 if (is_on_drive) 457 if (is_on_drive)
458 watch_path = drive::util::ExtractDrivePath(watch_path); 458 watch_path = drive::util::ExtractDrivePath(watch_path);
459 459
(...skipping 19 matching lines...) Expand all
479 file_watchers_[watch_path] = watcher.release(); 479 file_watchers_[watch_path] = watcher.release();
480 } else { 480 } else {
481 iter->second->AddExtension(extension_id); 481 iter->second->AddExtension(extension_id);
482 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 482 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
483 base::Bind(callback, true)); 483 base::Bind(callback, true));
484 } 484 }
485 } 485 }
486 486
487 void EventRouter::RemoveFileWatch(const base::FilePath& local_path, 487 void EventRouter::RemoveFileWatch(const base::FilePath& local_path,
488 const std::string& extension_id) { 488 const std::string& extension_id) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK_CURRENTLY_ON(BrowserThread::UI);
490 490
491 base::FilePath watch_path = local_path; 491 base::FilePath watch_path = local_path;
492 // Tweak watch path for remote sources - we need to drop leading /special 492 // Tweak watch path for remote sources - we need to drop leading /special
493 // directory from there in order to be able to pair these events with 493 // directory from there in order to be able to pair these events with
494 // their change notifications. 494 // their change notifications.
495 if (drive::util::IsUnderDriveMountPoint(watch_path)) { 495 if (drive::util::IsUnderDriveMountPoint(watch_path)) {
496 watch_path = drive::util::ExtractDrivePath(watch_path); 496 watch_path = drive::util::ExtractDrivePath(watch_path);
497 } 497 }
498 WatcherMap::iterator iter = file_watchers_.find(watch_path); 498 WatcherMap::iterator iter = file_watchers_.find(watch_path);
499 if (iter == file_watchers_.end()) 499 if (iter == file_watchers_.end())
500 return; 500 return;
501 // Remove the watcher if |watch_path| is no longer watched by any extensions. 501 // Remove the watcher if |watch_path| is no longer watched by any extensions.
502 iter->second->RemoveExtension(extension_id); 502 iter->second->RemoveExtension(extension_id);
503 if (iter->second->GetExtensionIds().empty()) { 503 if (iter->second->GetExtensionIds().empty()) {
504 delete iter->second; 504 delete iter->second;
505 file_watchers_.erase(iter); 505 file_watchers_.erase(iter);
506 } 506 }
507 } 507 }
508 508
509 void EventRouter::OnCopyCompleted(int copy_id, 509 void EventRouter::OnCopyCompleted(int copy_id,
510 const GURL& source_url, 510 const GURL& source_url,
511 const GURL& destination_url, 511 const GURL& destination_url,
512 base::File::Error error) { 512 base::File::Error error) {
513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 513 DCHECK_CURRENTLY_ON(BrowserThread::UI);
514 514
515 file_manager_private::CopyProgressStatus status; 515 file_manager_private::CopyProgressStatus status;
516 if (error == base::File::FILE_OK) { 516 if (error == base::File::FILE_OK) {
517 // Send success event. 517 // Send success event.
518 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_SUCCESS; 518 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_SUCCESS;
519 status.source_url.reset(new std::string(source_url.spec())); 519 status.source_url.reset(new std::string(source_url.spec()));
520 status.destination_url.reset(new std::string(destination_url.spec())); 520 status.destination_url.reset(new std::string(destination_url.spec()));
521 } else { 521 } else {
522 // Send error event. 522 // Send error event.
523 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_ERROR; 523 status.type = file_manager_private::COPY_PROGRESS_STATUS_TYPE_ERROR;
524 status.error.reset(new std::string(FileErrorToErrorName(error))); 524 status.error.reset(new std::string(FileErrorToErrorName(error)));
525 } 525 }
526 526
527 BroadcastEvent( 527 BroadcastEvent(
528 profile_, 528 profile_,
529 file_manager_private::OnCopyProgress::kEventName, 529 file_manager_private::OnCopyProgress::kEventName,
530 file_manager_private::OnCopyProgress::Create(copy_id, status)); 530 file_manager_private::OnCopyProgress::Create(copy_id, status));
531 } 531 }
532 532
533 void EventRouter::OnCopyProgress( 533 void EventRouter::OnCopyProgress(
534 int copy_id, 534 int copy_id,
535 storage::FileSystemOperation::CopyProgressType type, 535 storage::FileSystemOperation::CopyProgressType type,
536 const GURL& source_url, 536 const GURL& source_url,
537 const GURL& destination_url, 537 const GURL& destination_url,
538 int64 size) { 538 int64 size) {
539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 539 DCHECK_CURRENTLY_ON(BrowserThread::UI);
540 540
541 file_manager_private::CopyProgressStatus status; 541 file_manager_private::CopyProgressStatus status;
542 status.type = CopyProgressTypeToCopyProgressStatusType(type); 542 status.type = CopyProgressTypeToCopyProgressStatusType(type);
543 status.source_url.reset(new std::string(source_url.spec())); 543 status.source_url.reset(new std::string(source_url.spec()));
544 if (type == storage::FileSystemOperation::END_COPY_ENTRY) 544 if (type == storage::FileSystemOperation::END_COPY_ENTRY)
545 status.destination_url.reset(new std::string(destination_url.spec())); 545 status.destination_url.reset(new std::string(destination_url.spec()));
546 if (type == storage::FileSystemOperation::PROGRESS) 546 if (type == storage::FileSystemOperation::PROGRESS)
547 status.size.reset(new double(size)); 547 status.size.reset(new double(size));
548 548
549 // Should not skip events other than TYPE_PROGRESS. 549 // Should not skip events other than TYPE_PROGRESS.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 677 }
678 event.file_url = util::ConvertDrivePathToFileSystemUrl( 678 event.file_url = util::ConvertDrivePathToFileSystemUrl(
679 profile_, drive_path, kFileManagerAppId).spec(); 679 profile_, drive_path, kFileManagerAppId).spec();
680 BroadcastEvent( 680 BroadcastEvent(
681 profile_, 681 profile_,
682 file_manager_private::OnDriveSyncError::kEventName, 682 file_manager_private::OnDriveSyncError::kEventName,
683 file_manager_private::OnDriveSyncError::Create(event)); 683 file_manager_private::OnDriveSyncError::Create(event));
684 } 684 }
685 685
686 void EventRouter::OnRefreshTokenInvalid() { 686 void EventRouter::OnRefreshTokenInvalid() {
687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 687 DCHECK_CURRENTLY_ON(BrowserThread::UI);
688 688
689 // Raise a DriveConnectionStatusChanged event to notify the status offline. 689 // Raise a DriveConnectionStatusChanged event to notify the status offline.
690 BroadcastEvent( 690 BroadcastEvent(
691 profile_, 691 profile_,
692 file_manager_private::OnDriveConnectionStatusChanged::kEventName, 692 file_manager_private::OnDriveConnectionStatusChanged::kEventName,
693 file_manager_private::OnDriveConnectionStatusChanged::Create()); 693 file_manager_private::OnDriveConnectionStatusChanged::Create());
694 } 694 }
695 695
696 void EventRouter::OnReadyToSendRequests() { 696 void EventRouter::OnReadyToSendRequests() {
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 697 DCHECK_CURRENTLY_ON(BrowserThread::UI);
698 698
699 // Raise a DriveConnectionStatusChanged event to notify the status online. 699 // Raise a DriveConnectionStatusChanged event to notify the status online.
700 BroadcastEvent( 700 BroadcastEvent(
701 profile_, 701 profile_,
702 file_manager_private::OnDriveConnectionStatusChanged::kEventName, 702 file_manager_private::OnDriveConnectionStatusChanged::kEventName,
703 file_manager_private::OnDriveConnectionStatusChanged::Create()); 703 file_manager_private::OnDriveConnectionStatusChanged::Create());
704 } 704 }
705 705
706 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, 706 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list,
707 const base::FilePath& local_path, 707 const base::FilePath& local_path,
708 bool got_error) { 708 bool got_error) {
709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 709 DCHECK_CURRENTLY_ON(BrowserThread::UI);
710 710
711 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 711 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
712 if (iter == file_watchers_.end()) { 712 if (iter == file_watchers_.end()) {
713 return; 713 return;
714 } 714 }
715 715
716 if (list && list->size() > kDirectoryChangeEventMaxDetailInfoSize) { 716 if (list && list->size() > kDirectoryChangeEventMaxDetailInfoSize) {
717 // Removes the detailed information, if the list size is more than 717 // Removes the detailed information, if the list size is more than
718 // kDirectoryChangeEventMaxDetailInfoSize, since passing large list 718 // kDirectoryChangeEventMaxDetailInfoSize, since passing large list
719 // and processing it may cause more itme. 719 // and processing it may cause more itme.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 830
831 DispatchEventToExtension( 831 DispatchEventToExtension(
832 profile_, 832 profile_,
833 *extension_id, 833 *extension_id,
834 file_manager_private::OnDirectoryChanged::kEventName, 834 file_manager_private::OnDirectoryChanged::kEventName,
835 file_manager_private::OnDirectoryChanged::Create(event)); 835 file_manager_private::OnDirectoryChanged::Create(event));
836 } 836 }
837 837
838 void EventRouter::OnDiskAdded( 838 void EventRouter::OnDiskAdded(
839 const DiskMountManager::Disk& disk, bool mounting) { 839 const DiskMountManager::Disk& disk, bool mounting) {
840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 840 DCHECK_CURRENTLY_ON(BrowserThread::UI);
841 // Do nothing. 841 // Do nothing.
842 } 842 }
843 843
844 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) { 844 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk& disk) {
845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 845 DCHECK_CURRENTLY_ON(BrowserThread::UI);
846 // Do nothing. 846 // Do nothing.
847 } 847 }
848 848
849 void EventRouter::OnDeviceAdded(const std::string& device_path) { 849 void EventRouter::OnDeviceAdded(const std::string& device_path) {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 850 DCHECK_CURRENTLY_ON(BrowserThread::UI);
851 // Do nothing. 851 // Do nothing.
852 } 852 }
853 853
854 void EventRouter::OnDeviceRemoved(const std::string& device_path) { 854 void EventRouter::OnDeviceRemoved(const std::string& device_path) {
855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 855 DCHECK_CURRENTLY_ON(BrowserThread::UI);
856 // Do nothing. 856 // Do nothing.
857 } 857 }
858 858
859 void EventRouter::OnVolumeMounted(chromeos::MountError error_code, 859 void EventRouter::OnVolumeMounted(chromeos::MountError error_code,
860 const VolumeInfo& volume_info) { 860 const VolumeInfo& volume_info) {
861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 861 DCHECK_CURRENTLY_ON(BrowserThread::UI);
862 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 862 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
863 // happen at shutdown. This should be removed after removing Drive mounting 863 // happen at shutdown. This should be removed after removing Drive mounting
864 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is 864 // code in addMount. (addMount -> OnFileSystemMounted -> OnVolumeMounted is
865 // the only path to come here after Shutdown is called). 865 // the only path to come here after Shutdown is called).
866 if (!profile_) 866 if (!profile_)
867 return; 867 return;
868 868
869 DispatchMountCompletedEvent( 869 DispatchMountCompletedEvent(
870 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT, 870 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_MOUNT,
871 error_code, 871 error_code,
872 volume_info); 872 volume_info);
873 } 873 }
874 874
875 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code, 875 void EventRouter::OnVolumeUnmounted(chromeos::MountError error_code,
876 const VolumeInfo& volume_info) { 876 const VolumeInfo& volume_info) {
877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 877 DCHECK_CURRENTLY_ON(BrowserThread::UI);
878 DispatchMountCompletedEvent( 878 DispatchMountCompletedEvent(
879 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT, 879 file_manager_private::MOUNT_COMPLETED_EVENT_TYPE_UNMOUNT,
880 error_code, 880 error_code,
881 volume_info); 881 volume_info);
882 } 882 }
883 883
884 void EventRouter::DispatchMountCompletedEvent( 884 void EventRouter::DispatchMountCompletedEvent(
885 file_manager_private::MountCompletedEventType event_type, 885 file_manager_private::MountCompletedEventType event_type,
886 chromeos::MountError error, 886 chromeos::MountError error,
887 const VolumeInfo& volume_info) { 887 const VolumeInfo& volume_info) {
888 // Build an event object. 888 // Build an event object.
889 file_manager_private::MountCompletedEvent event; 889 file_manager_private::MountCompletedEvent event;
890 event.event_type = event_type; 890 event.event_type = event_type;
891 event.status = MountErrorToMountCompletedStatus(error); 891 event.status = MountErrorToMountCompletedStatus(error);
892 util::VolumeInfoToVolumeMetadata( 892 util::VolumeInfoToVolumeMetadata(
893 profile_, volume_info, &event.volume_metadata); 893 profile_, volume_info, &event.volume_metadata);
894 event.should_notify = ShouldShowNotificationForVolume( 894 event.should_notify = ShouldShowNotificationForVolume(
895 profile_, *device_event_router_, volume_info); 895 profile_, *device_event_router_, volume_info);
896 BroadcastEvent(profile_, 896 BroadcastEvent(profile_,
897 file_manager_private::OnMountCompleted::kEventName, 897 file_manager_private::OnMountCompleted::kEventName,
898 file_manager_private::OnMountCompleted::Create(event)); 898 file_manager_private::OnMountCompleted::Create(event));
899 } 899 }
900 900
901 void EventRouter::OnFormatStarted(const std::string& device_path, 901 void EventRouter::OnFormatStarted(const std::string& device_path,
902 bool success) { 902 bool success) {
903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 903 DCHECK_CURRENTLY_ON(BrowserThread::UI);
904 // Do nothing. 904 // Do nothing.
905 } 905 }
906 906
907 void EventRouter::OnFormatCompleted(const std::string& device_path, 907 void EventRouter::OnFormatCompleted(const std::string& device_path,
908 bool success) { 908 bool success) {
909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 909 DCHECK_CURRENTLY_ON(BrowserThread::UI);
910 // Do nothing. 910 // Do nothing.
911 } 911 }
912 912
913 void EventRouter::SetDispatchDirectoryChangeEventImplForTesting( 913 void EventRouter::SetDispatchDirectoryChangeEventImplForTesting(
914 const DispatchDirectoryChangeEventImplCallback& callback) { 914 const DispatchDirectoryChangeEventImplCallback& callback) {
915 dispatch_directory_change_event_impl_ = callback; 915 dispatch_directory_change_event_impl_ = callback;
916 } 916 }
917 917
918 base::WeakPtr<EventRouter> EventRouter::GetWeakPtr() { 918 base::WeakPtr<EventRouter> EventRouter::GetWeakPtr() {
919 return weak_factory_.GetWeakPtr(); 919 return weak_factory_.GetWeakPtr();
920 } 920 }
921 921
922 } // namespace file_manager 922 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698