Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1106)

Side by Side Diff: extensions/browser/api/system_info/system_info_api.cc

Issue 1924133002: Rename gfx::Display/Screen to display::Display/Screen in extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/macros.h" 15 #include "base/macros.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_storage/storage_info_provider.h" 23 #include "extensions/browser/api/system_storage/storage_info_provider.h"
24 #include "extensions/browser/extensions_browser_client.h" 24 #include "extensions/browser/extensions_browser_client.h"
25 #include "extensions/common/api/system_display.h" 25 #include "extensions/common/api/system_display.h"
26 #include "extensions/common/api/system_storage.h" 26 #include "extensions/common/api/system_storage.h"
27 #include "ui/gfx/display_observer.h" 27 #include "ui/display/display_observer.h"
28 #include "ui/gfx/screen.h" 28 #include "ui/display/screen.h"
29 29
30 namespace extensions { 30 namespace extensions {
31 31
32 using api::system_storage::StorageUnitInfo; 32 using api::system_storage::StorageUnitInfo;
33 using content::BrowserThread; 33 using content::BrowserThread;
34 using storage_monitor::StorageMonitor; 34 using storage_monitor::StorageMonitor;
35 35
36 namespace system_display = api::system_display; 36 namespace system_display = api::system_display;
37 namespace system_storage = api::system_storage; 37 namespace system_storage = api::system_storage;
38 38
39 namespace { 39 namespace {
40 40
41 bool IsDisplayChangedEvent(const std::string& event_name) { 41 bool IsDisplayChangedEvent(const std::string& event_name) {
42 return event_name == system_display::OnDisplayChanged::kEventName; 42 return event_name == system_display::OnDisplayChanged::kEventName;
43 } 43 }
44 44
45 bool IsSystemStorageEvent(const std::string& event_name) { 45 bool IsSystemStorageEvent(const std::string& event_name) {
46 return (event_name == system_storage::OnAttached::kEventName || 46 return (event_name == system_storage::OnAttached::kEventName ||
47 event_name == system_storage::OnDetached::kEventName); 47 event_name == system_storage::OnDetached::kEventName);
48 } 48 }
49 49
50 // Event router for systemInfo API. It is a singleton instance shared by 50 // Event router for systemInfo API. It is a singleton instance shared by
51 // multiple profiles. 51 // multiple profiles.
52 class SystemInfoEventRouter : public gfx::DisplayObserver, 52 class SystemInfoEventRouter : public display::DisplayObserver,
53 public storage_monitor::RemovableStorageObserver { 53 public storage_monitor::RemovableStorageObserver {
54 public: 54 public:
55 static SystemInfoEventRouter* GetInstance(); 55 static SystemInfoEventRouter* GetInstance();
56 56
57 SystemInfoEventRouter(); 57 SystemInfoEventRouter();
58 ~SystemInfoEventRouter() override; 58 ~SystemInfoEventRouter() override;
59 59
60 // Add/remove event listener for the |event_name| event. 60 // Add/remove event listener for the |event_name| event.
61 void AddEventListener(const std::string& event_name); 61 void AddEventListener(const std::string& event_name);
62 void RemoveEventListener(const std::string& event_name); 62 void RemoveEventListener(const std::string& event_name);
63 63
64 private: 64 private:
65 // gfx::DisplayObserver: 65 // display::DisplayObserver:
66 void OnDisplayAdded(const gfx::Display& new_display) override; 66 void OnDisplayAdded(const display::Display& new_display) override;
67 void OnDisplayRemoved(const gfx::Display& old_display) override; 67 void OnDisplayRemoved(const display::Display& old_display) override;
68 void OnDisplayMetricsChanged(const gfx::Display& display, 68 void OnDisplayMetricsChanged(const display::Display& display,
69 uint32_t metrics) override; 69 uint32_t metrics) override;
70 70
71 // RemovableStorageObserver implementation. 71 // RemovableStorageObserver implementation.
72 void OnRemovableStorageAttached( 72 void OnRemovableStorageAttached(
73 const storage_monitor::StorageInfo& info) override; 73 const storage_monitor::StorageInfo& info) override;
74 void OnRemovableStorageDetached( 74 void OnRemovableStorageDetached(
75 const storage_monitor::StorageInfo& info) override; 75 const storage_monitor::StorageInfo& info) override;
76 76
77 // Called from any thread to dispatch the systemInfo event to all extension 77 // Called from any thread to dispatch the systemInfo event to all extension
78 // processes cross multiple profiles. 78 // processes cross multiple profiles.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { 114 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) {
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); 115 DCHECK_CURRENTLY_ON(BrowserThread::UI);
116 116
117 watching_event_set_.insert(event_name); 117 watching_event_set_.insert(event_name);
118 if (watching_event_set_.count(event_name) > 1) 118 if (watching_event_set_.count(event_name) > 1)
119 return; 119 return;
120 120
121 if (IsDisplayChangedEvent(event_name)) { 121 if (IsDisplayChangedEvent(event_name)) {
122 gfx::Screen* screen = gfx::Screen::GetScreen(); 122 display::Screen* screen = display::Screen::GetScreen();
123 if (screen) 123 if (screen)
124 screen->AddObserver(this); 124 screen->AddObserver(this);
125 } 125 }
126 126
127 if (IsSystemStorageEvent(event_name)) { 127 if (IsSystemStorageEvent(event_name)) {
128 if (!has_storage_monitor_observer_) { 128 if (!has_storage_monitor_observer_) {
129 has_storage_monitor_observer_ = true; 129 has_storage_monitor_observer_ = true;
130 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); 130 DCHECK(StorageMonitor::GetInstance()->IsInitialized());
131 StorageMonitor::GetInstance()->AddObserver(this); 131 StorageMonitor::GetInstance()->AddObserver(this);
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) { 136 void SystemInfoEventRouter::RemoveEventListener(const std::string& event_name) {
137 DCHECK_CURRENTLY_ON(BrowserThread::UI); 137 DCHECK_CURRENTLY_ON(BrowserThread::UI);
138 138
139 std::multiset<std::string>::iterator it = 139 std::multiset<std::string>::iterator it =
140 watching_event_set_.find(event_name); 140 watching_event_set_.find(event_name);
141 if (it != watching_event_set_.end()) { 141 if (it != watching_event_set_.end()) {
142 watching_event_set_.erase(it); 142 watching_event_set_.erase(it);
143 if (watching_event_set_.count(event_name) > 0) 143 if (watching_event_set_.count(event_name) > 0)
144 return; 144 return;
145 } 145 }
146 146
147 if (IsDisplayChangedEvent(event_name)) { 147 if (IsDisplayChangedEvent(event_name)) {
148 gfx::Screen* screen = gfx::Screen::GetScreen(); 148 display::Screen* screen = display::Screen::GetScreen();
149 if (screen) 149 if (screen)
150 screen->RemoveObserver(this); 150 screen->RemoveObserver(this);
151 } 151 }
152 152
153 if (IsSystemStorageEvent(event_name)) { 153 if (IsSystemStorageEvent(event_name)) {
154 const std::string& other_event_name = 154 const std::string& other_event_name =
155 (event_name == system_storage::OnDetached::kEventName) 155 (event_name == system_storage::OnDetached::kEventName)
156 ? system_storage::OnAttached::kEventName 156 ? system_storage::OnAttached::kEventName
157 : system_storage::OnDetached::kEventName; 157 : system_storage::OnDetached::kEventName;
158 if (watching_event_set_.count(other_event_name) == 0) { 158 if (watching_event_set_.count(other_event_name) == 0) {
(...skipping 18 matching lines...) Expand all
177 std::unique_ptr<base::ListValue> args(new base::ListValue); 177 std::unique_ptr<base::ListValue> args(new base::ListValue);
178 std::string transient_id = 178 std::string transient_id =
179 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( 179 StorageMonitor::GetInstance()->GetTransientIdForDeviceId(
180 info.device_id()); 180 info.device_id());
181 args->AppendString(transient_id); 181 args->AppendString(transient_id);
182 182
183 DispatchEvent(events::SYSTEM_STORAGE_ON_DETACHED, 183 DispatchEvent(events::SYSTEM_STORAGE_ON_DETACHED,
184 system_storage::OnDetached::kEventName, std::move(args)); 184 system_storage::OnDetached::kEventName, std::move(args));
185 } 185 }
186 186
187 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { 187 void SystemInfoEventRouter::OnDisplayAdded(
188 const display::Display& new_display) {
188 OnDisplayChanged(); 189 OnDisplayChanged();
189 } 190 }
190 191
191 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { 192 void SystemInfoEventRouter::OnDisplayRemoved(
193 const display::Display& old_display) {
192 OnDisplayChanged(); 194 OnDisplayChanged();
193 } 195 }
194 196
195 void SystemInfoEventRouter::OnDisplayMetricsChanged(const gfx::Display& display, 197 void SystemInfoEventRouter::OnDisplayMetricsChanged(
196 uint32_t metrics) { 198 const display::Display& display,
199 uint32_t metrics) {
197 OnDisplayChanged(); 200 OnDisplayChanged();
198 } 201 }
199 202
200 void SystemInfoEventRouter::OnDisplayChanged() { 203 void SystemInfoEventRouter::OnDisplayChanged() {
201 std::unique_ptr<base::ListValue> args(new base::ListValue()); 204 std::unique_ptr<base::ListValue> args(new base::ListValue());
202 DispatchEvent(events::SYSTEM_DISPLAY_ON_DISPLAY_CHANGED, 205 DispatchEvent(events::SYSTEM_DISPLAY_ON_DISPLAY_CHANGED,
203 system_display::OnDisplayChanged::kEventName, std::move(args)); 206 system_display::OnDisplayChanged::kEventName, std::move(args));
204 } 207 }
205 208
206 void SystemInfoEventRouter::DispatchEvent( 209 void SystemInfoEventRouter::DispatchEvent(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 260 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
258 if (IsSystemStorageEvent(details.event_name)) { 261 if (IsSystemStorageEvent(details.event_name)) {
259 StorageMonitor::GetInstance()->EnsureInitialized( 262 StorageMonitor::GetInstance()->EnsureInitialized(
260 base::Bind(&RemoveEventListener, details.event_name)); 263 base::Bind(&RemoveEventListener, details.event_name));
261 } else { 264 } else {
262 RemoveEventListener(details.event_name); 265 RemoveEventListener(details.event_name);
263 } 266 }
264 } 267 }
265 268
266 } // namespace extensions 269 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/system_display/system_display_apitest.cc ('k') | extensions/browser/api/web_contents_capture_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698