Commit 39aaa52b authored by mtomasz's avatar mtomasz Committed by Commit bot

[fsp] Rename ObserveEntry with AddWatcher.

Since we may have more than one watcher, the previous naming didn't make sense.
This patch changes all naming related to observing entries into creating
watchers.

TEST=Refactoring only. All current tests should pass.
BUG=261491

Review URL: https://codereview.chromium.org/674413002

Cr-Commit-Position: refs/heads/master@{#301596}
parent 3a3c88a6
...@@ -321,10 +321,9 @@ ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile( ...@@ -321,10 +321,9 @@ ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::WriteFile(
return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
} }
ProvidedFileSystemInterface::AbortCallback ProvidedFileSystemInterface::AbortCallback FakeProvidedFileSystem::AddWatcher(
FakeProvidedFileSystem::ObserveDirectory(
const GURL& origin, const GURL& origin,
const base::FilePath& directory_path, const base::FilePath& entry_watcher,
bool recursive, bool recursive,
bool persistent, bool persistent,
const storage::AsyncFileUtil::StatusCallback& callback) { const storage::AsyncFileUtil::StatusCallback& callback) {
...@@ -332,7 +331,7 @@ FakeProvidedFileSystem::ObserveDirectory( ...@@ -332,7 +331,7 @@ FakeProvidedFileSystem::ObserveDirectory(
return PostAbortableTask(base::Bind(callback, base::File::FILE_OK)); return PostAbortableTask(base::Bind(callback, base::File::FILE_OK));
} }
void FakeProvidedFileSystem::UnobserveEntry( void FakeProvidedFileSystem::RemoveWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& entry_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
...@@ -351,8 +350,8 @@ RequestManager* FakeProvidedFileSystem::GetRequestManager() { ...@@ -351,8 +350,8 @@ RequestManager* FakeProvidedFileSystem::GetRequestManager() {
return NULL; return NULL;
} }
ObservedEntries* FakeProvidedFileSystem::GetObservedEntries() { Watchers* FakeProvidedFileSystem::GetWatchers() {
return &observed_entries_; return &watchers_;
} }
void FakeProvidedFileSystem::AddObserver(ProvidedFileSystemObserver* observer) { void FakeProvidedFileSystem::AddObserver(ProvidedFileSystemObserver* observer) {
...@@ -367,7 +366,7 @@ void FakeProvidedFileSystem::RemoveObserver( ...@@ -367,7 +366,7 @@ void FakeProvidedFileSystem::RemoveObserver(
} }
bool FakeProvidedFileSystem::Notify( bool FakeProvidedFileSystem::Notify(
const base::FilePath& observed_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
scoped_ptr<ProvidedFileSystemObserver::Changes> changes, scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
#include "chrome/browser/chromeos/file_system_provider/watcher.h"
#include "url/gurl.h" #include "url/gurl.h"
class Profile; class Profile;
...@@ -126,23 +126,23 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -126,23 +126,23 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
int64 offset, int64 offset,
int length, int length,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual AbortCallback ObserveDirectory( virtual AbortCallback AddWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& directory_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
bool persistent, bool persistent,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual void UnobserveEntry( virtual void RemoveWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& entry_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override;
virtual RequestManager* GetRequestManager() override; virtual RequestManager* GetRequestManager() override;
virtual ObservedEntries* GetObservedEntries() override; virtual Watchers* GetWatchers() override;
virtual void AddObserver(ProvidedFileSystemObserver* observer) override; virtual void AddObserver(ProvidedFileSystemObserver* observer) override;
virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override; virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override;
virtual bool Notify(const base::FilePath& observed_path, virtual bool Notify(const base::FilePath& entry_path,
bool recursive, bool recursive,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
scoped_ptr<ProvidedFileSystemObserver::Changes> changes, scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
...@@ -180,7 +180,7 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -180,7 +180,7 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
int last_file_handle_; int last_file_handle_;
base::CancelableTaskTracker tracker_; base::CancelableTaskTracker tracker_;
ObserverList<ProvidedFileSystemObserver> observers_; ObserverList<ProvidedFileSystemObserver> observers_;
ObservedEntries observed_entries_; Watchers watchers_;
base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_; base::WeakPtrFactory<FakeProvidedFileSystem> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem); DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/file_system_provider/operations/observe_directory.h" #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h"
#include <string> #include <string>
...@@ -13,46 +13,45 @@ namespace chromeos { ...@@ -13,46 +13,45 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace operations { namespace operations {
ObserveDirectory::ObserveDirectory( AddWatcher::AddWatcher(extensions::EventRouter* event_router,
extensions::EventRouter* event_router, const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const base::FilePath& entry_path,
const base::FilePath& directory_path, bool recursive,
bool recursive, const storage::AsyncFileUtil::StatusCallback& callback)
const storage::AsyncFileUtil::StatusCallback& callback)
: Operation(event_router, file_system_info), : Operation(event_router, file_system_info),
directory_path_(directory_path), entry_path_(entry_path),
recursive_(recursive), recursive_(recursive),
callback_(callback) { callback_(callback) {
} }
ObserveDirectory::~ObserveDirectory() { AddWatcher::~AddWatcher() {
} }
bool ObserveDirectory::Execute(int request_id) { bool AddWatcher::Execute(int request_id) {
using extensions::api::file_system_provider::ObserveDirectoryRequestedOptions; using extensions::api::file_system_provider::AddWatcherRequestedOptions;
ObserveDirectoryRequestedOptions options; AddWatcherRequestedOptions options;
options.file_system_id = file_system_info_.file_system_id(); options.file_system_id = file_system_info_.file_system_id();
options.request_id = request_id; options.request_id = request_id;
options.directory_path = directory_path_.AsUTF8Unsafe(); options.entry_path = entry_path_.AsUTF8Unsafe();
options.recursive = recursive_; options.recursive = recursive_;
return SendEvent(request_id, return SendEvent(
extensions::api::file_system_provider:: request_id,
OnObserveDirectoryRequested::kEventName, extensions::api::file_system_provider::OnAddWatcherRequested::kEventName,
extensions::api::file_system_provider:: extensions::api::file_system_provider::OnAddWatcherRequested::Create(
OnObserveDirectoryRequested::Create(options)); options));
} }
void ObserveDirectory::OnSuccess(int /* request_id */, void AddWatcher::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> /* result */, scoped_ptr<RequestValue> /* result */,
bool has_more) { bool has_more) {
callback_.Run(base::File::FILE_OK); callback_.Run(base::File::FILE_OK);
} }
void ObserveDirectory::OnError(int /* request_id */, void AddWatcher::OnError(int /* request_id */,
scoped_ptr<RequestValue> /* result */, scoped_ptr<RequestValue> /* result */,
base::File::Error error) { base::File::Error error) {
callback_.Run(error); callback_.Run(error);
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OBSERVE_DIRECTORY_H_ #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_ADD_WATCHER_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OBSERVE_DIRECTORY_H_ #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_ADD_WATCHER_H_
#include "base/files/file.h" #include "base/files/file.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -25,16 +25,17 @@ namespace chromeos { ...@@ -25,16 +25,17 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace operations { namespace operations {
// Observes a directory. If |recursive| is true, than also observes all of the // Adds a watcher. If |recursive| is true, than also watches for all of the
// child entries in within, recursively. // child entries in within, recursively. Recursive must not be set to true for
class ObserveDirectory : public Operation { // files.
class AddWatcher : public Operation {
public: public:
ObserveDirectory(extensions::EventRouter* event_router, AddWatcher(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& directory_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
const storage::AsyncFileUtil::StatusCallback& callback); const storage::AsyncFileUtil::StatusCallback& callback);
virtual ~ObserveDirectory(); virtual ~AddWatcher();
// Operation overrides. // Operation overrides.
virtual bool Execute(int request_id) override; virtual bool Execute(int request_id) override;
...@@ -46,15 +47,15 @@ class ObserveDirectory : public Operation { ...@@ -46,15 +47,15 @@ class ObserveDirectory : public Operation {
base::File::Error error) override; base::File::Error error) override;
private: private:
const base::FilePath directory_path_; const base::FilePath entry_path_;
const bool recursive_; const bool recursive_;
const storage::AsyncFileUtil::StatusCallback callback_; const storage::AsyncFileUtil::StatusCallback callback_;
DISALLOW_COPY_AND_ASSIGN(ObserveDirectory); DISALLOW_COPY_AND_ASSIGN(AddWatcher);
}; };
} // namespace operations } // namespace operations
} // namespace file_system_provider } // namespace file_system_provider
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OBSERVE_DIRECTORY_H_ #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_ADD_WATCHER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/file_system_provider/operations/observe_directory.h" #include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h"
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -27,14 +27,14 @@ namespace { ...@@ -27,14 +27,14 @@ namespace {
const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
const char kFileSystemId[] = "testing-file-system"; const char kFileSystemId[] = "testing-file-system";
const int kRequestId = 2; const int kRequestId = 2;
const base::FilePath::CharType kDirectoryPath[] = "/kitty/and/puppy/happy"; const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
} // namespace } // namespace
class FileSystemProviderOperationsObserveDirectoryTest : public testing::Test { class FileSystemProviderOperationsAddWatcherTest : public testing::Test {
protected: protected:
FileSystemProviderOperationsObserveDirectoryTest() {} FileSystemProviderOperationsAddWatcherTest() {}
virtual ~FileSystemProviderOperationsObserveDirectoryTest() {} virtual ~FileSystemProviderOperationsAddWatcherTest() {}
virtual void SetUp() override { virtual void SetUp() override {
file_system_info_ = ProvidedFileSystemInfo( file_system_info_ = ProvidedFileSystemInfo(
...@@ -46,103 +46,99 @@ class FileSystemProviderOperationsObserveDirectoryTest : public testing::Test { ...@@ -46,103 +46,99 @@ class FileSystemProviderOperationsObserveDirectoryTest : public testing::Test {
ProvidedFileSystemInfo file_system_info_; ProvidedFileSystemInfo file_system_info_;
}; };
TEST_F(FileSystemProviderOperationsObserveDirectoryTest, Execute) { TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute) {
using extensions::api::file_system_provider::ObserveDirectoryRequestedOptions; using extensions::api::file_system_provider::AddWatcherRequestedOptions;
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
ObserveDirectory observe_directory( AddWatcher add_watcher(NULL,
NULL, file_system_info_,
file_system_info_, base::FilePath::FromUTF8Unsafe(kEntryPath),
base::FilePath::FromUTF8Unsafe(kDirectoryPath), true /* recursive */,
true /* recursive */, base::Bind(&util::LogStatusCallback, &callback_log));
base::Bind(&util::LogStatusCallback, &callback_log)); add_watcher.SetDispatchEventImplForTesting(
observe_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(observe_directory.Execute(kRequestId)); EXPECT_TRUE(add_watcher.Execute(kRequestId));
ASSERT_EQ(1u, dispatcher.events().size()); ASSERT_EQ(1u, dispatcher.events().size());
extensions::Event* event = dispatcher.events()[0]; extensions::Event* event = dispatcher.events()[0];
EXPECT_EQ(extensions::api::file_system_provider::OnObserveDirectoryRequested:: EXPECT_EQ(
kEventName, extensions::api::file_system_provider::OnAddWatcherRequested::kEventName,
event->event_name); event->event_name);
base::ListValue* event_args = event->event_args.get(); base::ListValue* event_args = event->event_args.get();
ASSERT_EQ(1u, event_args->GetSize()); ASSERT_EQ(1u, event_args->GetSize());
const base::DictionaryValue* options_as_value = NULL; const base::DictionaryValue* options_as_value = NULL;
ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
ObserveDirectoryRequestedOptions options; AddWatcherRequestedOptions options;
ASSERT_TRUE( ASSERT_TRUE(
ObserveDirectoryRequestedOptions::Populate(*options_as_value, &options)); AddWatcherRequestedOptions::Populate(*options_as_value, &options));
EXPECT_EQ(kFileSystemId, options.file_system_id); EXPECT_EQ(kFileSystemId, options.file_system_id);
EXPECT_EQ(kRequestId, options.request_id); EXPECT_EQ(kRequestId, options.request_id);
EXPECT_EQ(kDirectoryPath, options.directory_path); EXPECT_EQ(kEntryPath, options.entry_path);
EXPECT_TRUE(options.recursive); EXPECT_TRUE(options.recursive);
} }
TEST_F(FileSystemProviderOperationsObserveDirectoryTest, Execute_NoListener) { TEST_F(FileSystemProviderOperationsAddWatcherTest, Execute_NoListener) {
util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
ObserveDirectory observe_directory( AddWatcher add_watcher(NULL,
NULL, file_system_info_,
file_system_info_, base::FilePath::FromUTF8Unsafe(kEntryPath),
base::FilePath::FromUTF8Unsafe(kDirectoryPath), true /* recursive */,
true /* recursive */, base::Bind(&util::LogStatusCallback, &callback_log));
base::Bind(&util::LogStatusCallback, &callback_log)); add_watcher.SetDispatchEventImplForTesting(
observe_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_FALSE(observe_directory.Execute(kRequestId)); EXPECT_FALSE(add_watcher.Execute(kRequestId));
} }
TEST_F(FileSystemProviderOperationsObserveDirectoryTest, OnSuccess) { TEST_F(FileSystemProviderOperationsAddWatcherTest, OnSuccess) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
ObserveDirectory observe_directory( AddWatcher add_watcher(NULL,
NULL, file_system_info_,
file_system_info_, base::FilePath::FromUTF8Unsafe(kEntryPath),
base::FilePath::FromUTF8Unsafe(kDirectoryPath), true /* recursive */,
true /* recursive */, base::Bind(&util::LogStatusCallback, &callback_log));
base::Bind(&util::LogStatusCallback, &callback_log)); add_watcher.SetDispatchEventImplForTesting(
observe_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(observe_directory.Execute(kRequestId)); EXPECT_TRUE(add_watcher.Execute(kRequestId));
observe_directory.OnSuccess(kRequestId, add_watcher.OnSuccess(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()), scoped_ptr<RequestValue>(new RequestValue()),
false /* has_more */); false /* has_more */);
ASSERT_EQ(1u, callback_log.size()); ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_OK, callback_log[0]); EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
} }
TEST_F(FileSystemProviderOperationsObserveDirectoryTest, OnError) { TEST_F(FileSystemProviderOperationsAddWatcherTest, OnError) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
ObserveDirectory observe_directory( AddWatcher add_watcher(NULL,
NULL, file_system_info_,
file_system_info_, base::FilePath::FromUTF8Unsafe(kEntryPath),
base::FilePath::FromUTF8Unsafe(kDirectoryPath), true /* recursive */,
true /* recursive */, base::Bind(&util::LogStatusCallback, &callback_log));
base::Bind(&util::LogStatusCallback, &callback_log)); add_watcher.SetDispatchEventImplForTesting(
observe_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(observe_directory.Execute(kRequestId)); EXPECT_TRUE(add_watcher.Execute(kRequestId));
observe_directory.OnError(kRequestId, add_watcher.OnError(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()), scoped_ptr<RequestValue>(new RequestValue()),
base::File::FILE_ERROR_TOO_MANY_OPENED); base::File::FILE_ERROR_TOO_MANY_OPENED);
ASSERT_EQ(1u, callback_log.size()); ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/file_system_provider/operations/unobserve_entry.h" #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher.h"
#include <string> #include <string>
...@@ -13,7 +13,7 @@ namespace chromeos { ...@@ -13,7 +13,7 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace operations { namespace operations {
UnobserveEntry::UnobserveEntry( RemoveWatcher::RemoveWatcher(
extensions::EventRouter* event_router, extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& entry_path, const base::FilePath& entry_path,
...@@ -25,13 +25,13 @@ UnobserveEntry::UnobserveEntry( ...@@ -25,13 +25,13 @@ UnobserveEntry::UnobserveEntry(
callback_(callback) { callback_(callback) {
} }
UnobserveEntry::~UnobserveEntry() { RemoveWatcher::~RemoveWatcher() {
} }
bool UnobserveEntry::Execute(int request_id) { bool RemoveWatcher::Execute(int request_id) {
using extensions::api::file_system_provider::UnobserveEntryRequestedOptions; using extensions::api::file_system_provider::RemoveWatcherRequestedOptions;
UnobserveEntryRequestedOptions options; RemoveWatcherRequestedOptions options;
options.file_system_id = file_system_info_.file_system_id(); options.file_system_id = file_system_info_.file_system_id();
options.request_id = request_id; options.request_id = request_id;
options.entry_path = entry_path_.AsUTF8Unsafe(); options.entry_path = entry_path_.AsUTF8Unsafe();
...@@ -39,21 +39,21 @@ bool UnobserveEntry::Execute(int request_id) { ...@@ -39,21 +39,21 @@ bool UnobserveEntry::Execute(int request_id) {
return SendEvent( return SendEvent(
request_id, request_id,
extensions::api::file_system_provider::OnUnobserveEntryRequested:: extensions::api::file_system_provider::OnRemoveWatcherRequested::
kEventName, kEventName,
extensions::api::file_system_provider::OnUnobserveEntryRequested::Create( extensions::api::file_system_provider::OnRemoveWatcherRequested::Create(
options)); options));
} }
void UnobserveEntry::OnSuccess(int /* request_id */, void RemoveWatcher::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> /* result */, scoped_ptr<RequestValue> /* result */,
bool has_more) { bool has_more) {
callback_.Run(base::File::FILE_OK); callback_.Run(base::File::FILE_OK);
} }
void UnobserveEntry::OnError(int /* request_id */, void RemoveWatcher::OnError(int /* request_id */,
scoped_ptr<RequestValue> /* result */, scoped_ptr<RequestValue> /* result */,
base::File::Error error) { base::File::Error error) {
callback_.Run(error); callback_.Run(error);
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_UNOBSERVE_ENTRY_H_ #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_REMOVE_WATCHER_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_UNOBSERVE_ENTRY_H_ #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_REMOVE_WATCHER_H_
#include "base/files/file.h" #include "base/files/file.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
...@@ -25,15 +25,15 @@ namespace chromeos { ...@@ -25,15 +25,15 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace operations { namespace operations {
// Unobserves an entry at |entry_path|. // Removes a watcher at |entry_path| with the |recursive| mode.
class UnobserveEntry : public Operation { class RemoveWatcher : public Operation {
public: public:
UnobserveEntry(extensions::EventRouter* event_router, RemoveWatcher(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& entry_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
const storage::AsyncFileUtil::StatusCallback& callback); const storage::AsyncFileUtil::StatusCallback& callback);
virtual ~UnobserveEntry(); virtual ~RemoveWatcher();
// Operation overrides. // Operation overrides.
virtual bool Execute(int request_id) override; virtual bool Execute(int request_id) override;
...@@ -49,11 +49,11 @@ class UnobserveEntry : public Operation { ...@@ -49,11 +49,11 @@ class UnobserveEntry : public Operation {
bool recursive_; bool recursive_;
const storage::AsyncFileUtil::StatusCallback callback_; const storage::AsyncFileUtil::StatusCallback callback_;
DISALLOW_COPY_AND_ASSIGN(UnobserveEntry); DISALLOW_COPY_AND_ASSIGN(RemoveWatcher);
}; };
} // namespace operations } // namespace operations
} // namespace file_system_provider } // namespace file_system_provider
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_UNOBSERVE_ENTRY_H_ #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_REMOVE_WATCHER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/file_system_provider/operations/unobserve_entry.h" #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher.h"
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -31,10 +31,10 @@ const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy"; ...@@ -31,10 +31,10 @@ const base::FilePath::CharType kEntryPath[] = "/kitty/and/puppy/happy";
} // namespace } // namespace
class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test { class FileSystemProviderOperationsRemoveWatcherTest : public testing::Test {
protected: protected:
FileSystemProviderOperationsUnobserveEntryTest() {} FileSystemProviderOperationsRemoveWatcherTest() {}
virtual ~FileSystemProviderOperationsUnobserveEntryTest() {} virtual ~FileSystemProviderOperationsRemoveWatcherTest() {}
virtual void SetUp() override { virtual void SetUp() override {
file_system_info_ = ProvidedFileSystemInfo( file_system_info_ = ProvidedFileSystemInfo(
...@@ -46,27 +46,27 @@ class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test { ...@@ -46,27 +46,27 @@ class FileSystemProviderOperationsUnobserveEntryTest : public testing::Test {
ProvidedFileSystemInfo file_system_info_; ProvidedFileSystemInfo file_system_info_;
}; };
TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) { TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute) {
using extensions::api::file_system_provider::UnobserveEntryRequestedOptions; using extensions::api::file_system_provider::RemoveWatcherRequestedOptions;
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
UnobserveEntry unobserve_entry( RemoveWatcher remove_watcher(
NULL, NULL,
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kEntryPath), base::FilePath::FromUTF8Unsafe(kEntryPath),
true /* recursive */, true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log)); base::Bind(&util::LogStatusCallback, &callback_log));
unobserve_entry.SetDispatchEventImplForTesting( remove_watcher.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); EXPECT_TRUE(remove_watcher.Execute(kRequestId));
ASSERT_EQ(1u, dispatcher.events().size()); ASSERT_EQ(1u, dispatcher.events().size());
extensions::Event* event = dispatcher.events()[0]; extensions::Event* event = dispatcher.events()[0];
EXPECT_EQ(extensions::api::file_system_provider::OnUnobserveEntryRequested:: EXPECT_EQ(extensions::api::file_system_provider::OnRemoveWatcherRequested::
kEventName, kEventName,
event->event_name); event->event_name);
base::ListValue* event_args = event->event_args.get(); base::ListValue* event_args = event->event_args.get();
...@@ -75,74 +75,74 @@ TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) { ...@@ -75,74 +75,74 @@ TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute) {
const base::DictionaryValue* options_as_value = NULL; const base::DictionaryValue* options_as_value = NULL;
ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value)); ASSERT_TRUE(event_args->GetDictionary(0, &options_as_value));
UnobserveEntryRequestedOptions options; RemoveWatcherRequestedOptions options;
ASSERT_TRUE( ASSERT_TRUE(
UnobserveEntryRequestedOptions::Populate(*options_as_value, &options)); RemoveWatcherRequestedOptions::Populate(*options_as_value, &options));
EXPECT_EQ(kFileSystemId, options.file_system_id); EXPECT_EQ(kFileSystemId, options.file_system_id);
EXPECT_EQ(kRequestId, options.request_id); EXPECT_EQ(kRequestId, options.request_id);
EXPECT_EQ(kEntryPath, options.entry_path); EXPECT_EQ(kEntryPath, options.entry_path);
EXPECT_TRUE(options.recursive); EXPECT_TRUE(options.recursive);
} }
TEST_F(FileSystemProviderOperationsUnobserveEntryTest, Execute_NoListener) { TEST_F(FileSystemProviderOperationsRemoveWatcherTest, Execute_NoListener) {
util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
UnobserveEntry unobserve_entry( RemoveWatcher remove_watcher(
NULL, NULL,
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kEntryPath), base::FilePath::FromUTF8Unsafe(kEntryPath),
true /* recursive */, true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log)); base::Bind(&util::LogStatusCallback, &callback_log));
unobserve_entry.SetDispatchEventImplForTesting( remove_watcher.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_FALSE(unobserve_entry.Execute(kRequestId)); EXPECT_FALSE(remove_watcher.Execute(kRequestId));
} }
TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnSuccess) { TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnSuccess) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
UnobserveEntry unobserve_entry( RemoveWatcher remove_watcher(
NULL, NULL,
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kEntryPath), base::FilePath::FromUTF8Unsafe(kEntryPath),
true /* recursive */, true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log)); base::Bind(&util::LogStatusCallback, &callback_log));
unobserve_entry.SetDispatchEventImplForTesting( remove_watcher.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); EXPECT_TRUE(remove_watcher.Execute(kRequestId));
unobserve_entry.OnSuccess(kRequestId, remove_watcher.OnSuccess(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()), scoped_ptr<RequestValue>(new RequestValue()),
false /* has_more */); false /* has_more */);
ASSERT_EQ(1u, callback_log.size()); ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_OK, callback_log[0]); EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
} }
TEST_F(FileSystemProviderOperationsUnobserveEntryTest, OnError) { TEST_F(FileSystemProviderOperationsRemoveWatcherTest, OnError) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log; util::StatusCallbackLog callback_log;
UnobserveEntry unobserve_entry( RemoveWatcher remove_watcher(
NULL, NULL,
file_system_info_, file_system_info_,
base::FilePath::FromUTF8Unsafe(kEntryPath), base::FilePath::FromUTF8Unsafe(kEntryPath),
true /* recursive */, true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log)); base::Bind(&util::LogStatusCallback, &callback_log));
unobserve_entry.SetDispatchEventImplForTesting( remove_watcher.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl, base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher))); base::Unretained(&dispatcher)));
EXPECT_TRUE(unobserve_entry.Execute(kRequestId)); EXPECT_TRUE(remove_watcher.Execute(kRequestId));
unobserve_entry.OnError(kRequestId, remove_watcher.OnError(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()), scoped_ptr<RequestValue>(new RequestValue()),
base::File::FILE_ERROR_TOO_MANY_OPENED); base::File::FILE_ERROR_TOO_MANY_OPENED);
ASSERT_EQ(1u, callback_log.size()); ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]); EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
} }
......
...@@ -40,9 +40,9 @@ class NotificationManagerInterface; ...@@ -40,9 +40,9 @@ class NotificationManagerInterface;
// Automatically calls the |update_callback| after all of the callbacks created // Automatically calls the |update_callback| after all of the callbacks created
// with |CreateCallback| are called. // with |CreateCallback| are called.
// //
// It's used to update tags of observed entries once a notification about a // It's used to update tags of watchers once a notification about a change is
// change are fully handles. It is to make sure that the change notification is // handled. It is to make sure that the change notification is fully handled
// fully handled before remembering the new tag. // before remembering the new tag.
// //
// It is necessary to update the tag after all observers handle it fully, so // It is necessary to update the tag after all observers handle it fully, so
// in case of shutdown or a crash we get the notifications again. // in case of shutdown or a crash we get the notifications again.
...@@ -137,23 +137,23 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -137,23 +137,23 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
int64 offset, int64 offset,
int length, int length,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual AbortCallback ObserveDirectory( virtual AbortCallback AddWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& directory_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
bool persistent, bool persistent,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual void UnobserveEntry( virtual void RemoveWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& entry_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
const storage::AsyncFileUtil::StatusCallback& callback) override; const storage::AsyncFileUtil::StatusCallback& callback) override;
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const override;
virtual RequestManager* GetRequestManager() override; virtual RequestManager* GetRequestManager() override;
virtual ObservedEntries* GetObservedEntries() override; virtual Watchers* GetWatchers() override;
virtual void AddObserver(ProvidedFileSystemObserver* observer) override; virtual void AddObserver(ProvidedFileSystemObserver* observer) override;
virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override; virtual void RemoveObserver(ProvidedFileSystemObserver* observer) override;
virtual bool Notify(const base::FilePath& observed_path, virtual bool Notify(const base::FilePath& entry_path,
bool recursive, bool recursive,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
scoped_ptr<ProvidedFileSystemObserver::Changes> changes, scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
...@@ -167,20 +167,19 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -167,20 +167,19 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
void Abort(int operation_request_id, void Abort(int operation_request_id,
const storage::AsyncFileUtil::StatusCallback& callback); const storage::AsyncFileUtil::StatusCallback& callback);
// Called when observing a directory process is completed with either success // Called when adding a watcher is completed with either success or en error.
// or en error. void OnAddWatcherCompleted(
void OnObserveDirectoryCompleted(
const GURL& origin, const GURL& origin,
const base::FilePath& directory_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
bool persistent, bool persistent,
const storage::AsyncFileUtil::StatusCallback& callback, const storage::AsyncFileUtil::StatusCallback& callback,
base::File::Error result); base::File::Error result);
// Called when all observers finished handling the change notification. It // Called when all observers finished handling the change notification. It
// updates the tag from |last_tag| to |tag| for the entry at |observed_path|. // updates the tag from |last_tag| to |tag| for the entry at |entry_path|.
void OnNotifyCompleted( void OnNotifyCompleted(
const base::FilePath& observed_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
scoped_ptr<ProvidedFileSystemObserver::Changes> changes, scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
...@@ -192,7 +191,7 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -192,7 +191,7 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
ProvidedFileSystemInfo file_system_info_; ProvidedFileSystemInfo file_system_info_;
scoped_ptr<NotificationManagerInterface> notification_manager_; scoped_ptr<NotificationManagerInterface> notification_manager_;
scoped_ptr<RequestManager> request_manager_; scoped_ptr<RequestManager> request_manager_;
ObservedEntries observed_entries_; Watchers watchers_;
ObserverList<ProvidedFileSystemObserver> observers_; ObserverList<ProvidedFileSystemObserver> observers_;
base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_; base::WeakPtrFactory<ProvidedFileSystem> weak_ptr_factory_;
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
#include "chrome/browser/chromeos/file_system_provider/watcher.h"
#include "storage/browser/fileapi/async_file_util.h" #include "storage/browser/fileapi/async_file_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -176,26 +176,28 @@ class ProvidedFileSystemInterface { ...@@ -176,26 +176,28 @@ class ProvidedFileSystemInterface {
int length, int length,
const storage::AsyncFileUtil::StatusCallback& callback) = 0; const storage::AsyncFileUtil::StatusCallback& callback) = 0;
// Requests observing a directory. // Requests adding a watcher on an entry. |recursive| must not be true for
virtual AbortCallback ObserveDirectory( // files.
virtual AbortCallback AddWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& directory_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
bool persistent, bool persistent,
const storage::AsyncFileUtil::StatusCallback& callback) = 0; const storage::AsyncFileUtil::StatusCallback& callback) = 0;
// Requests unobserving an entry, which is immediately removed from the // Requests removing a watcher, which is immediately deleted from the internal
// internal list, hence the operation is not abortable. // list, hence the operation is not abortable.
virtual void UnobserveEntry( virtual void RemoveWatcher(
const GURL& origin, const GURL& origin,
const base::FilePath& entry_path, const base::FilePath& entry_path,
bool recursive, bool recursive,
const storage::AsyncFileUtil::StatusCallback& callback) = 0; const storage::AsyncFileUtil::StatusCallback& callback) = 0;
// Notifies about changes to the observed entries within the file system. // Notifies about changes related to the watcher within the file system.
// Invoked by the file system implementation. Returns false if the // Invoked by the file system implementation. Returns false if the
// notification arguments are malformed or the entry is not observed anymore. // notification arguments are malformed or the entry is not watched anymore.
virtual bool Notify(const base::FilePath& observed_path, // TODO(mtomasz): Replace [entry_path, recursive] with a watcher id.
virtual bool Notify(const base::FilePath& entry_path,
bool recursive, bool recursive,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
scoped_ptr<ProvidedFileSystemObserver::Changes> changes, scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
...@@ -204,8 +206,8 @@ class ProvidedFileSystemInterface { ...@@ -204,8 +206,8 @@ class ProvidedFileSystemInterface {
// Returns a provided file system info for this file system. // Returns a provided file system info for this file system.
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0;
// Returns a mutable list of observed entries. // Returns a mutable list of watchers.
virtual ObservedEntries* GetObservedEntries() = 0; virtual Watchers* GetWatchers() = 0;
// Returns a request manager for the file system. // Returns a request manager for the file system.
virtual RequestManager* GetRequestManager() = 0; virtual RequestManager* GetRequestManager() = 0;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h" #include "chrome/browser/chromeos/file_system_provider/watcher.h"
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
...@@ -19,18 +19,18 @@ class ProvidedFileSystemInfo; ...@@ -19,18 +19,18 @@ class ProvidedFileSystemInfo;
class RequestManager; class RequestManager;
// Observer class to be notified about changes happened to the provided file // Observer class to be notified about changes happened to the provided file
// system, especially observed entries. // system, including watched entries.
class ProvidedFileSystemObserver { class ProvidedFileSystemObserver {
public: public:
struct Change; struct Change;
// Type of a change to an observed entry. // Type of a change to a watched entry.
enum ChangeType { CHANGED, DELETED }; enum ChangeType { CHANGED, DELETED };
// Lust of changes. // Lust of changes.
typedef std::vector<Change> Changes; typedef std::vector<Change> Changes;
// Describes a change related to an observed directory. // Describes a change related to a watched entry.
struct Change { struct Change {
Change(); Change();
~Change(); ~Change();
...@@ -39,26 +39,25 @@ class ProvidedFileSystemObserver { ...@@ -39,26 +39,25 @@ class ProvidedFileSystemObserver {
ChangeType change_type; ChangeType change_type;
}; };
// Called when an observed entry is changed, including removals. |callback| // Called when a watched entry is changed, including removals. |callback|
// *must* be called after the entry change is handled. Once all observers // *must* be called after the entry change is handled. Once all observers
// call the callback, the tag will be updated and OnObservedEntryTagUpdated // call the callback, the tag will be updated and OnWatcherTagUpdated
// called. The reference to |changes| is valid at least as long as |callback|. // called. The reference to |changes| is valid at least as long as |callback|.
virtual void OnObservedEntryChanged( virtual void OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const Watcher& watcher,
const ObservedEntry& observed_entry, ChangeType change_type,
ChangeType change_type, const Changes& changes,
const Changes& changes, const base::Closure& callback) = 0;
const base::Closure& callback) = 0;
// Called after the tag value is updated for the observed entry. // Called after the tag value is updated for the watcher.
virtual void OnObservedEntryTagUpdated( virtual void OnWatcherTagUpdated(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntry& observed_entry) = 0; const Watcher& watcher) = 0;
// Called after the list of observed entries is changed. // Called after the list of watchers is changed.
virtual void OnObservedEntryListChanged( virtual void OnWatcherListChanged(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) = 0; const Watchers& watchers) = 0;
}; };
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <string> #include <string>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
#include "chrome/browser/chromeos/file_system_provider/registry_interface.h" #include "chrome/browser/chromeos/file_system_provider/registry_interface.h"
#include "chrome/browser/chromeos/file_system_provider/watcher.h"
class Profile; class Profile;
...@@ -25,11 +25,11 @@ extern const char kPrefKeyFileSystemId[]; ...@@ -25,11 +25,11 @@ extern const char kPrefKeyFileSystemId[];
extern const char kPrefKeyDisplayName[]; extern const char kPrefKeyDisplayName[];
extern const char kPrefKeyWritable[]; extern const char kPrefKeyWritable[];
extern const char kPrefKeySupportsNotifyTag[]; extern const char kPrefKeySupportsNotifyTag[];
extern const char kPrefKeyObservedEntries[]; extern const char kPrefKeyWatchers[];
extern const char kPrefKeyObservedEntryEntryPath[]; extern const char kPrefKeyWatcherEntryPath[];
extern const char kPrefKeyObservedEntryRecursive[]; extern const char kPrefKeyWatcherRecursive[];
extern const char kPrefKeyObservedEntryPersistentOrigins[]; extern const char kPrefKeyWatcherPersistentOrigins[];
extern const char kPrefKeyObservedEntryLastTag[]; extern const char kPrefKeyWatcherLastTag[];
class ProvidedFileSystemInfo; class ProvidedFileSystemInfo;
...@@ -45,14 +45,13 @@ class Registry : public RegistryInterface { ...@@ -45,14 +45,13 @@ class Registry : public RegistryInterface {
// RegistryInterface overrides. // RegistryInterface overrides.
virtual void RememberFileSystem( virtual void RememberFileSystem(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) override; const Watchers& watchers) override;
virtual void ForgetFileSystem(const std::string& extension_id, virtual void ForgetFileSystem(const std::string& extension_id,
const std::string& file_system_id) override; const std::string& file_system_id) override;
virtual scoped_ptr<RestoredFileSystems> RestoreFileSystems( virtual scoped_ptr<RestoredFileSystems> RestoreFileSystems(
const std::string& extension_id) override; const std::string& extension_id) override;
virtual void UpdateObservedEntryTag( virtual void UpdateWatcherTag(const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const Watcher& watcher) override;
const ObservedEntry& observed_entry) override;
private: private:
Profile* profile_; // Not owned. Profile* profile_; // Not owned.
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/watcher.h"
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
...@@ -21,7 +21,7 @@ class RegistryInterface { ...@@ -21,7 +21,7 @@ class RegistryInterface {
public: public:
struct RestoredFileSystem; struct RestoredFileSystem;
// List of file systems together with their observed entries to be remounted. // List of file systems together with their watchers to be remounted.
typedef std::vector<RestoredFileSystem> RestoredFileSystems; typedef std::vector<RestoredFileSystem> RestoredFileSystems;
// Information about a file system to be restored. // Information about a file system to be restored.
...@@ -31,7 +31,7 @@ class RegistryInterface { ...@@ -31,7 +31,7 @@ class RegistryInterface {
std::string extension_id; std::string extension_id;
MountOptions options; MountOptions options;
ObservedEntries observed_entries; Watchers watchers;
}; };
virtual ~RegistryInterface(); virtual ~RegistryInterface();
...@@ -40,7 +40,7 @@ class RegistryInterface { ...@@ -40,7 +40,7 @@ class RegistryInterface {
// reboot. // reboot.
virtual void RememberFileSystem( virtual void RememberFileSystem(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) = 0; const Watchers& watchers) = 0;
// Removes the file system from preferences, so it is not remounmted anymore // Removes the file system from preferences, so it is not remounmted anymore
// after a reboot. // after a reboot.
...@@ -53,10 +53,9 @@ class RegistryInterface { ...@@ -53,10 +53,9 @@ class RegistryInterface {
virtual scoped_ptr<RestoredFileSystems> RestoreFileSystems( virtual scoped_ptr<RestoredFileSystems> RestoreFileSystems(
const std::string& extension_id) = 0; const std::string& extension_id) = 0;
// Updates a tag for the specified observed entry. // Updates a tag for the specified watcher.
virtual void UpdateObservedEntryTag( virtual void UpdateWatcherTag(const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const Watcher& watcher) = 0;
const ObservedEntry& observed_entry) = 0;
}; };
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -48,10 +48,10 @@ std::string RequestTypeToString(RequestType type) { ...@@ -48,10 +48,10 @@ std::string RequestTypeToString(RequestType type) {
return "WRITE_FILE"; return "WRITE_FILE";
case ABORT: case ABORT:
return "ABORT"; return "ABORT";
case OBSERVE_DIRECTORY: case ADD_WATCHER:
return "OBSERVE_DIRECTORY"; return "ADD_WATCHER";
case UNOBSERVE_ENTRY: case REMOVE_WATCHER:
return "UNOBSERVE_ENTRY"; return "REMOVE_WATCHER";
case TESTING: case TESTING:
return "TESTING"; return "TESTING";
} }
......
...@@ -39,8 +39,8 @@ enum RequestType { ...@@ -39,8 +39,8 @@ enum RequestType {
TRUNCATE, TRUNCATE,
WRITE_FILE, WRITE_FILE,
ABORT, ABORT,
OBSERVE_DIRECTORY, ADD_WATCHER,
UNOBSERVE_ENTRY, REMOVE_WATCHER,
TESTING TESTING
}; };
......
...@@ -158,8 +158,7 @@ bool Service::MountFileSystem(const std::string& extension_id, ...@@ -158,8 +158,7 @@ bool Service::MountFileSystem(const std::string& extension_id,
file_system; file_system;
mount_point_name_to_key_map_[mount_point_name] = mount_point_name_to_key_map_[mount_point_name] =
FileSystemKey(extension_id, options.file_system_id); FileSystemKey(extension_id, options.file_system_id);
registry_->RememberFileSystem(file_system_info, registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers());
*file_system->GetObservedEntries());
FOR_EACH_OBSERVER( FOR_EACH_OBSERVER(
Observer, Observer,
...@@ -311,9 +310,8 @@ void Service::OnExtensionLoaded(content::BrowserContext* browser_context, ...@@ -311,9 +310,8 @@ void Service::OnExtensionLoaded(content::BrowserContext* browser_context,
GetProvidedFileSystem(restored_file_system.extension_id, GetProvidedFileSystem(restored_file_system.extension_id,
restored_file_system.options.file_system_id); restored_file_system.options.file_system_id);
DCHECK(file_system); DCHECK(file_system);
file_system->GetObservedEntries()->insert( file_system->GetWatchers()->insert(restored_file_system.watchers.begin(),
restored_file_system.observed_entries.begin(), restored_file_system.watchers.end());
restored_file_system.observed_entries.end());
} }
} }
...@@ -347,28 +345,27 @@ void Service::OnRequestUnmountStatus( ...@@ -347,28 +345,27 @@ void Service::OnRequestUnmountStatus(
} }
} }
void Service::OnObservedEntryChanged( void Service::OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const Watcher& watcher,
const ObservedEntry& observed_entry, ChangeType change_type,
ChangeType change_type, const Changes& changes,
const Changes& changes, const base::Closure& callback) {
const base::Closure& callback) {
callback.Run(); callback.Run();
} }
void Service::OnObservedEntryTagUpdated( void Service::OnWatcherTagUpdated(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntry& observed_entry) { const Watcher& watcher) {
PrefService* const pref_service = profile_->GetPrefs(); PrefService* const pref_service = profile_->GetPrefs();
DCHECK(pref_service); DCHECK(pref_service);
registry_->UpdateObservedEntryTag(file_system_info, observed_entry); registry_->UpdateWatcherTag(file_system_info, watcher);
} }
void Service::OnObservedEntryListChanged( void Service::OnWatcherListChanged(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) { const Watchers& watchers) {
registry_->RememberFileSystem(file_system_info, observed_entries); registry_->RememberFileSystem(file_system_info, watchers);
} }
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h"
#include "chrome/browser/chromeos/file_system_provider/observer.h" #include "chrome/browser/chromeos/file_system_provider/observer.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
#include "chrome/browser/chromeos/file_system_provider/watcher.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/file_system_provider.h" #include "chrome/common/extensions/api/file_system_provider.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
...@@ -129,18 +129,18 @@ class Service : public KeyedService, ...@@ -129,18 +129,18 @@ class Service : public KeyedService,
const extensions::Extension* extension) override; const extensions::Extension* extension) override;
// ProvidedFileSystemInterface::Observer overrides. // ProvidedFileSystemInterface::Observer overrides.
virtual void OnObservedEntryChanged( virtual void OnWatcherChanged(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntry& observed_entry, const Watcher& watcher,
ProvidedFileSystemObserver::ChangeType change_type, ProvidedFileSystemObserver::ChangeType change_type,
const ProvidedFileSystemObserver::Changes& changes, const ProvidedFileSystemObserver::Changes& changes,
const base::Closure& callback) override; const base::Closure& callback) override;
virtual void OnObservedEntryTagUpdated( virtual void OnWatcherTagUpdated(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntry& observed_entry) override; const Watcher& watcher) override;
virtual void OnObservedEntryListChanged( virtual void OnWatcherListChanged(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) override; const Watchers& watchers) override;
private: private:
FRIEND_TEST_ALL_PREFIXES(FileSystemProviderServiceTest, RememberFileSystem); FRIEND_TEST_ALL_PREFIXES(FileSystemProviderServiceTest, RememberFileSystem);
...@@ -161,7 +161,7 @@ class Service : public KeyedService, ...@@ -161,7 +161,7 @@ class Service : public KeyedService,
// Remembers the file system in preferences, in order to remount after a // Remembers the file system in preferences, in order to remount after a
// reboot. // reboot.
void RememberFileSystem(const ProvidedFileSystemInfo& file_system_info, void RememberFileSystem(const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries); const Watchers& watchers);
// Removes the file system from preferences, so it is not remounmted anymore // Removes the file system from preferences, so it is not remounmted anymore
// after a reboot. // after a reboot.
......
...@@ -92,19 +92,19 @@ class FakeRegistry : public RegistryInterface { ...@@ -92,19 +92,19 @@ class FakeRegistry : public RegistryInterface {
// RegistryInterface overrides. // RegistryInterface overrides.
virtual void RememberFileSystem( virtual void RememberFileSystem(
const ProvidedFileSystemInfo& file_system_info, const ProvidedFileSystemInfo& file_system_info,
const ObservedEntries& observed_entries) override { const Watchers& watchers) override {
file_system_info_.reset(new ProvidedFileSystemInfo(file_system_info)); file_system_info_.reset(new ProvidedFileSystemInfo(file_system_info));
observed_entries_.reset(new ObservedEntries(observed_entries)); watchers_.reset(new Watchers(watchers));
} }
virtual void ForgetFileSystem(const std::string& extension_id, virtual void ForgetFileSystem(const std::string& extension_id,
const std::string& file_system_id) override { const std::string& file_system_id) override {
if (!file_system_info_.get() || !observed_entries_.get()) if (!file_system_info_.get() || !watchers_.get())
return; return;
if (file_system_info_->extension_id() == extension_id && if (file_system_info_->extension_id() == extension_id &&
file_system_info_->file_system_id() == file_system_id) { file_system_info_->file_system_id() == file_system_id) {
file_system_info_.reset(); file_system_info_.reset();
observed_entries_.reset(); watchers_.reset();
} }
} }
...@@ -112,7 +112,7 @@ class FakeRegistry : public RegistryInterface { ...@@ -112,7 +112,7 @@ class FakeRegistry : public RegistryInterface {
const std::string& extension_id) override { const std::string& extension_id) override {
scoped_ptr<RestoredFileSystems> result(new RestoredFileSystems); scoped_ptr<RestoredFileSystems> result(new RestoredFileSystems);
if (file_system_info_.get() && observed_entries_.get()) { if (file_system_info_.get() && watchers_.get()) {
RestoredFileSystem restored_file_system; RestoredFileSystem restored_file_system;
restored_file_system.extension_id = file_system_info_->extension_id(); restored_file_system.extension_id = file_system_info_->extension_id();
...@@ -122,7 +122,7 @@ class FakeRegistry : public RegistryInterface { ...@@ -122,7 +122,7 @@ class FakeRegistry : public RegistryInterface {
options.writable = file_system_info_->writable(); options.writable = file_system_info_->writable();
options.supports_notify_tag = file_system_info_->supports_notify_tag(); options.supports_notify_tag = file_system_info_->supports_notify_tag();
restored_file_system.options = options; restored_file_system.options = options;
restored_file_system.observed_entries = *observed_entries_.get(); restored_file_system.watchers = *watchers_.get();
result->push_back(restored_file_system); result->push_back(restored_file_system);
} }
...@@ -130,26 +130,23 @@ class FakeRegistry : public RegistryInterface { ...@@ -130,26 +130,23 @@ class FakeRegistry : public RegistryInterface {
return result; return result;
} }
virtual void UpdateObservedEntryTag( virtual void UpdateWatcherTag(const ProvidedFileSystemInfo& file_system_info,
const ProvidedFileSystemInfo& file_system_info, const Watcher& watcher) override {
const ObservedEntry& observed_entry) override { ASSERT_TRUE(watchers_.get());
ASSERT_TRUE(observed_entries_.get()); const Watchers::iterator it =
const ObservedEntries::iterator it = observed_entries_->find( watchers_->find(WatcherKey(watcher.entry_path, watcher.recursive));
ObservedEntryKey(observed_entry.entry_path, observed_entry.recursive)); ASSERT_NE(watchers_->end(), it);
ASSERT_NE(observed_entries_->end(), it); it->second.last_tag = watcher.last_tag;
it->second.last_tag = observed_entry.last_tag;
} }
ProvidedFileSystemInfo* const file_system_info() const { ProvidedFileSystemInfo* const file_system_info() const {
return file_system_info_.get(); return file_system_info_.get();
} }
ObservedEntries* const observed_entries() const { Watchers* const watchers() const { return watchers_.get(); }
return observed_entries_.get();
}
private: private:
scoped_ptr<ProvidedFileSystemInfo> file_system_info_; scoped_ptr<ProvidedFileSystemInfo> file_system_info_;
scoped_ptr<ObservedEntries> observed_entries_; scoped_ptr<Watchers> watchers_;
DISALLOW_COPY_AND_ASSIGN(FakeRegistry); DISALLOW_COPY_AND_ASSIGN(FakeRegistry);
}; };
...@@ -198,10 +195,9 @@ class FileSystemProviderServiceTest : public testing::Test { ...@@ -198,10 +195,9 @@ class FileSystemProviderServiceTest : public testing::Test {
// Passes ownership to the service instance. // Passes ownership to the service instance.
service_->SetRegistryForTesting(make_scoped_ptr(registry_)); service_->SetRegistryForTesting(make_scoped_ptr(registry_));
fake_observed_entry_.entry_path = fake_watcher_.entry_path = base::FilePath(FILE_PATH_LITERAL("/a/b/c"));
base::FilePath(FILE_PATH_LITERAL("/a/b/c")); fake_watcher_.recursive = true;
fake_observed_entry_.recursive = true; fake_watcher_.last_tag = "hello-world";
fake_observed_entry_.last_tag = "hello-world";
} }
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
...@@ -213,7 +209,7 @@ class FileSystemProviderServiceTest : public testing::Test { ...@@ -213,7 +209,7 @@ class FileSystemProviderServiceTest : public testing::Test {
scoped_ptr<Service> service_; scoped_ptr<Service> service_;
scoped_refptr<extensions::Extension> extension_; scoped_refptr<extensions::Extension> extension_;
FakeRegistry* registry_; // Owned by Service. FakeRegistry* registry_; // Owned by Service.
ObservedEntry fake_observed_entry_; Watcher fake_watcher_;
}; };
TEST_F(FileSystemProviderServiceTest, MountFileSystem) { TEST_F(FileSystemProviderServiceTest, MountFileSystem) {
...@@ -400,11 +396,10 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { ...@@ -400,11 +396,10 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
options.supports_notify_tag = true; options.supports_notify_tag = true;
ProvidedFileSystemInfo file_system_info( ProvidedFileSystemInfo file_system_info(
kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c"))); kExtensionId, options, base::FilePath(FILE_PATH_LITERAL("/a/b/c")));
ObservedEntries fake_observed_entries; Watchers fake_watchers;
fake_observed_entries[ObservedEntryKey(fake_observed_entry_.entry_path, fake_watchers[WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive)] =
fake_observed_entry_.recursive)] = fake_watcher_;
fake_observed_entry_; registry_->RememberFileSystem(file_system_info, fake_watchers);
registry_->RememberFileSystem(file_system_info, fake_observed_entries);
EXPECT_EQ(0u, observer.mounts.size()); EXPECT_EQ(0u, observer.mounts.size());
...@@ -431,22 +426,17 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { ...@@ -431,22 +426,17 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
service_->GetProvidedFileSystem(kExtensionId, kFileSystemId); service_->GetProvidedFileSystem(kExtensionId, kFileSystemId);
ASSERT_TRUE(file_system); ASSERT_TRUE(file_system);
const ObservedEntries* const observed_entries = const Watchers* const watchers = file_system->GetWatchers();
file_system->GetObservedEntries(); ASSERT_TRUE(watchers);
ASSERT_TRUE(observed_entries); ASSERT_EQ(1u, watchers->size());
ASSERT_EQ(1u, observed_entries->size());
const ObservedEntries::const_iterator restored_observed_entry_it = const Watchers::const_iterator restored_watcher_it = watchers->find(
observed_entries->find(ObservedEntryKey(fake_observed_entry_.entry_path, WatcherKey(fake_watcher_.entry_path, fake_watcher_.recursive));
fake_observed_entry_.recursive)); ASSERT_NE(watchers->end(), restored_watcher_it);
ASSERT_NE(observed_entries->end(), restored_observed_entry_it);
EXPECT_EQ(fake_observed_entry_.entry_path, EXPECT_EQ(fake_watcher_.entry_path, restored_watcher_it->second.entry_path);
restored_observed_entry_it->second.entry_path); EXPECT_EQ(fake_watcher_.recursive, restored_watcher_it->second.recursive);
EXPECT_EQ(fake_observed_entry_.recursive, EXPECT_EQ(fake_watcher_.last_tag, restored_watcher_it->second.last_tag);
restored_observed_entry_it->second.recursive);
EXPECT_EQ(fake_observed_entry_.last_tag,
restored_observed_entry_it->second.last_tag);
service_->RemoveObserver(&observer); service_->RemoveObserver(&observer);
} }
...@@ -456,7 +446,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) { ...@@ -456,7 +446,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) {
service_->AddObserver(&observer); service_->AddObserver(&observer);
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->observed_entries()); EXPECT_FALSE(registry_->watchers());
EXPECT_TRUE(service_->MountFileSystem( EXPECT_TRUE(service_->MountFileSystem(
kExtensionId, MountOptions(kFileSystemId, kDisplayName))); kExtensionId, MountOptions(kFileSystemId, kDisplayName)));
...@@ -468,7 +458,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) { ...@@ -468,7 +458,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) {
EXPECT_EQ(kDisplayName, registry_->file_system_info()->display_name()); EXPECT_EQ(kDisplayName, registry_->file_system_info()->display_name());
EXPECT_FALSE(registry_->file_system_info()->writable()); EXPECT_FALSE(registry_->file_system_info()->writable());
EXPECT_FALSE(registry_->file_system_info()->supports_notify_tag()); EXPECT_FALSE(registry_->file_system_info()->supports_notify_tag());
ASSERT_TRUE(registry_->observed_entries()); ASSERT_TRUE(registry_->watchers());
service_->RemoveObserver(&observer); service_->RemoveObserver(&observer);
} }
...@@ -479,13 +469,13 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) { ...@@ -479,13 +469,13 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) {
{ {
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->observed_entries()); EXPECT_FALSE(registry_->watchers());
EXPECT_TRUE(service_->MountFileSystem( EXPECT_TRUE(service_->MountFileSystem(
kExtensionId, MountOptions(kFileSystemId, kDisplayName))); kExtensionId, MountOptions(kFileSystemId, kDisplayName)));
EXPECT_EQ(1u, observer.mounts.size()); EXPECT_EQ(1u, observer.mounts.size());
EXPECT_TRUE(registry_->file_system_info()); EXPECT_TRUE(registry_->file_system_info());
EXPECT_TRUE(registry_->observed_entries()); EXPECT_TRUE(registry_->watchers());
} }
{ {
...@@ -494,7 +484,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) { ...@@ -494,7 +484,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) {
EXPECT_EQ(1u, observer.unmounts.size()); EXPECT_EQ(1u, observer.unmounts.size());
EXPECT_TRUE(registry_->file_system_info()); EXPECT_TRUE(registry_->file_system_info());
EXPECT_TRUE(registry_->observed_entries()); EXPECT_TRUE(registry_->watchers());
} }
service_->RemoveObserver(&observer); service_->RemoveObserver(&observer);
...@@ -506,13 +496,13 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) { ...@@ -506,13 +496,13 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) {
{ {
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->observed_entries()); EXPECT_FALSE(registry_->watchers());
EXPECT_TRUE(service_->MountFileSystem( EXPECT_TRUE(service_->MountFileSystem(
kExtensionId, MountOptions(kFileSystemId, kDisplayName))); kExtensionId, MountOptions(kFileSystemId, kDisplayName)));
EXPECT_EQ(1u, observer.mounts.size()); EXPECT_EQ(1u, observer.mounts.size());
EXPECT_TRUE(registry_->file_system_info()); EXPECT_TRUE(registry_->file_system_info());
EXPECT_TRUE(registry_->observed_entries()); EXPECT_TRUE(registry_->watchers());
} }
{ {
...@@ -521,7 +511,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) { ...@@ -521,7 +511,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) {
EXPECT_EQ(1u, observer.unmounts.size()); EXPECT_EQ(1u, observer.unmounts.size());
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->observed_entries()); EXPECT_FALSE(registry_->watchers());
} }
service_->RemoveObserver(&observer); service_->RemoveObserver(&observer);
......
...@@ -2,21 +2,20 @@ ...@@ -2,21 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/file_system_provider/observed_entry.h" #include "chrome/browser/chromeos/file_system_provider/watcher.h"
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
ObservedEntryKey::ObservedEntryKey(const base::FilePath& entry_path, WatcherKey::WatcherKey(const base::FilePath& entry_path, bool recursive)
bool recursive)
: entry_path(entry_path), recursive(recursive) { : entry_path(entry_path), recursive(recursive) {
} }
ObservedEntryKey::~ObservedEntryKey() { WatcherKey::~WatcherKey() {
} }
bool ObservedEntryKey::Comparator::operator()(const ObservedEntryKey& a, bool WatcherKey::Comparator::operator()(const WatcherKey& a,
const ObservedEntryKey& b) const { const WatcherKey& b) const {
if (a.entry_path != b.entry_path) if (a.entry_path != b.entry_path)
return a.entry_path < b.entry_path; return a.entry_path < b.entry_path;
return a.recursive < b.recursive; return a.recursive < b.recursive;
...@@ -28,10 +27,10 @@ Subscriber::Subscriber() : persistent(false) { ...@@ -28,10 +27,10 @@ Subscriber::Subscriber() : persistent(false) {
Subscriber::~Subscriber() { Subscriber::~Subscriber() {
} }
ObservedEntry::ObservedEntry() : recursive(false) { Watcher::Watcher() : recursive(false) {
} }
ObservedEntry::~ObservedEntry() { Watcher::~Watcher() {
} }
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OBSERVED_ENTRY_H_ #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_WATCHER_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OBSERVED_ENTRY_H_ #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_WATCHER_H_
#include <map> #include <map>
#include <set> #include <set>
...@@ -15,32 +15,31 @@ ...@@ -15,32 +15,31 @@
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
struct ObservedEntry; struct Watcher;
struct Subscriber; struct Subscriber;
// Key for storing an observed entry in the map. There may be two observers // Key for storing a watcher in the map. There may be two watchers per path,
// per path, as long as one is recursive, and the other one not. // as long as one is recursive, and the other one not.
struct ObservedEntryKey { struct WatcherKey {
ObservedEntryKey(const base::FilePath& entry_path, bool recursive); WatcherKey(const base::FilePath& entry_path, bool recursive);
~ObservedEntryKey(); ~WatcherKey();
struct Comparator { struct Comparator {
bool operator()(const ObservedEntryKey& a, const ObservedEntryKey& b) const; bool operator()(const WatcherKey& a, const WatcherKey& b) const;
}; };
base::FilePath entry_path; base::FilePath entry_path;
bool recursive; bool recursive;
}; };
// List of observed entries. // List of watchers.
typedef std::map<ObservedEntryKey, ObservedEntry, ObservedEntryKey::Comparator> typedef std::map<WatcherKey, Watcher, WatcherKey::Comparator> Watchers;
ObservedEntries;
// Map of subscribers for notifications about an observed entry. // Map of subscribers for notifications about a watcher.
typedef std::map<GURL, Subscriber> Subscribers; typedef std::map<GURL, Subscriber> Subscribers;
// Represents a subscriber for notification about an observed entry. There may // Represents a subscriber for notification about a watcher. There may be up to
// be up to one subscriber per origin for the same observed entry. // one subscriber per origin for the same watcher.
struct Subscriber { struct Subscriber {
Subscriber(); Subscriber();
~Subscriber(); ~Subscriber();
...@@ -52,21 +51,21 @@ struct Subscriber { ...@@ -52,21 +51,21 @@ struct Subscriber {
bool persistent; bool persistent;
}; };
// Represents an observed entry on a file system. // Represents a watcher on a file system.
struct ObservedEntry { struct Watcher {
ObservedEntry(); Watcher();
~ObservedEntry(); ~Watcher();
// Map of subscribers for notifications of the observed entry. // Map of subscribers for notifications of the watcher.
Subscribers subscribers; Subscribers subscribers;
// Path of the observed entry. // Path of the watcher.
base::FilePath entry_path; base::FilePath entry_path;
// Whether observing is recursive or not. // Whether watching is recursive or not.
bool recursive; bool recursive;
// Tag of the last notification for this observed entry. May be empty if not // Tag of the last notification for this watcher. May be empty if not
// supported. // supported.
std::string last_tag; std::string last_tag;
}; };
...@@ -74,4 +73,4 @@ struct ObservedEntry { ...@@ -74,4 +73,4 @@ struct ObservedEntry {
} // namespace file_system_provider } // namespace file_system_provider
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OBSERVED_ENTRY_H_ #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_WATCHER_H_
...@@ -280,11 +280,11 @@ ...@@ -280,11 +280,11 @@
'browser/chromeos/file_system_provider/notification_manager.cc', 'browser/chromeos/file_system_provider/notification_manager.cc',
'browser/chromeos/file_system_provider/notification_manager.h', 'browser/chromeos/file_system_provider/notification_manager.h',
'browser/chromeos/file_system_provider/notification_manager_interface.h', 'browser/chromeos/file_system_provider/notification_manager_interface.h',
'browser/chromeos/file_system_provider/observed_entry.cc',
'browser/chromeos/file_system_provider/observed_entry.h',
'browser/chromeos/file_system_provider/observer.h', 'browser/chromeos/file_system_provider/observer.h',
'browser/chromeos/file_system_provider/operations/abort.cc', 'browser/chromeos/file_system_provider/operations/abort.cc',
'browser/chromeos/file_system_provider/operations/abort.h', 'browser/chromeos/file_system_provider/operations/abort.h',
'browser/chromeos/file_system_provider/operations/add_watcher.cc',
'browser/chromeos/file_system_provider/operations/add_watcher.h',
'browser/chromeos/file_system_provider/operations/close_file.cc', 'browser/chromeos/file_system_provider/operations/close_file.cc',
'browser/chromeos/file_system_provider/operations/close_file.h', 'browser/chromeos/file_system_provider/operations/close_file.h',
'browser/chromeos/file_system_provider/operations/copy_entry.cc', 'browser/chromeos/file_system_provider/operations/copy_entry.cc',
...@@ -299,8 +299,6 @@ ...@@ -299,8 +299,6 @@
'browser/chromeos/file_system_provider/operations/get_metadata.h', 'browser/chromeos/file_system_provider/operations/get_metadata.h',
'browser/chromeos/file_system_provider/operations/move_entry.cc', 'browser/chromeos/file_system_provider/operations/move_entry.cc',
'browser/chromeos/file_system_provider/operations/move_entry.h', 'browser/chromeos/file_system_provider/operations/move_entry.h',
'browser/chromeos/file_system_provider/operations/observe_directory.cc',
'browser/chromeos/file_system_provider/operations/observe_directory.h',
'browser/chromeos/file_system_provider/operations/open_file.cc', 'browser/chromeos/file_system_provider/operations/open_file.cc',
'browser/chromeos/file_system_provider/operations/open_file.h', 'browser/chromeos/file_system_provider/operations/open_file.h',
'browser/chromeos/file_system_provider/operations/operation.cc', 'browser/chromeos/file_system_provider/operations/operation.cc',
...@@ -309,12 +307,12 @@ ...@@ -309,12 +307,12 @@
'browser/chromeos/file_system_provider/operations/read_directory.h', 'browser/chromeos/file_system_provider/operations/read_directory.h',
'browser/chromeos/file_system_provider/operations/read_file.cc', 'browser/chromeos/file_system_provider/operations/read_file.cc',
'browser/chromeos/file_system_provider/operations/read_file.h', 'browser/chromeos/file_system_provider/operations/read_file.h',
'browser/chromeos/file_system_provider/operations/remove_watcher.cc',
'browser/chromeos/file_system_provider/operations/remove_watcher.h',
'browser/chromeos/file_system_provider/operations/truncate.cc', 'browser/chromeos/file_system_provider/operations/truncate.cc',
'browser/chromeos/file_system_provider/operations/truncate.h', 'browser/chromeos/file_system_provider/operations/truncate.h',
'browser/chromeos/file_system_provider/operations/unmount.cc', 'browser/chromeos/file_system_provider/operations/unmount.cc',
'browser/chromeos/file_system_provider/operations/unmount.h', 'browser/chromeos/file_system_provider/operations/unmount.h',
'browser/chromeos/file_system_provider/operations/unobserve_entry.cc',
'browser/chromeos/file_system_provider/operations/unobserve_entry.h',
'browser/chromeos/file_system_provider/operations/write_file.cc', 'browser/chromeos/file_system_provider/operations/write_file.cc',
'browser/chromeos/file_system_provider/operations/write_file.h', 'browser/chromeos/file_system_provider/operations/write_file.h',
'browser/chromeos/file_system_provider/provided_file_system.cc', 'browser/chromeos/file_system_provider/provided_file_system.cc',
...@@ -337,6 +335,8 @@ ...@@ -337,6 +335,8 @@
'browser/chromeos/file_system_provider/service.h', 'browser/chromeos/file_system_provider/service.h',
'browser/chromeos/file_system_provider/service_factory.cc', 'browser/chromeos/file_system_provider/service_factory.cc',
'browser/chromeos/file_system_provider/service_factory.h', 'browser/chromeos/file_system_provider/service_factory.h',
'browser/chromeos/file_system_provider/watcher.cc',
'browser/chromeos/file_system_provider/watcher.h',
'browser/chromeos/fileapi/external_file_protocol_handler.cc', 'browser/chromeos/fileapi/external_file_protocol_handler.cc',
'browser/chromeos/fileapi/external_file_protocol_handler.h', 'browser/chromeos/fileapi/external_file_protocol_handler.h',
'browser/chromeos/fileapi/external_file_url_request_job.cc', 'browser/chromeos/fileapi/external_file_url_request_job.cc',
......
...@@ -158,6 +158,8 @@ ...@@ -158,6 +158,8 @@
'browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc', 'browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc',
'browser/chromeos/file_system_provider/mount_path_util_unittest.cc', 'browser/chromeos/file_system_provider/mount_path_util_unittest.cc',
'browser/chromeos/file_system_provider/operations/abort_unittest.cc', 'browser/chromeos/file_system_provider/operations/abort_unittest.cc',
'browser/chromeos/file_system_provider/operations/add_watcher_unittest.cc',
'browser/chromeos/file_system_provider/operations/add_watcher_unittest.cc',
'browser/chromeos/file_system_provider/operations/close_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/close_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/copy_entry_unittest.cc', 'browser/chromeos/file_system_provider/operations/copy_entry_unittest.cc',
'browser/chromeos/file_system_provider/operations/create_directory_unittest.cc', 'browser/chromeos/file_system_provider/operations/create_directory_unittest.cc',
...@@ -165,17 +167,14 @@ ...@@ -165,17 +167,14 @@
'browser/chromeos/file_system_provider/operations/delete_entry_unittest.cc', 'browser/chromeos/file_system_provider/operations/delete_entry_unittest.cc',
'browser/chromeos/file_system_provider/operations/get_metadata_unittest.cc', 'browser/chromeos/file_system_provider/operations/get_metadata_unittest.cc',
'browser/chromeos/file_system_provider/operations/move_entry_unittest.cc', 'browser/chromeos/file_system_provider/operations/move_entry_unittest.cc',
'browser/chromeos/file_system_provider/operations/observe_directory_unittest.cc',
'browser/chromeos/file_system_provider/operations/open_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/open_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/read_directory_unittest.cc', 'browser/chromeos/file_system_provider/operations/read_directory_unittest.cc',
'browser/chromeos/file_system_provider/operations/read_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/read_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/remove_watcher_unittest.cc',
'browser/chromeos/file_system_provider/operations/test_util.cc', 'browser/chromeos/file_system_provider/operations/test_util.cc',
'browser/chromeos/file_system_provider/operations/test_util.cc',
'browser/chromeos/file_system_provider/operations/test_util.h',
'browser/chromeos/file_system_provider/operations/test_util.h', 'browser/chromeos/file_system_provider/operations/test_util.h',
'browser/chromeos/file_system_provider/operations/truncate_unittest.cc', 'browser/chromeos/file_system_provider/operations/truncate_unittest.cc',
'browser/chromeos/file_system_provider/operations/unmount_unittest.cc', 'browser/chromeos/file_system_provider/operations/unmount_unittest.cc',
'browser/chromeos/file_system_provider/operations/unobserve_entry_unittest.cc',
'browser/chromeos/file_system_provider/operations/write_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/write_file_unittest.cc',
'browser/chromeos/file_system_provider/provided_file_system_unittest.cc', 'browser/chromeos/file_system_provider/provided_file_system_unittest.cc',
'browser/chromeos/file_system_provider/registry_unittest.cc', 'browser/chromeos/file_system_provider/registry_unittest.cc',
......
...@@ -63,15 +63,16 @@ namespace fileSystemProvider { ...@@ -63,15 +63,16 @@ namespace fileSystemProvider {
DOMString? thumbnail; DOMString? thumbnail;
}; };
// Represents an observed entry. // Represents a watcher.
dictionary ObservedEntry { dictionary Watcher {
// The path of the entry being observed. // The path of the entry being observed.
DOMString entryPath; DOMString entryPath;
// Whether observing should include all child entries recursively. // Whether watching should include all child entries recursively. It can be
// true for directories only.
boolean recursive; boolean recursive;
// Tag used by the last notification for the observed path. // Tag used by the last notification for the watcher.
DOMString? lastTag; DOMString? lastTag;
}; };
...@@ -91,8 +92,8 @@ namespace fileSystemProvider { ...@@ -91,8 +92,8 @@ namespace fileSystemProvider {
// directories. // directories.
[nodoc] boolean? supportsNotifyTag; [nodoc] boolean? supportsNotifyTag;
// List of observed entries. // List of watchers.
[nodoc] ObservedEntry[] observedEntries; [nodoc] Watcher[] watchers;
}; };
// Options for the <code>mount()</code> method. // Options for the <code>mount()</code> method.
...@@ -316,34 +317,35 @@ namespace fileSystemProvider { ...@@ -316,34 +317,35 @@ namespace fileSystemProvider {
long operationRequestId; long operationRequestId;
}; };
// Options for the <code>onObserveDirectoryRequested()</code> event. // Options for the <code>onAddWatcherRequested()</code> event.
dictionary ObserveDirectoryRequestedOptions { dictionary AddWatcherRequestedOptions {
// The identifier of the file system related to this operation. // The identifier of the file system related to this operation.
DOMString fileSystemId; DOMString fileSystemId;
// The unique identifier of this request. // The unique identifier of this request.
long requestId; long requestId;
// The path of the directory to be observed. // The path of the entry to be observed.
DOMString directoryPath; DOMString entryPath;
// Whether observing should include all child entries recursively. // Whether observing should include all child entries recursively. It can be
// true for directories only.
boolean recursive; boolean recursive;
}; };
// Options for the <code>onUnobserveEntryRequested()</code> event. // Options for the <code>onRemoveWatcherRequested()</code> event.
dictionary UnobserveEntryRequestedOptions { dictionary RemoveWatcherRequestedOptions {
// The identifier of the file system related to this operation. // The identifier of the file system related to this operation.
DOMString fileSystemId; DOMString fileSystemId;
// The unique identifier of this request. // The unique identifier of this request.
long requestId; long requestId;
// Mode of the observed entry. // The path of the watched entry.
boolean recursive;
// The path of the entry to be not observed anymore.
DOMString entryPath; DOMString entryPath;
// Mode of the watcher.
boolean recursive;
}; };
// Information about a change happened to an entry within the observed // Information about a change happened to an entry within the observed
...@@ -587,15 +589,15 @@ namespace fileSystemProvider { ...@@ -587,15 +589,15 @@ namespace fileSystemProvider {
// Raised when setting a new directory watcher is requested. If an error // Raised when setting a new directory watcher is requested. If an error
// occurs, then <code>errorCallback</code> must be called. // occurs, then <code>errorCallback</code> must be called.
[maxListeners=1, nodoc] static void onObserveDirectoryRequested( [maxListeners=1, nodoc] static void onAddWatcherRequested(
ObserveDirectoryRequestedOptions options, AddWatcherRequestedOptions options,
ProviderSuccessCallback successCallback, ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback); ProviderErrorCallback errorCallback);
// Raised when the entry should no longer be observed. If an error occurs, // Raised when the watcher should be removed. If an error occurs, then
// then <code>errorCallback</code> must be called. // <code>errorCallback</code> must be called.
[maxListeners=1, nodoc] static void onUnobserveEntryRequested( [maxListeners=1, nodoc] static void onRemoveWatcherRequested(
UnobserveEntryRequestedOptions options, RemoveWatcherRequestedOptions options,
ProviderSuccessCallback successCallback, ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback); ProviderErrorCallback errorCallback);
}; };
......
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