Chromium Code Reviews| 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..cfecd04ecf1ed9dc561f3abfb73c48659ad3ac41 |
| --- /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/file_path.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/profiles/profile.h" |
| + |
| +namespace extensions { |
| + |
| +// Event router for systemInfo API. It is a singleton instance shared by |
| +// multiple profiles. |
| +// TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver. |
| +// Since the system_monitor will be refactored along with media_gallery, once |
| +// http://crbug.com/145400 is fixed, We need to update SystemInfoEventRouter |
|
Mihai Parparita -not on Chrome
2012/08/31 01:01:00
Nit: lowercase the "We".
Hongbo Min
2012/08/31 15:29:53
Done.
|
| +// accordingly. |
| +class SystemInfoEventRouter { |
| + public: |
| + 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); |
| + |
| + // Return true if the |event_name| is an event from systemInfo namespace. |
| + static bool IsSystemInfoEvent(const std::string& event_name); |
| + |
| + // TODO(hongbo): The following methods should be likely overriden from |
| + // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400 |
| + // is fixed. |
| + void OnStorageAvailableCapacityChanged(const std::string& id, |
| + int64 available_capacity); |
| + void OnRemovableStorageAttached(const std::string& id, |
| + const string16& name, |
| + const FilePath::StringType& location); |
| + void OnRemovableStorageDetached(const std::string& id); |
| + |
| + private: |
| + friend struct DefaultSingletonTraits<SystemInfoEventRouter>; |
| + // Mapping of the profile and the event names that are being listened on it. |
| + typedef std::map<Profile*, std::set<std::string> > EventListenerMap; |
|
Mihai Parparita -not on Chrome
2012/08/31 01:01:00
I'm concerned about holding on to Profile pointers
Hongbo Min
2012/08/31 15:29:53
The ProfileManager::GetDefaultProfile is deprecate
Mihai Parparita -not on Chrome
2012/08/31 21:37:38
True. However, I'd still like to not worry about P
|
| + |
| + SystemInfoEventRouter(); |
| + virtual ~SystemInfoEventRouter(); |
| + |
| + // Called on the UI thread to dispatch the systemInfo event to all extension |
| + // processes cross multiple profiles. |
| + void DispatchEvent(const std::string& event_name, |
| + const base::ListValue& args); |
| + |
| + EventListenerMap event_listener_map_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); |
| +}; |
| + |
| +} // namespace extensions |
| +#endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ |