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

Unified 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 side-by-side diff with in-line comments
Download patch
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..a63000431522aeba8d4a3695ca767bd1f1bc5eea 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_directory_change_event_impl_(
+ base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl,
+ base::Unretained(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;
mtomasz 2014/10/17 05:26:56 nit: Please mark const what can be const.
yawano 2014/10/20 00:49:48 Done.
+ 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);
+
+ // 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.
+ // watched directory, we need to notify it.
+ // e.g. When /a is deleted, it means /a/b is also deleted.
+ if (containsDirectoryDeletion) {
+ // 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.
+ 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

Powered by Google App Engine
This is Rietveld 408576698