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

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

Issue 658013002: Changed api to notify when watched directory is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed to fix OnFileChanged rather than HandleFileWatchNotification. Created 6 years, 2 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/files/file_util.h" 8 #include "base/files/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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( 380 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus(
381 const drive::JobInfo& info, const std::string& status) 381 const drive::JobInfo& info, const std::string& status)
382 : job_info(info), status(status) { 382 : job_info(info), status(status) {
383 } 383 }
384 384
385 EventRouter::EventRouter(Profile* profile) 385 EventRouter::EventRouter(Profile* profile)
386 : pref_change_registrar_(new PrefChangeRegistrar), 386 : pref_change_registrar_(new PrefChangeRegistrar),
387 profile_(profile), 387 profile_(profile),
388 device_event_router_(new DeviceEventRouterImpl(profile)), 388 device_event_router_(new DeviceEventRouterImpl(profile)),
389 weak_factory_(this) { 389 weak_factory_(this),
390 dispatch_directory_change_event_impl_(
391 base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl,
392 base::Unretained(this))) {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
391 ObserveEvents(); 394 ObserveEvents();
392 } 395 }
393 396
394 EventRouter::~EventRouter() { 397 EventRouter::~EventRouter() {
395 } 398 }
396 399
397 void EventRouter::Shutdown() { 400 void EventRouter::Shutdown() {
398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
399 402
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 file_manager_private::OnFileTransfersUpdated::kEventName, 708 file_manager_private::OnFileTransfersUpdated::kEventName,
706 file_manager_private::OnFileTransfersUpdated::Create(status)); 709 file_manager_private::OnFileTransfersUpdated::Create(status));
707 } 710 }
708 711
709 void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) { 712 void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
710 HandleFileWatchNotification(NULL, drive_path, false); 713 HandleFileWatchNotification(NULL, drive_path, false);
711 } 714 }
712 715
713 void EventRouter::OnFileChanged(const drive::FileChange& changed_files) { 716 void EventRouter::OnFileChanged(const drive::FileChange& changed_files) {
714 typedef std::map<base::FilePath, drive::FileChange> FileChangeMap; 717 typedef std::map<base::FilePath, drive::FileChange> FileChangeMap;
718 typedef drive::FileChange::ChangeList::List FileChangeList;
715 719
716 FileChangeMap map; 720 FileChangeMap map;
717 const drive::FileChange::Map& changed_file_map = changed_files.map(); 721 const drive::FileChange::Map& changed_file_map = changed_files.map();
718 for (drive::FileChange::Map::const_iterator it = changed_file_map.begin(); 722 for (drive::FileChange::Map::const_iterator it = changed_file_map.begin();
719 it != changed_file_map.end(); 723 it != changed_file_map.end();
720 it++) { 724 it++) {
725 bool containsDirectoryDeletion = false;
mtomasz 2014/10/17 05:26:56 nit: Please mark const what can be const.
yawano 2014/10/20 00:49:48 Done.
726 FileChangeList list = it->second.list();
727 for (FileChangeList::const_iterator iter = list.begin();
728 iter != list.end();
729 ++iter) {
730 if (iter->IsDirectory() && iter->IsDelete()) {
731 containsDirectoryDeletion = true;
732 break;
733 }
734 }
735
721 const base::FilePath& path = it->first; 736 const base::FilePath& path = it->first;
722 map[path.DirName()].Update(path, it->second); 737 map[path.DirName()].Update(path, it->second);
738
739 // Since if the change is a deletion of a directory, it may have deleted a
mtomasz 2014/10/17 05:26:56 Does this mean, that if we have directories /a and
mtomasz 2014/10/17 05:26:56 Since if -> Since (or) If
yawano 2014/10/20 00:49:48 Yes. When we are watching /a and /a/b, and /a is d
yawano 2014/10/20 00:49:48 Done.
740 // watched directory, we need to notify it.
741 // e.g. When /a is deleted, it means /a/b is also deleted.
742 if (containsDirectoryDeletion) {
743 // Expaned the deleted directory path with watched paths.
mtomasz 2014/10/17 05:26:56 typo: Expand
yawano 2014/10/20 00:49:48 Done.
744 for (WatcherMap::const_iterator i = file_watchers_.lower_bound(path);
745 i != file_watchers_.end() &&
746 i->first.value().find(path.value()) == 0;
747 ++i) {
748 // Set an empty change list.
749 drive::FileChange::ChangeList change_list;
750 map[i->first].Update(i->first, change_list);
751 }
752 }
723 } 753 }
724 754
725 for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) { 755 for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) {
726 HandleFileWatchNotification(&(it->second), it->first, false); 756 HandleFileWatchNotification(&(it->second), it->first, false);
727 } 757 }
728 } 758 }
729 759
730 void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type, 760 void EventRouter::OnDriveSyncError(drive::file_system::DriveSyncErrorType type,
731 const base::FilePath& drive_path) { 761 const base::FilePath& drive_path) {
732 file_manager_private::DriveSyncErrorEvent event; 762 file_manager_private::DriveSyncErrorEvent event;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 list, 814 list,
785 got_error, 815 got_error,
786 iter->second->GetExtensionIds()); 816 iter->second->GetExtensionIds());
787 } 817 }
788 818
789 void EventRouter::DispatchDirectoryChangeEvent( 819 void EventRouter::DispatchDirectoryChangeEvent(
790 const base::FilePath& virtual_path, 820 const base::FilePath& virtual_path,
791 const drive::FileChange* list, 821 const drive::FileChange* list,
792 bool got_error, 822 bool got_error,
793 const std::vector<std::string>& extension_ids) { 823 const std::vector<std::string>& extension_ids) {
824 dispatch_directory_change_event_impl_.Run(virtual_path,
825 list, got_error, extension_ids);
826 }
827
828 void EventRouter::DispatchDirectoryChangeEventImpl(
829 const base::FilePath& virtual_path,
830 const drive::FileChange* list,
831 bool got_error,
832 const std::vector<std::string>& extension_ids) {
794 if (!profile_) { 833 if (!profile_) {
795 NOTREACHED(); 834 NOTREACHED();
796 return; 835 return;
797 } 836 }
798 linked_ptr<drive::FileChange> changes; 837 linked_ptr<drive::FileChange> changes;
799 if (list) 838 if (list)
800 changes.reset(new drive::FileChange(*list)); // Copy 839 changes.reset(new drive::FileChange(*list)); // Copy
801 840
802 for (size_t i = 0; i < extension_ids.size(); ++i) { 841 for (size_t i = 0; i < extension_ids.size(); ++i) {
803 std::string* extension_id = new std::string(extension_ids[i]); 842 std::string* extension_id = new std::string(extension_ids[i]);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 void EventRouter::Observe(int type, 999 void EventRouter::Observe(int type,
961 const content::NotificationSource& source, 1000 const content::NotificationSource& source,
962 const content::NotificationDetails& details) { 1001 const content::NotificationDetails& details) {
963 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { 1002 if (type == chrome::NOTIFICATION_PROFILE_ADDED) {
964 Profile* const added_profile = content::Source<Profile>(source).ptr(); 1003 Profile* const added_profile = content::Source<Profile>(source).ptr();
965 if (!added_profile->IsOffTheRecord()) 1004 if (!added_profile->IsOffTheRecord())
966 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); 1005 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_);
967 } 1006 }
968 } 1007 }
969 1008
1009 void EventRouter::SetDispatchDirectoryChangeEventImplForTesting(
1010 const DispatchDirectoryChangeEventImplCallback& callback) {
1011 dispatch_directory_change_event_impl_ = callback;
1012 }
1013
970 } // namespace file_manager 1014 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698