| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/system_info/system_info_api.h" | 5 #include "chrome/browser/extensions/api/system_info/system_info_api.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 SystemInfoEventRouter(); | 60 SystemInfoEventRouter(); |
| 61 virtual ~SystemInfoEventRouter(); | 61 virtual ~SystemInfoEventRouter(); |
| 62 | 62 |
| 63 // Add/remove event listener for the |event_name| event. | 63 // Add/remove event listener for the |event_name| event. |
| 64 void AddEventListener(const std::string& event_name); | 64 void AddEventListener(const std::string& event_name); |
| 65 void RemoveEventListener(const std::string& event_name); | 65 void RemoveEventListener(const std::string& event_name); |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // gfx::DisplayObserver: | 68 // gfx::DisplayObserver: |
| 69 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; | |
| 70 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; | 69 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; |
| 71 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; | 70 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; |
| 71 virtual void OnDisplayMetricsChanged(const gfx::Display& display, |
| 72 DisplayObserver::MetricsType metrics) OVERRIDE; |
| 72 | 73 |
| 73 // RemovableStorageObserver implementation. | 74 // RemovableStorageObserver implementation. |
| 74 virtual void OnRemovableStorageAttached( | 75 virtual void OnRemovableStorageAttached( |
| 75 const storage_monitor::StorageInfo& info) OVERRIDE; | 76 const storage_monitor::StorageInfo& info) OVERRIDE; |
| 76 virtual void OnRemovableStorageDetached( | 77 virtual void OnRemovableStorageDetached( |
| 77 const storage_monitor::StorageInfo& info) OVERRIDE; | 78 const storage_monitor::StorageInfo& info) OVERRIDE; |
| 78 | 79 |
| 79 // Called from any thread to dispatch the systemInfo event to all extension | 80 // Called from any thread to dispatch the systemInfo event to all extension |
| 80 // processes cross multiple profiles. | 81 // processes cross multiple profiles. |
| 81 void DispatchEvent(const std::string& event_name, | 82 void DispatchEvent(const std::string& event_name, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 const storage_monitor::StorageInfo& info) { | 176 const storage_monitor::StorageInfo& info) { |
| 176 scoped_ptr<base::ListValue> args(new base::ListValue); | 177 scoped_ptr<base::ListValue> args(new base::ListValue); |
| 177 std::string transient_id = | 178 std::string transient_id = |
| 178 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 179 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
| 179 info.device_id()); | 180 info.device_id()); |
| 180 args->AppendString(transient_id); | 181 args->AppendString(transient_id); |
| 181 | 182 |
| 182 DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); | 183 DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 void SystemInfoEventRouter::OnDisplayBoundsChanged( | |
| 186 const gfx::Display& display) { | |
| 187 OnDisplayChanged(); | |
| 188 } | |
| 189 | |
| 190 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { | 186 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { |
| 191 OnDisplayChanged(); | 187 OnDisplayChanged(); |
| 192 } | 188 } |
| 193 | 189 |
| 194 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { | 190 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { |
| 195 OnDisplayChanged(); | 191 OnDisplayChanged(); |
| 196 } | 192 } |
| 197 | 193 |
| 194 void SystemInfoEventRouter::OnDisplayMetricsChanged( |
| 195 const gfx::Display&, DisplayObserver::MetricsType) { |
| 196 OnDisplayChanged(); |
| 197 } |
| 198 |
| 198 void SystemInfoEventRouter::OnDisplayChanged() { | 199 void SystemInfoEventRouter::OnDisplayChanged() { |
| 199 scoped_ptr<base::ListValue> args(new base::ListValue()); | 200 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 200 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); | 201 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, | 204 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, |
| 204 scoped_ptr<base::ListValue> args) { | 205 scoped_ptr<base::ListValue> args) { |
| 205 g_browser_process->extension_event_router_forwarder()-> | 206 g_browser_process->extension_event_router_forwarder()-> |
| 206 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); | 207 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); |
| 207 } | 208 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 253 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 253 if (IsSystemStorageEvent(details.event_name)) { | 254 if (IsSystemStorageEvent(details.event_name)) { |
| 254 StorageMonitor::GetInstance()->EnsureInitialized( | 255 StorageMonitor::GetInstance()->EnsureInitialized( |
| 255 base::Bind(&RemoveEventListener, details.event_name)); | 256 base::Bind(&RemoveEventListener, details.event_name)); |
| 256 } else { | 257 } else { |
| 257 RemoveEventListener(details.event_name); | 258 RemoveEventListener(details.event_name); |
| 258 } | 259 } |
| 259 } | 260 } |
| 260 | 261 |
| 261 } // namespace extensions | 262 } // namespace extensions |
| OLD | NEW |