Chromium Code Reviews| Index: chrome/browser/extensions/api/system_info/system_info_api.cc |
| =================================================================== |
| --- chrome/browser/extensions/api/system_info/system_info_api.cc (revision 245000) |
| +++ chrome/browser/extensions/api/system_info/system_info_api.cc (working copy) |
| @@ -68,7 +68,7 @@ |
| // Called from any thread to dispatch the systemInfo event to all extension |
| // processes cross multiple profiles. |
| void DispatchEvent(const std::string& event_name, |
| - scoped_ptr<base::ListValue> args); |
| + scoped_ptr<base::ListValue> args); |
| // Called to dispatch the systemInfo.display.onDisplayChanged event. |
| void OnDisplayChanged(); |
| @@ -89,7 +89,6 @@ |
| SystemInfoEventRouter::SystemInfoEventRouter() { |
| StorageMonitor::GetInstance()->AddObserver(this); |
| - StorageMonitor::GetInstance()->EnsureInitialized(base::Closure()); |
| } |
| SystemInfoEventRouter::~SystemInfoEventRouter() { |
| @@ -112,8 +111,7 @@ |
| } |
| } |
| -void SystemInfoEventRouter::RemoveEventListener( |
| - const std::string& event_name) { |
| +void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| std::multiset<std::string>::iterator it = |
| @@ -173,6 +171,16 @@ |
| BroadcastEventToRenderers(event_name, args.Pass(), GURL()); |
| } |
|
Haojian Wu
2014/01/16 06:53:27
Some performance concerns: everytime we add an sys
Lei Zhang
2014/01/16 23:24:11
See patch set 2.
|
| +void AddEventListener(const std::string& event_name) { |
| + DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| + SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); |
| +} |
| + |
| +void RemoveEventListener(const std::string& event_name) { |
| + DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
| + SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); |
| +} |
| + |
| } // namespace |
| static base::LazyInstance<ProfileKeyedAPIFactory<SystemInfoAPI> > |
| @@ -200,11 +208,13 @@ |
| } |
| void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { |
| - SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); |
| + StorageMonitor::GetInstance()->EnsureInitialized( |
| + base::Bind(&AddEventListener, details.event_name)); |
| } |
| void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| - SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); |
| + StorageMonitor::GetInstance()->EnsureInitialized( |
| + base::Bind(&RemoveEventListener, details.event_name)); |
| } |
| } // namespace extensions |