Commit 0dcdc38c authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Filter DriveFS file change notifications to just watched directories.

Currently, all DriveFS change notifications are forwarded to the UI.
Some parts do their own checks for matching the expected directory, but
others do not; one part that does not is DirectoryTree, which triggers a
rescan of any changed directories. Filter to just directories with a
registered watcher like the old Drive client does.

Bug: 943886
Change-Id: If106ef054e5bfbdd16697e41d74b176996c6750f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529896Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642357}
parent b1156dcf
...@@ -160,7 +160,8 @@ void DriveFsEventRouter::OnFilesChanged( ...@@ -160,7 +160,8 @@ void DriveFsEventRouter::OnFilesChanged(
CHANGE_TYPE_ADD_OR_UPDATE); CHANGE_TYPE_ADD_OR_UPDATE);
} }
for (auto& event : events) { for (auto& event : events) {
DispatchOnDirectoryChangedEventToExtension(extension_id, event.second); DispatchOnDirectoryChangedEventToExtension(extension_id, event.first,
event.second);
} }
} }
} }
...@@ -204,7 +205,11 @@ void DriveFsEventRouter::DispatchOnFileTransfersUpdatedEventToExtension( ...@@ -204,7 +205,11 @@ void DriveFsEventRouter::DispatchOnFileTransfersUpdatedEventToExtension(
void DriveFsEventRouter::DispatchOnDirectoryChangedEventToExtension( void DriveFsEventRouter::DispatchOnDirectoryChangedEventToExtension(
const std::string& extension_id, const std::string& extension_id,
const base::FilePath& directory,
const extensions::api::file_manager_private::FileWatchEvent& event) { const extensions::api::file_manager_private::FileWatchEvent& event) {
if (!IsPathWatched(directory)) {
return;
}
DispatchEventToExtension( DispatchEventToExtension(
extension_id, extension_id,
extensions::events::FILE_MANAGER_PRIVATE_ON_DIRECTORY_CHANGED, extensions::events::FILE_MANAGER_PRIVATE_ON_DIRECTORY_CHANGED,
......
...@@ -59,12 +59,15 @@ class DriveFsEventRouter : public drivefs::DriveFsHostObserver { ...@@ -59,12 +59,15 @@ class DriveFsEventRouter : public drivefs::DriveFsHostObserver {
virtual std::string GetDriveFileSystemName() = 0; virtual std::string GetDriveFileSystemName() = 0;
virtual bool IsPathWatched(const base::FilePath& path) = 0;
void DispatchOnFileTransfersUpdatedEventToExtension( void DispatchOnFileTransfersUpdatedEventToExtension(
const std::string& extension_id, const std::string& extension_id,
const extensions::api::file_manager_private::FileTransferStatus& status); const extensions::api::file_manager_private::FileTransferStatus& status);
void DispatchOnDirectoryChangedEventToExtension( void DispatchOnDirectoryChangedEventToExtension(
const std::string& extension_id, const std::string& extension_id,
const base::FilePath& directory,
const extensions::api::file_manager_private::FileWatchEvent& event); const extensions::api::file_manager_private::FileWatchEvent& event);
// Helper method for dispatching an event to an extension. // Helper method for dispatching an event to an extension.
......
...@@ -68,7 +68,9 @@ testing::Matcher<const base::ListValue&> MatchFileWatchEvent( ...@@ -68,7 +68,9 @@ testing::Matcher<const base::ListValue&> MatchFileWatchEvent(
class TestDriveFsEventRouter : public DriveFsEventRouter { class TestDriveFsEventRouter : public DriveFsEventRouter {
public: public:
TestDriveFsEventRouter() = default; TestDriveFsEventRouter() {
ON_CALL(*this, IsPathWatched).WillByDefault(testing::Return(true));
}
void DispatchEventToExtension( void DispatchEventToExtension(
const std::string& extension_id, const std::string& extension_id,
...@@ -82,6 +84,7 @@ class TestDriveFsEventRouter : public DriveFsEventRouter { ...@@ -82,6 +84,7 @@ class TestDriveFsEventRouter : public DriveFsEventRouter {
void(const std::string& extension_id, void(const std::string& extension_id,
const std::string& name, const std::string& name,
const base::ListValue& event)); const base::ListValue& event));
MOCK_METHOD1(IsPathWatched, bool(const base::FilePath&));
GURL ConvertDrivePathToFileSystemUrl( GURL ConvertDrivePathToFileSystemUrl(
const base::FilePath& file_path, const base::FilePath& file_path,
...@@ -529,6 +532,10 @@ TEST_F(DriveFsEventRouterTest, OnFilesChanged_Basic) { ...@@ -529,6 +532,10 @@ TEST_F(DriveFsEventRouterTest, OnFilesChanged_Basic) {
file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE); file_manager_private::CHANGE_TYPE_ADD_OR_UPDATE);
} }
EXPECT_CALL(mock(), IsPathWatched(base::FilePath("/root")))
.WillOnce(testing::Return(true));
EXPECT_CALL(mock(), IsPathWatched(base::FilePath("/other")))
.WillOnce(testing::Return(false));
EXPECT_CALL(mock(), EXPECT_CALL(mock(),
DispatchEventToExtensionImpl( DispatchEventToExtensionImpl(
"ext", file_manager_private::OnDirectoryChanged::kEventName, "ext", file_manager_private::OnDirectoryChanged::kEventName,
...@@ -541,6 +548,8 @@ TEST_F(DriveFsEventRouterTest, OnFilesChanged_Basic) { ...@@ -541,6 +548,8 @@ TEST_F(DriveFsEventRouterTest, OnFilesChanged_Basic) {
drivefs::mojom::FileChange::Type::kCreate); drivefs::mojom::FileChange::Type::kCreate);
changes.emplace_back(base::FilePath("/root/c"), changes.emplace_back(base::FilePath("/root/c"),
drivefs::mojom::FileChange::Type::kModify); drivefs::mojom::FileChange::Type::kModify);
changes.emplace_back(base::FilePath("/other/a"),
drivefs::mojom::FileChange::Type::kModify);
observer().OnFilesChanged(changes); observer().OnFilesChanged(changes);
} }
......
...@@ -391,7 +391,11 @@ class JobEventRouterImpl : public JobEventRouter { ...@@ -391,7 +391,11 @@ class JobEventRouterImpl : public JobEventRouter {
class DriveFsEventRouterImpl : public DriveFsEventRouter { class DriveFsEventRouterImpl : public DriveFsEventRouter {
public: public:
explicit DriveFsEventRouterImpl(Profile* profile) : profile_(profile) {} DriveFsEventRouterImpl(
Profile* profile,
const std::map<base::FilePath, std::unique_ptr<FileWatcher>>*
file_watchers)
: profile_(profile), file_watchers_(file_watchers) {}
private: private:
std::set<std::string> GetEventListenerExtensionIds( std::set<std::string> GetEventListenerExtensionIds(
...@@ -420,6 +424,14 @@ class DriveFsEventRouterImpl : public DriveFsEventRouter { ...@@ -420,6 +424,14 @@ class DriveFsEventRouterImpl : public DriveFsEventRouter {
.value(); .value();
} }
bool IsPathWatched(const base::FilePath& path) override {
base::FilePath absolute_path =
DriveIntegrationServiceFactory::FindForProfile(profile_)
->GetMountPointPath();
return base::FilePath("/").AppendRelativePath(path, &absolute_path) &&
base::ContainsKey(*file_watchers_, absolute_path);
}
void DispatchEventToExtension( void DispatchEventToExtension(
const std::string& extension_id, const std::string& extension_id,
extensions::events::HistogramValue histogram_value, extensions::events::HistogramValue histogram_value,
...@@ -431,6 +443,8 @@ class DriveFsEventRouterImpl : public DriveFsEventRouter { ...@@ -431,6 +443,8 @@ class DriveFsEventRouterImpl : public DriveFsEventRouter {
} }
Profile* const profile_; Profile* const profile_;
const std::map<base::FilePath, std::unique_ptr<FileWatcher>>* const
file_watchers_;
DISALLOW_COPY_AND_ASSIGN(DriveFsEventRouterImpl); DISALLOW_COPY_AND_ASSIGN(DriveFsEventRouterImpl);
}; };
...@@ -442,7 +456,8 @@ EventRouter::EventRouter(Profile* profile) ...@@ -442,7 +456,8 @@ EventRouter::EventRouter(Profile* profile)
profile_(profile), profile_(profile),
device_event_router_(std::make_unique<DeviceEventRouterImpl>(profile)), device_event_router_(std::make_unique<DeviceEventRouterImpl>(profile)),
job_event_router_(std::make_unique<JobEventRouterImpl>(profile)), job_event_router_(std::make_unique<JobEventRouterImpl>(profile)),
drivefs_event_router_(std::make_unique<DriveFsEventRouterImpl>(profile)), drivefs_event_router_(
std::make_unique<DriveFsEventRouterImpl>(profile, &file_watchers_)),
dispatch_directory_change_event_impl_( dispatch_directory_change_event_impl_(
base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl, base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl,
base::Unretained(this))), base::Unretained(this))),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment