| 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 "extensions/browser/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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" | |
| 17 #include "chrome/browser/extensions/event_router_forwarder.h" | |
| 18 #include "chrome/common/extensions/api/system_display.h" | |
| 19 #include "chrome/common/extensions/api/system_storage.h" | |
| 20 #include "components/storage_monitor/removable_storage_observer.h" | 15 #include "components/storage_monitor/removable_storage_observer.h" |
| 21 #include "components/storage_monitor/storage_info.h" | 16 #include "components/storage_monitor/storage_info.h" |
| 22 #include "components/storage_monitor/storage_monitor.h" | 17 #include "components/storage_monitor/storage_monitor.h" |
| 23 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "extensions/browser/api/system_storage/storage_info_provider.h" |
| 20 #include "extensions/browser/extensions_browser_client.h" |
| 21 #include "extensions/common/api/system_display.h" |
| 22 #include "extensions/common/api/system_storage.h" |
| 24 #include "ui/gfx/display_observer.h" | 23 #include "ui/gfx/display_observer.h" |
| 25 | 24 |
| 26 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 27 #include "ash/shell.h" | 26 #include "ash/shell.h" |
| 28 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
| 29 #endif | 28 #endif |
| 30 | 29 |
| 31 namespace extensions { | 30 namespace extensions { |
| 32 | 31 |
| 33 using api::system_storage::StorageUnitInfo; | 32 using core_api::system_storage::StorageUnitInfo; |
| 34 using content::BrowserThread; | 33 using content::BrowserThread; |
| 35 using storage_monitor::StorageMonitor; | 34 using storage_monitor::StorageMonitor; |
| 36 | 35 |
| 37 namespace system_display = api::system_display; | 36 namespace system_display = core_api::system_display; |
| 38 namespace system_storage = api::system_storage; | 37 namespace system_storage = core_api::system_storage; |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 43 bool IsDisplayChangedEvent(const std::string& event_name) { | 42 bool IsDisplayChangedEvent(const std::string& event_name) { |
| 44 return event_name == system_display::OnDisplayChanged::kEventName; | 43 return event_name == system_display::OnDisplayChanged::kEventName; |
| 45 } | 44 } |
| 46 #endif | 45 #endif |
| 47 | 46 |
| 48 bool IsSystemStorageEvent(const std::string& event_name) { | 47 bool IsSystemStorageEvent(const std::string& event_name) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 OnDisplayChanged(); | 195 OnDisplayChanged(); |
| 197 } | 196 } |
| 198 | 197 |
| 199 void SystemInfoEventRouter::OnDisplayChanged() { | 198 void SystemInfoEventRouter::OnDisplayChanged() { |
| 200 scoped_ptr<base::ListValue> args(new base::ListValue()); | 199 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 201 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); | 200 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, | 203 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, |
| 205 scoped_ptr<base::ListValue> args) { | 204 scoped_ptr<base::ListValue> args) { |
| 206 g_browser_process->extension_event_router_forwarder()-> | 205 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(event_name, |
| 207 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); | 206 args.Pass()); |
| 208 } | 207 } |
| 209 | 208 |
| 210 void AddEventListener(const std::string& event_name) { | 209 void AddEventListener(const std::string& event_name) { |
| 211 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); | 210 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); |
| 212 } | 211 } |
| 213 | 212 |
| 214 void RemoveEventListener(const std::string& event_name) { | 213 void RemoveEventListener(const std::string& event_name) { |
| 215 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); | 214 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); |
| 216 } | 215 } |
| 217 | 216 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 252 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 254 if (IsSystemStorageEvent(details.event_name)) { | 253 if (IsSystemStorageEvent(details.event_name)) { |
| 255 StorageMonitor::GetInstance()->EnsureInitialized( | 254 StorageMonitor::GetInstance()->EnsureInitialized( |
| 256 base::Bind(&RemoveEventListener, details.event_name)); | 255 base::Bind(&RemoveEventListener, details.event_name)); |
| 257 } else { | 256 } else { |
| 258 RemoveEventListener(details.event_name); | 257 RemoveEventListener(details.event_name); |
| 259 } | 258 } |
| 260 } | 259 } |
| 261 | 260 |
| 262 } // namespace extensions | 261 } // namespace extensions |
| OLD | NEW |