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