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