Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/operations/operation.cc

Issue 1093383002: [WIP] Provided file system from NACL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved several modules to chromeos folder. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/file_system_provider/operations/operation.h" 5 #include "chrome/browser/chromeos/file_system_provider/operations/operation.h"
6 6
7 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin _operation_router.h"
7 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 8 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
9 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/provid ed_file_system_adapter.h"
8 #include "extensions/browser/event_router.h" 10 #include "extensions/browser/event_router.h"
9 11
10 namespace chromeos { 12 namespace chromeos {
11 namespace file_system_provider { 13 namespace file_system_provider {
12 namespace operations { 14 namespace operations {
13 namespace { 15 namespace {
14
15 // Default implementation for dispatching an event. Can be replaced for unit 16 // Default implementation for dispatching an event. Can be replaced for unit
16 // tests by Operation::SetDispatchEventImplForTest(). 17 // tests by Operation::SetDispatchEventImplForTest().
17 bool DispatchEventImpl(extensions::EventRouter* event_router, 18 template <class DestinationPolicy=ExtensionDestination>
18 const std::string& extension_id, 19 bool DispatchEventImpl(
19 scoped_ptr<extensions::Event> event) { 20 typename DestinationPolicy::EventRouterType* event_router,
21 const std::string& extension_id,
22 scoped_ptr<extensions::Event> event) {
20 if (!event_router->ExtensionHasEventListener(extension_id, event->event_name)) 23 if (!event_router->ExtensionHasEventListener(extension_id, event->event_name))
21 return false; 24 return false;
22 25
23 event_router->DispatchEventToExtension(extension_id, event.Pass()); 26 event_router->DispatchEventToExtension(extension_id, event.Pass());
24 return true; 27 return true;
25 } 28 }
26 29
30 template <>
31 bool DispatchEventImpl<PluginDestination>(
32 typename PluginDestination::EventRouterType*
33 event_router,
34 const std::string& source_id,
35 scoped_ptr<extensions::Event> event) {
36 if (!event_router->PluginHasOperationListener(
37 ProvidedFileSystemAdapter::OperationTypeFromExtensionEvent(
38 event->event_name),
39 source_id))
40 return false;
41
42 event_router->DispatchOperationToPlugin(source_id, event.Pass());
43 return true;
44 }
45
27 } // namespace 46 } // namespace
28 47
29 Operation::Operation(extensions::EventRouter* event_router, 48 template <class DestinationPolicy>
30 const ProvidedFileSystemInfo& file_system_info) 49 Operation<DestinationPolicy>::Operation(
50 typename DestinationPolicy::EventRouterType* event_router,
51 const ProvidedFileSystemInfo& file_system_info)
31 : file_system_info_(file_system_info), 52 : file_system_info_(file_system_info),
32 dispatch_event_impl_(base::Bind(&DispatchEventImpl, 53 dispatch_event_impl_(base::Bind(&DispatchEventImpl<DestinationPolicy>,
33 event_router, 54 event_router,
34 file_system_info_.extension_id())) { 55 file_system_info_.source_id())) {
56 }
57 template <class DestinationPolicy>
58 Operation<DestinationPolicy>::~Operation() {
35 } 59 }
36 60
37 Operation::~Operation() { 61 template <class DestinationPolicy>
38 } 62 void Operation<DestinationPolicy>::SetDispatchEventImplForTesting(
39
40 void Operation::SetDispatchEventImplForTesting(
41 const DispatchEventImplCallback& callback) { 63 const DispatchEventImplCallback& callback) {
42 dispatch_event_impl_ = callback; 64 dispatch_event_impl_ = callback;
43 } 65 }
44 66
45 bool Operation::SendEvent(int request_id, 67 template <class DestinationPolicy>
46 const std::string& event_name, 68 bool Operation<DestinationPolicy>::SendEvent(int request_id,
47 scoped_ptr<base::ListValue> event_args) { 69 const std::string& event_name,
70 scoped_ptr<base::ListValue> event_args) {
48 return dispatch_event_impl_.Run( 71 return dispatch_event_impl_.Run(
49 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass()))); 72 make_scoped_ptr(new extensions::Event(event_name, event_args.Pass())));
50 } 73 }
51 74
75 FOR_EACH_DESTINATION_SPECIALIZE(Operation)
76
52 } // namespace operations 77 } // namespace operations
53 } // namespace file_system_provider 78 } // namespace file_system_provider
54 } // namespace chromeos 79 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698