| 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..e637899be13b57a2337b8ef02d107fc62d1f54df 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();
|
| @@ -712,14 +715,41 @@ void EventRouter::OnDirectoryChanged(const base::FilePath& drive_path) {
|
|
|
| void EventRouter::OnFileChanged(const drive::FileChange& changed_files) {
|
| 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;
|
| + 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);
|
| + 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 +821,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 +1006,9 @@ void EventRouter::Observe(int type,
|
| }
|
| }
|
|
|
| +void EventRouter::SetDispatchDirectoryChangeEventImplForTesting(
|
| + const DispatchDirectoryChangeEventImplCallback& callback) {
|
| + dispatch_directory_change_event_impl_ = callback;
|
| +}
|
| +
|
| } // namespace file_manager
|
|
|