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

Unified Diff: chrome/browser/extensions/system_info_event_router.h

Issue 10836341: Add the basic code skeleton for system info event router (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add mock implementation for onAdded and onRemoved events Created 8 years, 4 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/extensions/system_info_event_router.h
diff --git a/chrome/browser/extensions/system_info_event_router.h b/chrome/browser/extensions/system_info_event_router.h
new file mode 100644
index 0000000000000000000000000000000000000000..788eef13279e854813bb80191756a1a7a1f4d709
--- /dev/null
+++ b/chrome/browser/extensions/system_info_event_router.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 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_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
+#define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/system_info_watcher.h"
+#include "chrome/browser/profiles/profile.h"
+
+namespace extensions {
+
+class SystemInfoWatcher;
+
+// Event router for systemInfo API. It is a singleton instance shared by
+// multiple profiles.
+class SystemInfoEventRouter : public SystemInfoWatcher::Observer {
+ public:
+ // The single instance of the event router.
+ static SystemInfoEventRouter* GetInstance();
+
+ // Add/remove event listener for the |event_name| event from |profile|.
+ void AddEventListener(Profile* profile, const std::string& event_name);
+ void RemoveEventListener(Profile* profile, const std::string& event_name);
+
+ // Return true if the |event_name| event is already being listened.
+ bool HasEventListener(const std::string& event_name);
+
+ private:
+ friend struct DefaultSingletonTraits<SystemInfoEventRouter>;
+
+ // Map of the profile and its events that are being listened.
+ typedef std::map<Profile*, std::set<std::string> > EventListenerMap;
+
+ SystemInfoEventRouter();
+ virtual ~SystemInfoEventRouter();
+
+ // SystemInfoWatcher::Observer overridens.
+ void OnStorageDeviceAvailableCapacityChanged(const std::string& id,
+ double available_capacity);
+ void OnStorageDeviceAdded(const std::string& id,
+ const std::string& type,
+ double capacity,
+ double available_capacity);
+ void OnStorageDeviceRemoved(const std::string& id);
+
+
+ // Dispatch systemInfo event to all profiles it observes.
+ void DispatchEvent(const std::string& event_name,
+ scoped_ptr<base::ListValue> args);
+
+ // The watcher for system information changes.
+ SystemInfoWatcher* system_info_watcher_;
+
+ EventListenerMap event_listener_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
+};
+
+} // namespace extensions
+#endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_

Powered by Google App Engine
This is Rietveld 408576698