| Index: chrome/browser/chromeos/file_system_provider/operations/operation.cc
|
| diff --git a/chrome/browser/chromeos/file_system_provider/operations/operation.cc b/chrome/browser/chromeos/file_system_provider/operations/operation.cc
|
| index dd35b465d29cff600de17db37dae4e54304b41ed..09cff1987b8e9f905b0f5d8815ffa5f612742c99 100644
|
| --- a/chrome/browser/chromeos/file_system_provider/operations/operation.cc
|
| +++ b/chrome/browser/chromeos/file_system_provider/operations/operation.cc
|
| @@ -4,19 +4,22 @@
|
|
|
| #include "chrome/browser/chromeos/file_system_provider/operations/operation.h"
|
|
|
| +#include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin_operation_router.h"
|
| #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
|
| +#include "chrome/browser/chromeos/file_system_provider/file_system_plugin/provided_file_system_adapter.h"
|
| #include "extensions/browser/event_router.h"
|
|
|
| namespace chromeos {
|
| namespace file_system_provider {
|
| namespace operations {
|
| namespace {
|
| -
|
| // Default implementation for dispatching an event. Can be replaced for unit
|
| // tests by Operation::SetDispatchEventImplForTest().
|
| -bool DispatchEventImpl(extensions::EventRouter* event_router,
|
| - const std::string& extension_id,
|
| - scoped_ptr<extensions::Event> event) {
|
| +template <class DestinationPolicy=ExtensionDestination>
|
| +bool DispatchEventImpl(
|
| + typename DestinationPolicy::EventRouterType* event_router,
|
| + const std::string& extension_id,
|
| + scoped_ptr<extensions::Event> event) {
|
| if (!event_router->ExtensionHasEventListener(extension_id, event->event_name))
|
| return false;
|
|
|
| @@ -24,31 +27,53 @@ bool DispatchEventImpl(extensions::EventRouter* event_router,
|
| return true;
|
| }
|
|
|
| +template <>
|
| +bool DispatchEventImpl<PluginDestination>(
|
| + typename PluginDestination::EventRouterType*
|
| + event_router,
|
| + const std::string& source_id,
|
| + scoped_ptr<extensions::Event> event) {
|
| + if (!event_router->PluginHasOperationListener(
|
| + ProvidedFileSystemAdapter::OperationTypeFromExtensionEvent(
|
| + event->event_name),
|
| + source_id))
|
| + return false;
|
| +
|
| + event_router->DispatchOperationToPlugin(source_id, event.Pass());
|
| + return true;
|
| +}
|
| +
|
| } // namespace
|
|
|
| -Operation::Operation(extensions::EventRouter* event_router,
|
| - const ProvidedFileSystemInfo& file_system_info)
|
| +template <class DestinationPolicy>
|
| +Operation<DestinationPolicy>::Operation(
|
| + typename DestinationPolicy::EventRouterType* event_router,
|
| + const ProvidedFileSystemInfo& file_system_info)
|
| : file_system_info_(file_system_info),
|
| - dispatch_event_impl_(base::Bind(&DispatchEventImpl,
|
| + dispatch_event_impl_(base::Bind(&DispatchEventImpl<DestinationPolicy>,
|
| event_router,
|
| - file_system_info_.extension_id())) {
|
| + file_system_info_.source_id())) {
|
| }
|
| -
|
| -Operation::~Operation() {
|
| +template <class DestinationPolicy>
|
| +Operation<DestinationPolicy>::~Operation() {
|
| }
|
|
|
| -void Operation::SetDispatchEventImplForTesting(
|
| +template <class DestinationPolicy>
|
| +void Operation<DestinationPolicy>::SetDispatchEventImplForTesting(
|
| const DispatchEventImplCallback& callback) {
|
| dispatch_event_impl_ = callback;
|
| }
|
|
|
| -bool Operation::SendEvent(int request_id,
|
| - const std::string& event_name,
|
| - scoped_ptr<base::ListValue> event_args) {
|
| +template <class DestinationPolicy>
|
| +bool Operation<DestinationPolicy>::SendEvent(int request_id,
|
| + const std::string& event_name,
|
| + scoped_ptr<base::ListValue> event_args) {
|
| return dispatch_event_impl_.Run(
|
| make_scoped_ptr(new extensions::Event(event_name, event_args.Pass())));
|
| }
|
|
|
| +FOR_EACH_DESTINATION_SPECIALIZE(Operation)
|
| +
|
| } // namespace operations
|
| } // namespace file_system_provider
|
| } // namespace chromeos
|
|
|