Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ | |
| 7 | |
| 8 #include "base/file_path.h" | |
| 9 #include "base/memory/singleton.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 | |
| 13 namespace extensions { | |
| 14 | |
| 15 // Event router for systemInfo API. It is a singleton instance shared by | |
| 16 // multiple profiles. | |
| 17 // TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver. | |
| 18 // Since the system_monitor will be refactored along with media_gallery, once | |
| 19 // 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.
| |
| 20 // accordingly. | |
| 21 class SystemInfoEventRouter { | |
| 22 public: | |
| 23 static SystemInfoEventRouter* GetInstance(); | |
| 24 | |
| 25 // Add/remove event listener for the |event_name| event from |profile|. | |
| 26 void AddEventListener(Profile* profile, const std::string& event_name); | |
| 27 void RemoveEventListener(Profile* profile, const std::string& event_name); | |
| 28 | |
| 29 // Return true if the |event_name| event is already being listened. | |
| 30 bool HasEventListener(const std::string& event_name); | |
| 31 | |
| 32 // Return true if the |event_name| is an event from systemInfo namespace. | |
| 33 static bool IsSystemInfoEvent(const std::string& event_name); | |
| 34 | |
| 35 // TODO(hongbo): The following methods should be likely overriden from | |
| 36 // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400 | |
| 37 // is fixed. | |
| 38 void OnStorageAvailableCapacityChanged(const std::string& id, | |
| 39 int64 available_capacity); | |
| 40 void OnRemovableStorageAttached(const std::string& id, | |
| 41 const string16& name, | |
| 42 const FilePath::StringType& location); | |
| 43 void OnRemovableStorageDetached(const std::string& id); | |
| 44 | |
| 45 private: | |
| 46 friend struct DefaultSingletonTraits<SystemInfoEventRouter>; | |
| 47 // Mapping of the profile and the event names that are being listened on it. | |
| 48 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
| |
| 49 | |
| 50 SystemInfoEventRouter(); | |
| 51 virtual ~SystemInfoEventRouter(); | |
| 52 | |
| 53 // Called on the UI thread to dispatch the systemInfo event to all extension | |
| 54 // processes cross multiple profiles. | |
| 55 void DispatchEvent(const std::string& event_name, | |
| 56 const base::ListValue& args); | |
| 57 | |
| 58 EventListenerMap event_listener_map_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); | |
| 61 }; | |
| 62 | |
| 63 } // namespace extensions | |
| 64 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ | |
| OLD | NEW |