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..410147b1ec56a2ca998a6ec73d4a314b9c9b0753 100644 |
| --- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| +++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc |
| @@ -386,6 +386,9 @@ EventRouter::EventRouter(Profile* profile) |
| : pref_change_registrar_(new PrefChangeRegistrar), |
| profile_(profile), |
| device_event_router_(new DeviceEventRouterImpl(profile)), |
| + dispatch_directory_change_event_impl_( |
| + base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl, |
| + base::Unretained(this))), |
| weak_factory_(this) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| ObserveEvents(); |
| @@ -711,15 +714,51 @@ void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) { |
| } |
| void EventRouter::OnFileChanged(const drive::FileChange& changed_files) { |
| + // For deletion of a directory, onFileChanged gets different change_files. |
|
mtomasz
2014/10/20 07:03:13
typo: changed_files
yawano
2014/10/20 07:58:30
Done.
|
| + // We solve the difference in this method. |
| + // |
| + // /a/b is watched, and delete /a from Drive(e.g. from Web). |
|
mtomasz
2014/10/20 07:03:13
nit: Drive( -> Drive (
mtomasz
2014/10/20 07:03:13
nit: and delete /a -> and /a is deleted
yawano
2014/10/20 07:58:29
Done.
yawano
2014/10/20 07:58:30
Done.
|
| + // 1. /a/b DELETE:DIRECTORY |
| + // 2. /a DELETE:DIRECTORY |
| + // |
| + // /a/b is watched, and delete /a from Files.app. |
| + // 1. /a DELETE:DIRECTORY |
| typedef std::map<base::FilePath, drive::FileChange> FileChangeMap; |
| + typedef drive::FileChange::ChangeList::List FileChangeList; |
| FileChangeMap map; |
| const drive::FileChange::Map& changed_file_map = changed_files.map(); |
| for (drive::FileChange::Map::const_iterator it = changed_file_map.begin(); |
| it != changed_file_map.end(); |
| it++) { |
| + bool containsDirectoryDeletion = false; |
|
mtomasz
2014/10/20 07:03:13
nit: please_use_underscores_in_variable_names
yawano
2014/10/20 07:58:30
Done.
|
| + const FileChangeList list = it->second.list(); |
| + for (FileChangeList::const_iterator iter = list.begin(); |
| + iter != list.end(); |
| + ++iter) { |
| + if (iter->IsDirectory() && iter->IsDelete()) { |
| + containsDirectoryDeletion = true; |
| + break; |
| + } |
| + } |
| + |
| const base::FilePath& path = it->first; |
| map[path.DirName()].Update(path, it->second); |
| + |
| + // If the change is a deletion of a directory, it may have deleted a |
| + // watched directory. |
| + // e.g. When /a is deleted, it means /a/b is also deleted. |
| + if (containsDirectoryDeletion) { |
| + // Expand the deleted directory path with watched paths. |
| + for (WatcherMap::const_iterator i = file_watchers_.lower_bound(path); |
|
mtomasz
2014/10/20 07:03:13
nit: We have it, iter and i. Hard to say which one
yawano
2014/10/20 07:58:29
Done.
|
| + i != file_watchers_.end() && |
| + i->first.value().find(path.value()) == 0; |
| + ++i) { |
| + // Set an empty change list. |
| + drive::FileChange::ChangeList change_list; |
| + map[i->first].Update(i->first, change_list); |
| + } |
| + } |
| } |
| for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) { |
| @@ -791,6 +830,15 @@ void EventRouter::DispatchDirectoryChangeEvent( |
| const drive::FileChange* list, |
| bool got_error, |
| const std::vector<std::string>& extension_ids) { |
| + dispatch_directory_change_event_impl_.Run(virtual_path, |
| + 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 +1015,9 @@ void EventRouter::Observe(int type, |
| } |
| } |
| +void EventRouter::SetDispatchDirectoryChangeEventImplForTesting( |
| + const DispatchDirectoryChangeEventImplCallback& callback) { |
| + dispatch_directory_change_event_impl_ = callback; |
| +} |
| + |
| } // namespace file_manager |