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

Unified Diff: chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h

Issue 1093383002: [WIP] Provided file system from NACL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Various cleanups Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h
diff --git a/chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h b/chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h
new file mode 100644
index 0000000000000000000000000000000000000000..9e5cc63beeea92f1887cbc600754b6fbdfabb737
--- /dev/null
+++ b/chrome/browser/chromeos/file_system_provider/file_system_plugin/plugineventrouter.h
@@ -0,0 +1,132 @@
+// 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_FILE_SYSTEM_PLUGIN_PLUGINEVENTROUTER_H_
+#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PLUGIN_PLUGINEVENTROUTER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+
+#include "ppapi/host/resource_host.h"
+
+template <typename T>
+struct DefaultSingletonTraits;
+
+namespace extensions {
+struct Event;
+} // namespace extensions
+
+namespace chromeos {
+
+class EventToPluginList;
+class PluginListeningInstances;
+
+class PluginEventRouter {
+ public:
+ class PluginEventRouterClient {
+ virtual void OnDispatchEvent(std::string event_name,
+ scoped_ptr<base::ListValue> event_args) {}
+ friend class PluginListeningInstances;
+ };
+
+ static PluginEventRouter* GetInstance();
+ // Register and array of events for a plugin
+ void AddEventsListener(const std::vector<std::string>& event_names,
+ PluginEventRouterClient* plugin_ref,
+ const std::string& plugin_id);
+ // Register a single event for the plugin
+ void AddEventListener(const std::string& event_name,
+ PluginEventRouterClient* plugin_ref,
+ const std::string& plugin_id);
+ // Remove an array of events at a time
+ void RemoveEventsListeners(const std::vector<std::string>& event_names,
+ PluginEventRouterClient* plugin_ref,
+ const std::string& plugin_id);
+ // Remove a single event
+ void RemoveEventListener(const std::string& event_name,
+ PluginEventRouterClient* plugin_process,
+ const std::string& plugin_id);
+
+ // Does the router have any listener on this event
+ bool HasEventListener(const std::string& event_name);
+
+ // Does a specific plugin have the event registered
+ bool PluginHasEventListener(const std::string& event_name,
+ const std::string& plugin_id);
+ void DispatchEventToPlugin(const std::string& plugin_id,
+ scoped_ptr<extensions::Event> event);
+
+ private:
+ PluginEventRouter();
+ ~PluginEventRouter();
+ friend struct DefaultSingletonTraits<PluginEventRouter>;
+
+ // [event_name] = map[plugin1, plugin2]
+ typedef std::map<std::string, EventToPluginList> EventList;
+ typedef EventList::iterator EventListIterator;
+ EventList listOfListenedEvents_;
+
+ base::WeakPtrFactory<PluginEventRouter> weak_ptr_factory_;
+ DISALLOW_COPY_AND_ASSIGN(PluginEventRouter);
+};
+
+class PluginListeningInstances {
+ public:
+ PluginListeningInstances(
+ const std::string& plugin_id,
+ PluginEventRouter::PluginEventRouterClient* instance_);
+ ~PluginListeningInstances();
+
+ void AddPluginInstance(PluginEventRouter::PluginEventRouterClient* instance);
+ void RemovePluginInstance(
+ PluginEventRouter::PluginEventRouterClient* instance);
+ bool Empty();
+ void DispatchEvent(std::string event_name,
+ scoped_ptr<base::ListValue> event_args);
+
+ protected:
+ std::string plugin_id_;
+ typedef std::set<PluginEventRouter::PluginEventRouterClient*> SetOfInstances;
+ typedef SetOfInstances::iterator SetOfInstancesIterator;
+ SetOfInstances plugin_instances_;
+};
+
+class EventToPluginList {
+ public:
+ EventToPluginList(const std::string& event_name,
+ const std::string& plugin_id,
+ PluginEventRouter::PluginEventRouterClient* instance);
+ ~EventToPluginList();
+
+ void AddPluginInstance(const std::string& plugin_id,
+ PluginEventRouter::PluginEventRouterClient* instance);
+ void RemovePluginInstance(
+ const std::string& plugin_id,
+ PluginEventRouter::PluginEventRouterClient* instance);
+ bool Empty();
+
+ bool HasPlugin(const std::string& plugin_id);
+
+ void DispatchEventToPlugin(std::string plugin_id,
+ std::string event_name,
+ scoped_ptr<base::ListValue> event_args);
+
+ protected:
+ std::string event_name_;
+ // [plugin_id] = set[ instance_1, instance_2 ]
+ typedef std::map<std::string, PluginListeningInstances> ListOfPlugins;
+ typedef ListOfPlugins::iterator PluginListIterator;
+ ListOfPlugins plugin_list_;
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PLUGIN_PLUGINEVENTROUTER_H_

Powered by Google App Engine
This is Rietveld 408576698