Commit 3d79d9d3 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski

Add events for configuring and adding new providers to FSP API.

According to the newest mocks, the file systems will be managable from Files
app. In order to do that, both of the events are required.

TEST=None.
BUG=474146
R=benwells@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#325379}
parent 718df167
......@@ -372,6 +372,12 @@ void FakeProvidedFileSystem::Notify(
callback.Run(base::File::FILE_ERROR_SECURITY);
}
void FakeProvidedFileSystem::Configure(
const storage::AsyncFileUtil::StatusCallback& callback) {
NOTREACHED();
callback.Run(base::File::FILE_ERROR_SECURITY);
}
ProvidedFileSystemInterface* FakeProvidedFileSystem::Create(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) {
......
......@@ -154,6 +154,8 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
const std::string& tag,
const storage::AsyncFileUtil::StatusCallback& callback) override;
void Configure(
const storage::AsyncFileUtil::StatusCallback& callback) override;
base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
// Factory callback, to be used in Service::SetFileSystemFactory(). The
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/configure.h"
#include "base/values.h"
#include "chrome/common/extensions/api/file_system_provider.h"
namespace chromeos {
namespace file_system_provider {
namespace operations {
Configure::Configure(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info,
const storage::AsyncFileUtil::StatusCallback& callback)
: Operation(event_router, file_system_info), callback_(callback) {
}
Configure::~Configure() {
}
bool Configure::Execute(int request_id) {
using extensions::api::file_system_provider::ConfigureRequestedOptions;
ConfigureRequestedOptions options;
options.file_system_id = file_system_info_.file_system_id();
options.request_id = request_id;
return SendEvent(
request_id,
extensions::api::file_system_provider::OnConfigureRequested::kEventName,
extensions::api::file_system_provider::OnConfigureRequested::Create(
options));
}
void Configure::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> /* result */,
bool /* has_more */) {
callback_.Run(base::File::FILE_OK);
}
void Configure::OnError(int /* request_id */,
scoped_ptr<RequestValue> /* result */,
base::File::Error error) {
callback_.Run(error);
}
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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_CONFIGURE_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_CONFIGURE_H_
#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/operations/operation.h"
#include "storage/browser/fileapi/async_file_util.h"
namespace base {
class DictionaryValue;
} // namespace base
namespace extensions {
class EventRouter;
} // namespace extensions
namespace chromeos {
namespace file_system_provider {
class ProvidedFileSystemInfo;
namespace operations {
// Bridge between fileManagerPrivate's configure operation and providing
// extension's configure request. Created per request.
class Configure : public Operation {
public:
Configure(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info,
const storage::AsyncFileUtil::StatusCallback& callback);
~Configure() override;
// Operation overrides.
bool Execute(int request_id) override;
void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_more) override;
void OnError(int request_id,
scoped_ptr<RequestValue> result,
base::File::Error error) override;
private:
const storage::AsyncFileUtil::StatusCallback callback_;
DISALLOW_COPY_AND_ASSIGN(Configure);
};
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_CONFIGURE_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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/configure.h"
#include <string>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/common/extensions/api/file_system_provider.h"
#include "chrome/common/extensions/api/file_system_provider_internal.h"
#include "extensions/browser/event_router.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace file_system_provider {
namespace operations {
namespace {
const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
const char kFileSystemId[] = "testing-file-system";
const int kRequestId = 2;
} // namespace
class FileSystemProviderOperationsConfigureTest : public testing::Test {
protected:
FileSystemProviderOperationsConfigureTest() {}
~FileSystemProviderOperationsConfigureTest() override {}
void SetUp() override {
file_system_info_ = ProvidedFileSystemInfo(
kExtensionId, MountOptions(kFileSystemId, "" /* display_name */),
base::FilePath());
}
ProvidedFileSystemInfo file_system_info_;
};
TEST_F(FileSystemProviderOperationsConfigureTest, Execute) {
using extensions::api::file_system_provider::ConfigureRequestedOptions;
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
Configure configure(NULL, file_system_info_,
base::Bind(&util::LogStatusCallback, &callback_log));
configure.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(configure.Execute(kRequestId));
ASSERT_EQ(1u, dispatcher.events().size());
extensions::Event* event = dispatcher.events()[0];
EXPECT_EQ(
extensions::api::file_system_provider::OnConfigureRequested::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));
ConfigureRequestedOptions options;
ASSERT_TRUE(ConfigureRequestedOptions::Populate(*options_as_value, &options));
EXPECT_EQ(kFileSystemId, options.file_system_id);
EXPECT_EQ(kRequestId, options.request_id);
}
TEST_F(FileSystemProviderOperationsConfigureTest, Execute_NoListener) {
util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
util::StatusCallbackLog callback_log;
Configure configure(NULL, file_system_info_,
base::Bind(&util::LogStatusCallback, &callback_log));
configure.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_FALSE(configure.Execute(kRequestId));
}
TEST_F(FileSystemProviderOperationsConfigureTest, OnSuccess) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
Configure configure(NULL, file_system_info_,
base::Bind(&util::LogStatusCallback, &callback_log));
configure.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(configure.Execute(kRequestId));
configure.OnSuccess(kRequestId, scoped_ptr<RequestValue>(new RequestValue()),
false /* has_more */);
ASSERT_EQ(1u, callback_log.size());
base::File::Error event_result = callback_log[0];
EXPECT_EQ(base::File::FILE_OK, event_result);
}
TEST_F(FileSystemProviderOperationsConfigureTest, OnError) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
Configure configure(NULL, file_system_info_,
base::Bind(&util::LogStatusCallback, &callback_log));
configure.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(configure.Execute(kRequestId));
configure.OnError(kRequestId, scoped_ptr<RequestValue>(new RequestValue()),
base::File::FILE_ERROR_NOT_FOUND);
ASSERT_EQ(1u, callback_log.size());
base::File::Error event_result = callback_log[0];
EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, event_result);
}
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
......@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/file_system_provider/operations/abort.h"
#include "chrome/browser/chromeos/file_system_provider/operations/add_watcher.h"
#include "chrome/browser/chromeos/file_system_provider/operations/close_file.h"
#include "chrome/browser/chromeos/file_system_provider/operations/configure.h"
#include "chrome/browser/chromeos/file_system_provider/operations/copy_entry.h"
#include "chrome/browser/chromeos/file_system_provider/operations/create_directory.h"
#include "chrome/browser/chromeos/file_system_provider/operations/create_file.h"
......@@ -490,6 +491,16 @@ void ProvidedFileSystem::Notify(
changes.Pass(), tag, callback)))));
}
void ProvidedFileSystem::Configure(
const storage::AsyncFileUtil::StatusCallback& callback) {
const int request_id = request_manager_->CreateRequest(
CONFIGURE,
scoped_ptr<RequestManager::HandlerInterface>(new operations::Configure(
event_router_, file_system_info_, callback)));
if (!request_id)
callback.Run(base::File::FILE_ERROR_SECURITY);
}
void ProvidedFileSystem::Abort(int operation_request_id) {
request_manager_->RejectRequest(operation_request_id,
make_scoped_ptr(new RequestValue()),
......
......@@ -163,6 +163,8 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
const std::string& tag,
const storage::AsyncFileUtil::StatusCallback& callback) override;
void Configure(
const storage::AsyncFileUtil::StatusCallback& callback) override;
base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
private:
......
......@@ -218,6 +218,12 @@ class ProvidedFileSystemInterface {
const std::string& tag,
const storage::AsyncFileUtil::StatusCallback& callback) = 0;
// Requests showing UI for configuring the file system by user. Once the
// configuration process is completed, base::File::FILE_OK or an error code is
// returned via the |callback|.
virtual void Configure(
const storage::AsyncFileUtil::StatusCallback& callback) = 0;
// Returns a provided file system info for this file system.
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0;
......
......@@ -52,6 +52,8 @@ std::string RequestTypeToString(RequestType type) {
return "ADD_WATCHER";
case REMOVE_WATCHER:
return "REMOVE_WATCHER";
case CONFIGURE:
return "CONFIGURE";
case TESTING:
return "TESTING";
}
......
......@@ -41,6 +41,7 @@ enum RequestType {
ABORT,
ADD_WATCHER,
REMOVE_WATCHER,
CONFIGURE,
TESTING
};
......
......@@ -8,6 +8,7 @@
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
#include "chrome/browser/chromeos/file_system_provider/observer.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
......@@ -16,6 +17,7 @@
#include "chrome/browser/chromeos/file_system_provider/registry_interface.h"
#include "chrome/browser/chromeos/file_system_provider/service_factory.h"
#include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "storage/browser/fileapi/external_mount_points.h"
......@@ -245,6 +247,28 @@ bool Service::RequestUnmount(const std::string& extension_id,
return true;
}
bool Service::RequestMount(const std::string& extension_id) {
DCHECK(thread_checker_.CalledOnValidThread());
extensions::EventRouter* const event_router =
extensions::EventRouter::Get(profile_);
DCHECK(event_router);
if (!event_router->ExtensionHasEventListener(
extension_id, extensions::api::file_system_provider::
OnMountRequested::kEventName)) {
return false;
}
event_router->DispatchEventToExtension(
extension_id,
make_scoped_ptr(new extensions::Event(
extensions::api::file_system_provider::OnMountRequested::kEventName,
scoped_ptr<base::ListValue>(nullptr))));
return true;
}
std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() {
DCHECK(thread_checker_.CalledOnValidThread());
......
......@@ -93,12 +93,16 @@ class Service : public KeyedService,
const std::string& file_system_id,
UnmountReason reason);
// Requests unmounting of the file system. The callback is called when the
// request is accepted or rejected, with an error code. Returns false if the
// request could not been created, true otherwise.
// Requests unmounting of the file system. Returns false if the request could
// not been created, true otherwise.
bool RequestUnmount(const std::string& extension_id,
const std::string& file_system_id);
// Requests mounting a new file system by the providing extension with
// |extension_id|. Returns false if the request could not been created, true
// otherwise.
bool RequestMount(const std::string& extension_id);
// Returns a list of information of all currently provided file systems. All
// items are copied.
std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList();
......
......@@ -183,6 +183,11 @@ void ThrottledFileSystem::Notify(
changes.Pass(), tag, callback);
}
void ThrottledFileSystem::Configure(
const storage::AsyncFileUtil::StatusCallback& callback) {
return file_system_->Configure(callback);
}
base::WeakPtr<ProvidedFileSystemInterface> ThrottledFileSystem::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
......
......@@ -117,6 +117,8 @@ class ThrottledFileSystem : public ProvidedFileSystemInterface {
scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
const std::string& tag,
const storage::AsyncFileUtil::StatusCallback& callback) override;
void Configure(
const storage::AsyncFileUtil::StatusCallback& callback) override;
base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
private:
......
......@@ -290,6 +290,8 @@
'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/configure.cc',
'browser/chromeos/file_system_provider/operations/configure.h',
'browser/chromeos/file_system_provider/operations/copy_entry.cc',
'browser/chromeos/file_system_provider/operations/copy_entry.h',
'browser/chromeos/file_system_provider/operations/create_directory.cc',
......
......@@ -1204,6 +1204,7 @@
'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/close_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/configure_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_file_unittest.cc',
......
......@@ -44,7 +44,7 @@ namespace fileSystemProvider {
// Source of the file system data.
enum FileSystemSource {
// The file system is handling a file, eg. an archive file obtained via the
// <code>OnLaunched</code> event and the <code>file_handlers</code> manifest
// <code>onLaunched</code> event and the <code>file_handlers</code> manifest
// entry.
FILE,
......@@ -171,6 +171,8 @@ namespace fileSystemProvider {
dictionary UnmountRequestedOptions {
// The identifier of the file system to be unmounted.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
};
......@@ -432,6 +434,15 @@ namespace fileSystemProvider {
DOMString? tag;
};
// Options for the <code>onConfigureRequested()</code> event.
[nodoc] dictionary ConfigureRequestedOptions {
// The identifier of the file system to be configured.
DOMString fileSystemId;
// The unique identifier of this request.
long requestId;
};
// Callback to receive the result of getAll() function.
callback GetAllCallback = void(FileSystemInfo[] fileSystems);
......@@ -647,6 +658,21 @@ namespace fileSystemProvider {
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when showing a configuration dialog for <code>fileSystemId</code>
// is requested. If it's not supported, then this event must not be handled.
[maxListeners=1, nodoc] static void onConfigureRequested(
ConfigureRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// Raised when showing a dialog for mounting a new file system is requested.
// If the extension/app is a file handler, then this event shouldn't be
// handled. Instead <code>onLaunched</code> should be handled in order to
// mount new file systems when a file is opened.
[maxListeners=1, nodoc] static void onMountRequested(
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
// 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 onAddWatcherRequested(
......
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