Chromium Code Reviews| Index: chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| diff --git a/chrome/browser/chromeos/extensions/file_manager/event_router.cc b/chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| index 9e0604cc8e26b0848f575559e66294274d4872c0..03ee7b456c41009936d4c90ac1ba31556f7811e6 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| @@ -386,7 +386,10 @@ EventRouter::EventRouter(Profile* profile) |
| : pref_change_registrar_(new PrefChangeRegistrar), |
| profile_(profile), |
| device_event_router_(new DeviceEventRouterImpl(profile)), |
| - weak_factory_(this) { |
| + weak_factory_(this), |
| + dispatch_dir_change_eve_impl_( |
|
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:22
Done.
|
| + base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl, |
| + base::Unretained(this))) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| ObserveEvents(); |
| } |
| @@ -767,11 +770,6 @@ void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, |
| bool got_error) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - WatcherMap::const_iterator iter = file_watchers_.find(local_path); |
| - if (iter == file_watchers_.end()) { |
| - return; |
| - } |
| - |
| if (list && list->size() > kDirectoryChangeEventMaxDetailInfoSize) { |
| // Removes the detailed information, if the list size is more than |
| // kDirectoryChangeEventMaxDetailInfoSize, since passing large list |
| @@ -780,10 +778,25 @@ void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, |
| list = NULL; |
| } |
| - DispatchDirectoryChangeEvent(iter->second->virtual_path(), |
| - list, |
| - got_error, |
| - iter->second->GetExtensionIds()); |
| + // Since a change in the parent directory of a watching directory causes |
|
mtomasz
2014/10/16 04:02:02
What if we watch for /a/b only, and /a/b is remove
yawano
2014/10/17 03:57:21
While we changed the point to fix in the latest Cl
|
| + // deletion of the watching directory, we check whether the watching directory |
| + // exists and notify if it is deleted. |
| + for (WatcherMap::const_iterator iter = file_watchers_.lower_bound(local_path); |
| + iter != file_watchers_.end() && |
| + iter->first.value().find(local_path.value()) == 0; |
| + ++iter) { |
| + // If a change has happend in the parent directory, checks the descendant |
| + // directory(watching directory) still exists. |
| + if (local_path.value().size() < iter->first.value().size() && |
| + base::PathExists(iter->first)) { |
|
mtomasz
2014/10/16 04:02:02
PathExists can't be called on UI thread. You have
yawano
2014/10/17 03:57:21
Acknowledged.
|
| + continue; |
| + } |
| + |
| + DispatchDirectoryChangeEvent(iter->second->virtual_path(), |
| + list, |
| + got_error, |
| + iter->second->GetExtensionIds()); |
| + } |
| } |
| void EventRouter::DispatchDirectoryChangeEvent( |
| @@ -791,6 +804,15 @@ void EventRouter::DispatchDirectoryChangeEvent( |
| const drive::FileChange* list, |
| bool got_error, |
| const std::vector<std::string>& extension_ids) { |
| + dispatch_dir_change_eve_impl_.Run(virtual_path, |
|
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:21
Done.
|
| + list, got_error, extension_ids); |
| +} |
| + |
| +void EventRouter::DispatchDirectoryChangeEventImpl( |
| + const base::FilePath& virtual_path, |
| + const drive::FileChange* list, |
| + bool got_error, |
| + const std::vector<std::string>& extension_ids) { |
| if (!profile_) { |
| NOTREACHED(); |
| return; |
| @@ -967,4 +989,9 @@ void EventRouter::Observe(int type, |
| } |
| } |
| +void EventRouter::SetDispatchDirChangeEveImplForTesting( |
| + const DispatchDirChangeEveImplCallback& callback) { |
| + dispatch_dir_change_eve_impl_ = callback; |
|
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:22
Done.
|
| +} |
| + |
| } // namespace file_manager |