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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 676403003: Revert of Changed api to notify when watched directory is deleted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2371c21c394d06e5f06ccd48385a5a8c2d2b220c..9e0604cc8e26b0848f575559e66294274d4872c0 100644
--- a/chrome/browser/chromeos/extensions/file_manager/event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/event_router.cc
@@ -386,9 +386,6 @@
: 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();
@@ -714,63 +711,19 @@
}
void EventRouter::OnFileChanged(const drive::FileChange& changed_files) {
- // In this method, we convert changed_files to a map which can be handled by
- // HandleFileWatchNotification.
- //
- // e.g.
- // /a/b DIRECTORY:DELETE
- //
- // map[/a] = /a/b DIRECTORY:DELETE
- // map[/a/b] = /a/b DIRECTORY:DELETE
- //
- // We used the key of map to match the watched directories of file watchers.
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 (auto const& file_change_key_value : changed_file_map) {
- // Check whether the FileChangeList contains directory deletion.
- bool contains_directory_deletion = false;
- const FileChangeList list = file_change_key_value.second.list();
- for (drive::FileChange::Change const& change : list) {
- if (change.IsDirectory() && change.IsDelete()) {
- contains_directory_deletion = true;
- break;
- }
- }
-
- const base::FilePath& path = file_change_key_value.first;
- map[path.DirName()].Update(path, file_change_key_value.second);
-
- // For deletion of a directory, onFileChanged gets different changed_files.
- // We solve the difference here.
- //
- // /a/b is watched, and /a is deleted from Drive (e.g. from Web).
- // 1. /a/b DELETE:DIRECTORY
- // 2. /a DELETE:DIRECTORY
- //
- // /a/b is watched, and /a is deleted from Files.app.
- // 1. /a DELETE:DIRECTORY
- if (contains_directory_deletion) {
- // Expand the deleted directory path with watched paths.
- for (WatcherMap::const_iterator file_watchers_it =
- file_watchers_.lower_bound(path);
- file_watchers_it != file_watchers_.end(); ++file_watchers_it) {
- if (path == file_watchers_it->first ||
- path.IsParent(file_watchers_it->first)) {
- map[file_watchers_it->first].Update(
- file_watchers_it->first,
- drive::FileChange::FileType::FILE_TYPE_DIRECTORY,
- drive::FileChange::ChangeType::DELETE);
- }
- }
- }
- }
-
- for (auto const& file_change_key_value : map) {
- HandleFileWatchNotification(&(file_change_key_value.second),
- file_change_key_value.first, false);
+ for (drive::FileChange::Map::const_iterator it = changed_file_map.begin();
+ it != changed_file_map.end();
+ it++) {
+ const base::FilePath& path = it->first;
+ map[path.DirName()].Update(path, it->second);
+ }
+
+ for (FileChangeMap::const_iterator it = map.begin(); it != map.end(); it++) {
+ HandleFileWatchNotification(&(it->second), it->first, false);
}
}
@@ -838,15 +791,6 @@
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;
@@ -1023,9 +967,4 @@
}
}
-void EventRouter::SetDispatchDirectoryChangeEventImplForTesting(
- const DispatchDirectoryChangeEventImplCallback& callback) {
- dispatch_directory_change_event_impl_ = callback;
-}
-
} // namespace file_manager

Powered by Google App Engine
This is Rietveld 408576698