| 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( |
| 72 const gfx::Display& display, |
| 73 DisplayObserver::DisplayMetrics metrics) OVERRIDE; |
| 72 | 74 |
| 73 // RemovableStorageObserver implementation. | 75 // RemovableStorageObserver implementation. |
| 74 virtual void OnRemovableStorageAttached( | 76 virtual void OnRemovableStorageAttached( |
| 75 const storage_monitor::StorageInfo& info) OVERRIDE; | 77 const storage_monitor::StorageInfo& info) OVERRIDE; |
| 76 virtual void OnRemovableStorageDetached( | 78 virtual void OnRemovableStorageDetached( |
| 77 const storage_monitor::StorageInfo& info) OVERRIDE; | 79 const storage_monitor::StorageInfo& info) OVERRIDE; |
| 78 | 80 |
| 79 // Called from any thread to dispatch the systemInfo event to all extension | 81 // Called from any thread to dispatch the systemInfo event to all extension |
| 80 // processes cross multiple profiles. | 82 // processes cross multiple profiles. |
| 81 void DispatchEvent(const std::string& event_name, | 83 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) { | 177 const storage_monitor::StorageInfo& info) { |
| 176 scoped_ptr<base::ListValue> args(new base::ListValue); | 178 scoped_ptr<base::ListValue> args(new base::ListValue); |
| 177 std::string transient_id = | 179 std::string transient_id = |
| 178 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 180 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
| 179 info.device_id()); | 181 info.device_id()); |
| 180 args->AppendString(transient_id); | 182 args->AppendString(transient_id); |
| 181 | 183 |
| 182 DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); | 184 DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); |
| 183 } | 185 } |
| 184 | 186 |
| 185 void SystemInfoEventRouter::OnDisplayBoundsChanged( | |
| 186 const gfx::Display& display) { | |
| 187 OnDisplayChanged(); | |
| 188 } | |
| 189 | |
| 190 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { | 187 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { |
| 191 OnDisplayChanged(); | 188 OnDisplayChanged(); |
| 192 } | 189 } |
| 193 | 190 |
| 194 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { | 191 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { |
| 195 OnDisplayChanged(); | 192 OnDisplayChanged(); |
| 196 } | 193 } |
| 197 | 194 |
| 195 void SystemInfoEventRouter::OnDisplayMetricsChanged( |
| 196 const gfx::Display& display, |
| 197 DisplayObserver::DisplayMetrics metrics) { |
| 198 OnDisplayChanged(); |
| 199 } |
| 200 |
| 198 void SystemInfoEventRouter::OnDisplayChanged() { | 201 void SystemInfoEventRouter::OnDisplayChanged() { |
| 199 scoped_ptr<base::ListValue> args(new base::ListValue()); | 202 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 200 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); | 203 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, | 206 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, |
| 204 scoped_ptr<base::ListValue> args) { | 207 scoped_ptr<base::ListValue> args) { |
| 205 g_browser_process->extension_event_router_forwarder()-> | 208 g_browser_process->extension_event_router_forwarder()-> |
| 206 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); | 209 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); |
| 207 } | 210 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 255 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 253 if (IsSystemStorageEvent(details.event_name)) { | 256 if (IsSystemStorageEvent(details.event_name)) { |
| 254 StorageMonitor::GetInstance()->EnsureInitialized( | 257 StorageMonitor::GetInstance()->EnsureInitialized( |
| 255 base::Bind(&RemoveEventListener, details.event_name)); | 258 base::Bind(&RemoveEventListener, details.event_name)); |
| 256 } else { | 259 } else { |
| 257 RemoveEventListener(details.event_name); | 260 RemoveEventListener(details.event_name); |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 | 263 |
| 261 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |