| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 void ProvidedFileSystem::OnAddWatcherInQueueCompleted( | 647 void ProvidedFileSystem::OnAddWatcherInQueueCompleted( |
| 648 size_t token, | 648 size_t token, |
| 649 const base::FilePath& entry_path, | 649 const base::FilePath& entry_path, |
| 650 bool recursive, | 650 bool recursive, |
| 651 const Subscriber& subscriber, | 651 const Subscriber& subscriber, |
| 652 const storage::AsyncFileUtil::StatusCallback& callback, | 652 const storage::AsyncFileUtil::StatusCallback& callback, |
| 653 base::File::Error result) { | 653 base::File::Error result) { |
| 654 if (result != base::File::FILE_OK) { | 654 if (result != base::File::FILE_OK) { |
| 655 callback.Run(result); | 655 callback.Run(result); |
| 656 watcher_queue_.Complete(token); | 656 watcher_queue_.Complete(token); |
| 657 watcher_queue_.Remove(token); | |
| 658 return; | 657 return; |
| 659 } | 658 } |
| 660 | 659 |
| 661 const WatcherKey key(entry_path, recursive); | 660 const WatcherKey key(entry_path, recursive); |
| 662 const Watchers::iterator it = watchers_.find(key); | 661 const Watchers::iterator it = watchers_.find(key); |
| 663 if (it != watchers_.end()) { | 662 if (it != watchers_.end()) { |
| 664 callback.Run(base::File::FILE_OK); | 663 callback.Run(base::File::FILE_OK); |
| 665 watcher_queue_.Complete(token); | 664 watcher_queue_.Complete(token); |
| 666 watcher_queue_.Remove(token); | |
| 667 return; | 665 return; |
| 668 } | 666 } |
| 669 | 667 |
| 670 Watcher* const watcher = &watchers_[key]; | 668 Watcher* const watcher = &watchers_[key]; |
| 671 watcher->entry_path = entry_path; | 669 watcher->entry_path = entry_path; |
| 672 watcher->recursive = recursive; | 670 watcher->recursive = recursive; |
| 673 watcher->subscribers[subscriber.origin] = subscriber; | 671 watcher->subscribers[subscriber.origin] = subscriber; |
| 674 | 672 |
| 675 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 673 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, |
| 676 observers_, | 674 observers_, |
| 677 OnWatcherListChanged(file_system_info_, watchers_)); | 675 OnWatcherListChanged(file_system_info_, watchers_)); |
| 678 | 676 |
| 679 callback.Run(base::File::FILE_OK); | 677 callback.Run(base::File::FILE_OK); |
| 680 watcher_queue_.Complete(token); | 678 watcher_queue_.Complete(token); |
| 681 watcher_queue_.Remove(token); | |
| 682 } | 679 } |
| 683 | 680 |
| 684 void ProvidedFileSystem::OnRemoveWatcherInQueueCompleted( | 681 void ProvidedFileSystem::OnRemoveWatcherInQueueCompleted( |
| 685 size_t token, | 682 size_t token, |
| 686 const GURL& origin, | 683 const GURL& origin, |
| 687 const WatcherKey& key, | 684 const WatcherKey& key, |
| 688 const storage::AsyncFileUtil::StatusCallback& callback, | 685 const storage::AsyncFileUtil::StatusCallback& callback, |
| 689 bool extension_response, | 686 bool extension_response, |
| 690 base::File::Error result) { | 687 base::File::Error result) { |
| 691 if (!extension_response && result != base::File::FILE_OK) { | 688 if (!extension_response && result != base::File::FILE_OK) { |
| 692 watcher_queue_.Complete(token); | 689 watcher_queue_.Complete(token); |
| 693 watcher_queue_.Remove(token); | |
| 694 callback.Run(result); | 690 callback.Run(result); |
| 695 return; | 691 return; |
| 696 } | 692 } |
| 697 | 693 |
| 698 // Even if the extension returns an error, the callback is called with base:: | 694 // Even if the extension returns an error, the callback is called with base:: |
| 699 // File::FILE_OK. | 695 // File::FILE_OK. |
| 700 const auto it = watchers_.find(key); | 696 const auto it = watchers_.find(key); |
| 701 DCHECK(it != watchers_.end()); | 697 DCHECK(it != watchers_.end()); |
| 702 DCHECK(it->second.subscribers.find(origin) != it->second.subscribers.end()); | 698 DCHECK(it->second.subscribers.find(origin) != it->second.subscribers.end()); |
| 703 | 699 |
| 704 it->second.subscribers.erase(origin); | 700 it->second.subscribers.erase(origin); |
| 705 | 701 |
| 706 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, observers_, | 702 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, observers_, |
| 707 OnWatcherListChanged(file_system_info_, watchers_)); | 703 OnWatcherListChanged(file_system_info_, watchers_)); |
| 708 | 704 |
| 709 // If there are no more subscribers, then remove the watcher. | 705 // If there are no more subscribers, then remove the watcher. |
| 710 if (!it->second.subscribers.size()) | 706 if (!it->second.subscribers.size()) |
| 711 watchers_.erase(it); | 707 watchers_.erase(it); |
| 712 | 708 |
| 713 callback.Run(base::File::FILE_OK); | 709 callback.Run(base::File::FILE_OK); |
| 714 watcher_queue_.Complete(token); | 710 watcher_queue_.Complete(token); |
| 715 watcher_queue_.Remove(token); | |
| 716 } | 711 } |
| 717 | 712 |
| 718 void ProvidedFileSystem::OnNotifyInQueueCompleted( | 713 void ProvidedFileSystem::OnNotifyInQueueCompleted( |
| 719 scoped_ptr<NotifyInQueueArgs> args, | 714 scoped_ptr<NotifyInQueueArgs> args, |
| 720 base::File::Error result) { | 715 base::File::Error result) { |
| 721 if (result != base::File::FILE_OK) { | 716 if (result != base::File::FILE_OK) { |
| 722 args->callback.Run(result); | 717 args->callback.Run(result); |
| 723 watcher_queue_.Complete(args->token); | 718 watcher_queue_.Complete(args->token); |
| 724 watcher_queue_.Remove(args->token); | |
| 725 return; | 719 return; |
| 726 } | 720 } |
| 727 | 721 |
| 728 // Check if the entry is still watched. | 722 // Check if the entry is still watched. |
| 729 const WatcherKey key(args->entry_path, args->recursive); | 723 const WatcherKey key(args->entry_path, args->recursive); |
| 730 const Watchers::iterator it = watchers_.find(key); | 724 const Watchers::iterator it = watchers_.find(key); |
| 731 if (it == watchers_.end()) { | 725 if (it == watchers_.end()) { |
| 732 args->callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 726 args->callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 733 watcher_queue_.Complete(args->token); | 727 watcher_queue_.Complete(args->token); |
| 734 watcher_queue_.Remove(args->token); | |
| 735 return; | 728 return; |
| 736 } | 729 } |
| 737 | 730 |
| 738 it->second.last_tag = args->tag; | 731 it->second.last_tag = args->tag; |
| 739 | 732 |
| 740 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 733 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, |
| 741 observers_, | 734 observers_, |
| 742 OnWatcherTagUpdated(file_system_info_, it->second)); | 735 OnWatcherTagUpdated(file_system_info_, it->second)); |
| 743 | 736 |
| 744 // If the watched entry is deleted, then remove the watcher. | 737 // If the watched entry is deleted, then remove the watcher. |
| 745 if (args->change_type == storage::WatcherManager::DELETED) { | 738 if (args->change_type == storage::WatcherManager::DELETED) { |
| 746 // Make a copy, since the |it| iterator will get invalidated on the last | 739 // Make a copy, since the |it| iterator will get invalidated on the last |
| 747 // subscriber. | 740 // subscriber. |
| 748 Subscribers subscribers = it->second.subscribers; | 741 Subscribers subscribers = it->second.subscribers; |
| 749 for (const auto& subscriber_it : subscribers) { | 742 for (const auto& subscriber_it : subscribers) { |
| 750 RemoveWatcher(subscriber_it.second.origin, args->entry_path, | 743 RemoveWatcher(subscriber_it.second.origin, args->entry_path, |
| 751 args->recursive, base::Bind(&EmptyStatusCallback)); | 744 args->recursive, base::Bind(&EmptyStatusCallback)); |
| 752 } | 745 } |
| 753 } | 746 } |
| 754 | 747 |
| 755 args->callback.Run(base::File::FILE_OK); | 748 args->callback.Run(base::File::FILE_OK); |
| 756 watcher_queue_.Complete(args->token); | 749 watcher_queue_.Complete(args->token); |
| 757 watcher_queue_.Remove(args->token); | |
| 758 } | 750 } |
| 759 | 751 |
| 760 void ProvidedFileSystem::OnOpenFileCompleted(const base::FilePath& file_path, | 752 void ProvidedFileSystem::OnOpenFileCompleted(const base::FilePath& file_path, |
| 761 OpenFileMode mode, | 753 OpenFileMode mode, |
| 762 const OpenFileCallback& callback, | 754 const OpenFileCallback& callback, |
| 763 int file_handle, | 755 int file_handle, |
| 764 base::File::Error result) { | 756 base::File::Error result) { |
| 765 if (result != base::File::FILE_OK) { | 757 if (result != base::File::FILE_OK) { |
| 766 callback.Run(file_handle, result); | 758 callback.Run(file_handle, result); |
| 767 return; | 759 return; |
| 768 } | 760 } |
| 769 | 761 |
| 770 opened_files_[file_handle] = OpenedFile(file_path, mode); | 762 opened_files_[file_handle] = OpenedFile(file_path, mode); |
| 771 callback.Run(file_handle, base::File::FILE_OK); | 763 callback.Run(file_handle, base::File::FILE_OK); |
| 772 } | 764 } |
| 773 | 765 |
| 774 void ProvidedFileSystem::OnCloseFileCompleted( | 766 void ProvidedFileSystem::OnCloseFileCompleted( |
| 775 int file_handle, | 767 int file_handle, |
| 776 const storage::AsyncFileUtil::StatusCallback& callback, | 768 const storage::AsyncFileUtil::StatusCallback& callback, |
| 777 base::File::Error result) { | 769 base::File::Error result) { |
| 778 // Closing files is final. Even if an error happened, we remove it from the | 770 // Closing files is final. Even if an error happened, we remove it from the |
| 779 // list of opened files. | 771 // list of opened files. |
| 780 opened_files_.erase(file_handle); | 772 opened_files_.erase(file_handle); |
| 781 callback.Run(result); | 773 callback.Run(result); |
| 782 } | 774 } |
| 783 | 775 |
| 784 } // namespace file_system_provider | 776 } // namespace file_system_provider |
| 785 } // namespace chromeos | 777 } // namespace chromeos |
| OLD | NEW |