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" | 23 #include "extensions/browser/api/system_display/display_info_provider.h" |
oshima
2016/01/20 06:40:12
remove this?
scottmg
2016/01/26 20:46:35
Done.
| |
24 #include "extensions/browser/api/system_storage/storage_info_provider.h" | 24 #include "extensions/browser/api/system_storage/storage_info_provider.h" |
25 #include "extensions/browser/extensions_browser_client.h" | 25 #include "extensions/browser/extensions_browser_client.h" |
26 #include "extensions/common/api/system_display.h" | 26 #include "extensions/common/api/system_display.h" |
27 #include "extensions/common/api/system_storage.h" | 27 #include "extensions/common/api/system_storage.h" |
28 #include "ui/gfx/display_observer.h" | 28 #include "ui/gfx/display_observer.h" |
29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
30 | 30 |
31 namespace extensions { | 31 namespace extensions { |
32 | 32 |
33 using api::system_storage::StorageUnitInfo; | 33 using api::system_storage::StorageUnitInfo; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 } | 113 } |
114 | 114 |
115 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { | 115 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { |
116 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 116 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
117 | 117 |
118 watching_event_set_.insert(event_name); | 118 watching_event_set_.insert(event_name); |
119 if (watching_event_set_.count(event_name) > 1) | 119 if (watching_event_set_.count(event_name) > 1) |
120 return; | 120 return; |
121 | 121 |
122 if (IsDisplayChangedEvent(event_name)) { | 122 if (IsDisplayChangedEvent(event_name)) { |
123 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen(); | 123 gfx::Screen* screen = gfx::Screen::GetScreen(); |
124 if (screen) | 124 if (screen) |
125 screen->AddObserver(this); | 125 screen->AddObserver(this); |
126 } | 126 } |
127 | 127 |
128 if (IsSystemStorageEvent(event_name)) { | 128 if (IsSystemStorageEvent(event_name)) { |
129 if (!has_storage_monitor_observer_) { | 129 if (!has_storage_monitor_observer_) { |
130 has_storage_monitor_observer_ = true; | 130 has_storage_monitor_observer_ = true; |
131 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 131 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
132 StorageMonitor::GetInstance()->AddObserver(this); | 132 StorageMonitor::GetInstance()->AddObserver(this); |
133 } | 133 } |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { | 137 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { |
138 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
139 | 139 |
140 std::multiset<std::string>::iterator it = | 140 std::multiset<std::string>::iterator it = |
141 watching_event_set_.find(event_name); | 141 watching_event_set_.find(event_name); |
142 if (it != watching_event_set_.end()) { | 142 if (it != watching_event_set_.end()) { |
143 watching_event_set_.erase(it); | 143 watching_event_set_.erase(it); |
144 if (watching_event_set_.count(event_name) > 0) | 144 if (watching_event_set_.count(event_name) > 0) |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 if (IsDisplayChangedEvent(event_name)) { | 148 if (IsDisplayChangedEvent(event_name)) { |
149 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen(); | 149 gfx::Screen* screen = gfx::Screen::GetScreen(); |
150 if (screen) | 150 if (screen) |
151 screen->RemoveObserver(this); | 151 screen->RemoveObserver(this); |
152 } | 152 } |
153 | 153 |
154 if (IsSystemStorageEvent(event_name)) { | 154 if (IsSystemStorageEvent(event_name)) { |
155 const std::string& other_event_name = | 155 const std::string& other_event_name = |
156 (event_name == system_storage::OnDetached::kEventName) | 156 (event_name == system_storage::OnDetached::kEventName) |
157 ? system_storage::OnAttached::kEventName | 157 ? system_storage::OnAttached::kEventName |
158 : system_storage::OnDetached::kEventName; | 158 : system_storage::OnDetached::kEventName; |
159 if (watching_event_set_.count(other_event_name) == 0) { | 159 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) { | 258 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
259 if (IsSystemStorageEvent(details.event_name)) { | 259 if (IsSystemStorageEvent(details.event_name)) { |
260 StorageMonitor::GetInstance()->EnsureInitialized( | 260 StorageMonitor::GetInstance()->EnsureInitialized( |
261 base::Bind(&RemoveEventListener, details.event_name)); | 261 base::Bind(&RemoveEventListener, details.event_name)); |
262 } else { | 262 } else { |
263 RemoveEventListener(details.event_name); | 263 RemoveEventListener(details.event_name); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 } // namespace extensions | 267 } // namespace extensions |
OLD | NEW |