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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin_operation_router.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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin _operation_router.h"
6
7 #include "base/memory/singleton.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "extensions/browser/event_router.h"
10
11 using content::BrowserThread;
12 using extensions::Event;
13
14 namespace chromeos {
15 namespace file_system_provider {
16 PluginOperationRouter::PluginOperationRouter() : weak_ptr_factory_(this) {
17 }
18
19 PluginOperationRouter::~PluginOperationRouter() {
20 }
21
22 // Static
23 PluginOperationRouter* PluginOperationRouter::GetInstance() {
24 return Singleton<PluginOperationRouter>::get();
25 }
26
27 void PluginOperationRouter::AddOperationsForListener(
28 const std::vector<RequestType>& operation_types,
29 PluginOperationRouterClient* plugin_ref,
30 const std::string& plugin_id) {
31 DCHECK_CURRENTLY_ON(BrowserThread::IO);
32 for (
33 std::vector<RequestType>::const_iterator it =
34 operation_types.begin();
35 it != operation_types.end(); ++it) {
36 AddOperationForListener(*it, plugin_ref, plugin_id);
37 }
38 }
39
40 void PluginOperationRouter::AddOperationForListener(
41 RequestType operation_type,
42 PluginOperationRouterClient* plugin_ref,
43 const std::string& plugin_id) {
44 DCHECK_CURRENTLY_ON(BrowserThread::IO);
45 OperationsListIterator it = listOfListenedEvents_.find(operation_type);
46 // If the event is not in the list add it
47 if (it == listOfListenedEvents_.end()) {
48 it = listOfListenedEvents_.insert(listOfListenedEvents_.begin(),
49 std::make_pair(operation_type,
50 PluginInstances() ) );
51 }
52 it->second.insert( std::make_pair(plugin_id, plugin_ref) );
53 }
54
55 void PluginOperationRouter::RemoveOperationsForListener(
56 const std::vector<RequestType>& operation_types,
57 const std::string& plugin_id) {
58 DCHECK_CURRENTLY_ON(BrowserThread::IO);
59 for (std::vector<RequestType>::const_iterator
60 it = operation_types.begin();
61 it != operation_types.end(); ++it) {
62 RemoveOperationForListener(*it, plugin_id);
63 }
64 }
65
66 void PluginOperationRouter::RemoveOperationForListener(
67 RequestType operation_type,
68 const std::string& plugin_id) {
69 DCHECK_CURRENTLY_ON(BrowserThread::IO);
70 OperationsListIterator it = listOfListenedEvents_.find(operation_type);
71
72 if (it!=listOfListenedEvents_.end()) {
73 PluginInstancesIterator plugin_it = it->second.find(plugin_id);
74 if (plugin_it!=it->second.end())
75 it->second.erase(plugin_it);
76 if(it->second.size()==0)
77 listOfListenedEvents_.erase(it);
78 }
79 }
80
81 bool PluginOperationRouter::PluginHasOperationListener(
82 RequestType operation_type,
83 const std::string& plugin_id) {
84 OperationsListIterator it = listOfListenedEvents_.find(operation_type);
85 if (it != listOfListenedEvents_.end())
86 return it->second.find(plugin_id)!=it->second.end();
87 return false;
88 }
89
90 void PluginOperationRouter::DispatchOperationToPlugin(
91 const std::string& plugin_id,
92 scoped_ptr<extensions::Event> request) {
93 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
94 BrowserThread::PostTask(
95 BrowserThread::IO, FROM_HERE,
96 base::Bind(
97 base::IgnoreResult(&PluginOperationRouter::DispatchOperationToPlugin ),
98 weak_ptr_factory_.GetWeakPtr(), plugin_id,
99 base::Passed(request.Pass())));
100 return;
101 }
102 RequestType type = ProvidedFileSystemAdapter::OperationTypeFromExtensionEvent(
103 request->event_name);
104 OperationsListIterator it = listOfListenedEvents_.find(type);
105 if (it != listOfListenedEvents_.end()) {
106 PluginInstancesIterator plugin_it = it->second.find( plugin_id );
107 if (plugin_it!=it->second.end())
108 plugin_it->second->OnDispatchOperationRequest(type,
109 request->event_args.Pass());
110 }
111 }
112 } // namespace file_system_provider
113 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698