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 "extensions/browser/api/system_info/system_info_api.h" | 5 #include "extensions/browser/api/system_info/system_info_api.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "components/storage_monitor/removable_storage_observer.h" | 19 #include "components/storage_monitor/removable_storage_observer.h" |
20 #include "components/storage_monitor/storage_info.h" | 20 #include "components/storage_monitor/storage_info.h" |
21 #include "components/storage_monitor/storage_monitor.h" | 21 #include "components/storage_monitor/storage_monitor.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "extensions/browser/api/system_display/display_info_provider.h" | |
24 #include "extensions/browser/api/system_storage/storage_info_provider.h" | 23 #include "extensions/browser/api/system_storage/storage_info_provider.h" |
25 #include "extensions/browser/extensions_browser_client.h" | 24 #include "extensions/browser/extensions_browser_client.h" |
26 #include "extensions/common/api/system_display.h" | 25 #include "extensions/common/api/system_display.h" |
27 #include "extensions/common/api/system_storage.h" | 26 #include "extensions/common/api/system_storage.h" |
28 #include "ui/gfx/display_observer.h" | 27 #include "ui/gfx/display_observer.h" |
29 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
30 | 29 |
31 namespace extensions { | 30 namespace extensions { |
32 | 31 |
33 using api::system_storage::StorageUnitInfo; | 32 using api::system_storage::StorageUnitInfo; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 112 } |
114 | 113 |
115 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { | 114 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { |
116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
117 | 116 |
118 watching_event_set_.insert(event_name); | 117 watching_event_set_.insert(event_name); |
119 if (watching_event_set_.count(event_name) > 1) | 118 if (watching_event_set_.count(event_name) > 1) |
120 return; | 119 return; |
121 | 120 |
122 if (IsDisplayChangedEvent(event_name)) { | 121 if (IsDisplayChangedEvent(event_name)) { |
123 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen(); | 122 gfx::Screen* screen = gfx::Screen::GetScreen(); |
124 if (screen) | 123 if (screen) |
125 screen->AddObserver(this); | 124 screen->AddObserver(this); |
126 } | 125 } |
127 | 126 |
128 if (IsSystemStorageEvent(event_name)) { | 127 if (IsSystemStorageEvent(event_name)) { |
129 if (!has_storage_monitor_observer_) { | 128 if (!has_storage_monitor_observer_) { |
130 has_storage_monitor_observer_ = true; | 129 has_storage_monitor_observer_ = true; |
131 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 130 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
132 StorageMonitor::GetInstance()->AddObserver(this); | 131 StorageMonitor::GetInstance()->AddObserver(this); |
133 } | 132 } |
134 } | 133 } |
135 } | 134 } |
136 | 135 |
137 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { | 136 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { |
138 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 137 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
139 | 138 |
140 std::multiset<std::string>::iterator it = | 139 std::multiset<std::string>::iterator it = |
141 watching_event_set_.find(event_name); | 140 watching_event_set_.find(event_name); |
142 if (it != watching_event_set_.end()) { | 141 if (it != watching_event_set_.end()) { |
143 watching_event_set_.erase(it); | 142 watching_event_set_.erase(it); |
144 if (watching_event_set_.count(event_name) > 0) | 143 if (watching_event_set_.count(event_name) > 0) |
145 return; | 144 return; |
146 } | 145 } |
147 | 146 |
148 if (IsDisplayChangedEvent(event_name)) { | 147 if (IsDisplayChangedEvent(event_name)) { |
149 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen(); | 148 gfx::Screen* screen = gfx::Screen::GetScreen(); |
150 if (screen) | 149 if (screen) |
151 screen->RemoveObserver(this); | 150 screen->RemoveObserver(this); |
152 } | 151 } |
153 | 152 |
154 if (IsSystemStorageEvent(event_name)) { | 153 if (IsSystemStorageEvent(event_name)) { |
155 const std::string& other_event_name = | 154 const std::string& other_event_name = |
156 (event_name == system_storage::OnDetached::kEventName) | 155 (event_name == system_storage::OnDetached::kEventName) |
157 ? system_storage::OnAttached::kEventName | 156 ? system_storage::OnAttached::kEventName |
158 : system_storage::OnDetached::kEventName; | 157 : system_storage::OnDetached::kEventName; |
159 if (watching_event_set_.count(other_event_name) == 0) { | 158 if (watching_event_set_.count(other_event_name) == 0) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 257 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
259 if (IsSystemStorageEvent(details.event_name)) { | 258 if (IsSystemStorageEvent(details.event_name)) { |
260 StorageMonitor::GetInstance()->EnsureInitialized( | 259 StorageMonitor::GetInstance()->EnsureInitialized( |
261 base::Bind(&RemoveEventListener, details.event_name)); | 260 base::Bind(&RemoveEventListener, details.event_name)); |
262 } else { | 261 } else { |
263 RemoveEventListener(details.event_name); | 262 RemoveEventListener(details.event_name); |
264 } | 263 } |
265 } | 264 } |
266 | 265 |
267 } // namespace extensions | 266 } // namespace extensions |
OLD | NEW |