| OLD | NEW |
| 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/file_system_provider/provided_file_system.h" | 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 | 680 |
| 681 // Call all notification callbacks (if any). | 681 // Call all notification callbacks (if any). |
| 682 for (const auto& subscriber_it : watcher_it->second.subscribers) { | 682 for (const auto& subscriber_it : watcher_it->second.subscribers) { |
| 683 const storage::WatcherManager::NotificationCallback& notification_callback = | 683 const storage::WatcherManager::NotificationCallback& notification_callback = |
| 684 subscriber_it.second.notification_callback; | 684 subscriber_it.second.notification_callback; |
| 685 if (!notification_callback.is_null()) | 685 if (!notification_callback.is_null()) |
| 686 notification_callback.Run(change_type); | 686 notification_callback.Run(change_type); |
| 687 } | 687 } |
| 688 | 688 |
| 689 // Notify all observers. | 689 // Notify all observers. |
| 690 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 690 for (auto& observer : observers_) { |
| 691 observers_, | 691 observer.OnWatcherChanged(file_system_info_, watcher_it->second, |
| 692 OnWatcherChanged(file_system_info_, | 692 change_type, changes_ref, |
| 693 watcher_it->second, | 693 auto_updater->CreateCallback()); |
| 694 change_type, | 694 } |
| 695 changes_ref, | |
| 696 auto_updater->CreateCallback())); | |
| 697 | 695 |
| 698 return AbortCallback(); | 696 return AbortCallback(); |
| 699 } | 697 } |
| 700 | 698 |
| 701 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { | 699 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { |
| 702 return weak_ptr_factory_.GetWeakPtr(); | 700 return weak_ptr_factory_.GetWeakPtr(); |
| 703 } | 701 } |
| 704 | 702 |
| 705 void ProvidedFileSystem::OnAddWatcherInQueueCompleted( | 703 void ProvidedFileSystem::OnAddWatcherInQueueCompleted( |
| 706 size_t token, | 704 size_t token, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 721 callback.Run(base::File::FILE_OK); | 719 callback.Run(base::File::FILE_OK); |
| 722 watcher_queue_.Complete(token); | 720 watcher_queue_.Complete(token); |
| 723 return; | 721 return; |
| 724 } | 722 } |
| 725 | 723 |
| 726 Watcher* const watcher = &watchers_[key]; | 724 Watcher* const watcher = &watchers_[key]; |
| 727 watcher->entry_path = entry_path; | 725 watcher->entry_path = entry_path; |
| 728 watcher->recursive = recursive; | 726 watcher->recursive = recursive; |
| 729 watcher->subscribers[subscriber.origin] = subscriber; | 727 watcher->subscribers[subscriber.origin] = subscriber; |
| 730 | 728 |
| 731 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 729 for (auto& observer : observers_) |
| 732 observers_, | 730 observer.OnWatcherListChanged(file_system_info_, watchers_); |
| 733 OnWatcherListChanged(file_system_info_, watchers_)); | |
| 734 | 731 |
| 735 callback.Run(base::File::FILE_OK); | 732 callback.Run(base::File::FILE_OK); |
| 736 watcher_queue_.Complete(token); | 733 watcher_queue_.Complete(token); |
| 737 } | 734 } |
| 738 | 735 |
| 739 void ProvidedFileSystem::OnRemoveWatcherInQueueCompleted( | 736 void ProvidedFileSystem::OnRemoveWatcherInQueueCompleted( |
| 740 size_t token, | 737 size_t token, |
| 741 const GURL& origin, | 738 const GURL& origin, |
| 742 const WatcherKey& key, | 739 const WatcherKey& key, |
| 743 const storage::AsyncFileUtil::StatusCallback& callback, | 740 const storage::AsyncFileUtil::StatusCallback& callback, |
| 744 bool extension_response, | 741 bool extension_response, |
| 745 base::File::Error result) { | 742 base::File::Error result) { |
| 746 if (!extension_response && result != base::File::FILE_OK) { | 743 if (!extension_response && result != base::File::FILE_OK) { |
| 747 watcher_queue_.Complete(token); | 744 watcher_queue_.Complete(token); |
| 748 callback.Run(result); | 745 callback.Run(result); |
| 749 return; | 746 return; |
| 750 } | 747 } |
| 751 | 748 |
| 752 // Even if the extension returns an error, the callback is called with base:: | 749 // Even if the extension returns an error, the callback is called with base:: |
| 753 // File::FILE_OK. | 750 // File::FILE_OK. |
| 754 const auto it = watchers_.find(key); | 751 const auto it = watchers_.find(key); |
| 755 DCHECK(it != watchers_.end()); | 752 DCHECK(it != watchers_.end()); |
| 756 DCHECK(it->second.subscribers.find(origin) != it->second.subscribers.end()); | 753 DCHECK(it->second.subscribers.find(origin) != it->second.subscribers.end()); |
| 757 | 754 |
| 758 it->second.subscribers.erase(origin); | 755 it->second.subscribers.erase(origin); |
| 759 | 756 |
| 760 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, observers_, | 757 for (auto& observer : observers_) |
| 761 OnWatcherListChanged(file_system_info_, watchers_)); | 758 observer.OnWatcherListChanged(file_system_info_, watchers_); |
| 762 | 759 |
| 763 // If there are no more subscribers, then remove the watcher. | 760 // If there are no more subscribers, then remove the watcher. |
| 764 if (it->second.subscribers.empty()) | 761 if (it->second.subscribers.empty()) |
| 765 watchers_.erase(it); | 762 watchers_.erase(it); |
| 766 | 763 |
| 767 callback.Run(base::File::FILE_OK); | 764 callback.Run(base::File::FILE_OK); |
| 768 watcher_queue_.Complete(token); | 765 watcher_queue_.Complete(token); |
| 769 } | 766 } |
| 770 | 767 |
| 771 void ProvidedFileSystem::OnNotifyInQueueCompleted( | 768 void ProvidedFileSystem::OnNotifyInQueueCompleted( |
| 772 std::unique_ptr<NotifyInQueueArgs> args, | 769 std::unique_ptr<NotifyInQueueArgs> args, |
| 773 base::File::Error result) { | 770 base::File::Error result) { |
| 774 if (result != base::File::FILE_OK) { | 771 if (result != base::File::FILE_OK) { |
| 775 args->callback.Run(result); | 772 args->callback.Run(result); |
| 776 watcher_queue_.Complete(args->token); | 773 watcher_queue_.Complete(args->token); |
| 777 return; | 774 return; |
| 778 } | 775 } |
| 779 | 776 |
| 780 // Check if the entry is still watched. | 777 // Check if the entry is still watched. |
| 781 const WatcherKey key(args->entry_path, args->recursive); | 778 const WatcherKey key(args->entry_path, args->recursive); |
| 782 const Watchers::iterator it = watchers_.find(key); | 779 const Watchers::iterator it = watchers_.find(key); |
| 783 if (it == watchers_.end()) { | 780 if (it == watchers_.end()) { |
| 784 args->callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 781 args->callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 785 watcher_queue_.Complete(args->token); | 782 watcher_queue_.Complete(args->token); |
| 786 return; | 783 return; |
| 787 } | 784 } |
| 788 | 785 |
| 789 it->second.last_tag = args->tag; | 786 it->second.last_tag = args->tag; |
| 790 | 787 |
| 791 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 788 for (auto& observer : observers_) |
| 792 observers_, | 789 observer.OnWatcherTagUpdated(file_system_info_, it->second); |
| 793 OnWatcherTagUpdated(file_system_info_, it->second)); | |
| 794 | 790 |
| 795 // If the watched entry is deleted, then remove the watcher. | 791 // If the watched entry is deleted, then remove the watcher. |
| 796 if (args->change_type == storage::WatcherManager::DELETED) { | 792 if (args->change_type == storage::WatcherManager::DELETED) { |
| 797 // Make a copy, since the |it| iterator will get invalidated on the last | 793 // Make a copy, since the |it| iterator will get invalidated on the last |
| 798 // subscriber. | 794 // subscriber. |
| 799 Subscribers subscribers = it->second.subscribers; | 795 Subscribers subscribers = it->second.subscribers; |
| 800 for (const auto& subscriber_it : subscribers) { | 796 for (const auto& subscriber_it : subscribers) { |
| 801 RemoveWatcher(subscriber_it.second.origin, args->entry_path, | 797 RemoveWatcher(subscriber_it.second.origin, args->entry_path, |
| 802 args->recursive, base::Bind(&EmptyStatusCallback)); | 798 args->recursive, base::Bind(&EmptyStatusCallback)); |
| 803 } | 799 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 826 const storage::AsyncFileUtil::StatusCallback& callback, | 822 const storage::AsyncFileUtil::StatusCallback& callback, |
| 827 base::File::Error result) { | 823 base::File::Error result) { |
| 828 // Closing files is final. Even if an error happened, we remove it from the | 824 // Closing files is final. Even if an error happened, we remove it from the |
| 829 // list of opened files. | 825 // list of opened files. |
| 830 opened_files_.erase(file_handle); | 826 opened_files_.erase(file_handle); |
| 831 callback.Run(result); | 827 callback.Run(result); |
| 832 } | 828 } |
| 833 | 829 |
| 834 } // namespace file_system_provider | 830 } // namespace file_system_provider |
| 835 } // namespace chromeos | 831 } // namespace chromeos |
| OLD | NEW |