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

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

Issue 389633002: Move system.* family of APIs to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No ash/ dependency anymore Created 6 years, 3 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 "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_display/display_info_provider.h"
17 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h"
18 #include "chrome/browser/extensions/event_router_forwarder.h"
19 #include "chrome/common/extensions/api/system_display.h"
20 #include "chrome/common/extensions/api/system_storage.h"
21 #include "components/storage_monitor/removable_storage_observer.h" 15 #include "components/storage_monitor/removable_storage_observer.h"
22 #include "components/storage_monitor/storage_info.h" 16 #include "components/storage_monitor/storage_info.h"
23 #include "components/storage_monitor/storage_monitor.h" 17 #include "components/storage_monitor/storage_monitor.h"
24 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "extensions/browser/api/system_display/display_info_provider.h"
20 #include "extensions/browser/api/system_storage/storage_info_provider.h"
21 #include "extensions/browser/extensions_browser_client.h"
22 #include "extensions/common/api/system_display.h"
23 #include "extensions/common/api/system_storage.h"
25 #include "ui/gfx/display_observer.h" 24 #include "ui/gfx/display_observer.h"
26 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
27 26
28 namespace extensions { 27 namespace extensions {
29 28
30 using api::system_storage::StorageUnitInfo; 29 using core_api::system_storage::StorageUnitInfo;
31 using content::BrowserThread; 30 using content::BrowserThread;
32 using storage_monitor::StorageMonitor; 31 using storage_monitor::StorageMonitor;
33 32
34 namespace system_display = api::system_display; 33 namespace system_display = core_api::system_display;
35 namespace system_storage = api::system_storage; 34 namespace system_storage = core_api::system_storage;
36 35
37 namespace { 36 namespace {
38 37
39 bool IsDisplayChangedEvent(const std::string& event_name) { 38 bool IsDisplayChangedEvent(const std::string& event_name) {
40 return event_name == system_display::OnDisplayChanged::kEventName; 39 return event_name == system_display::OnDisplayChanged::kEventName;
41 } 40 }
42 41
43 bool IsSystemStorageEvent(const std::string& event_name) { 42 bool IsSystemStorageEvent(const std::string& event_name) {
44 return (event_name == system_storage::OnAttached::kEventName || 43 return (event_name == system_storage::OnAttached::kEventName ||
45 event_name == system_storage::OnDetached::kEventName); 44 event_name == system_storage::OnDetached::kEventName);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 141 }
143 142
144 if (IsDisplayChangedEvent(event_name)) { 143 if (IsDisplayChangedEvent(event_name)) {
145 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen(); 144 gfx::Screen* screen = DisplayInfoProvider::Get()->GetActiveScreen();
146 if (screen) 145 if (screen)
147 screen->RemoveObserver(this); 146 screen->RemoveObserver(this);
148 } 147 }
149 148
150 if (IsSystemStorageEvent(event_name)) { 149 if (IsSystemStorageEvent(event_name)) {
151 const std::string& other_event_name = 150 const std::string& other_event_name =
152 (event_name == system_storage::OnDetached::kEventName) ? 151 (event_name == system_storage::OnDetached::kEventName)
153 system_storage::OnAttached::kEventName : 152 ? system_storage::OnAttached::kEventName
154 system_storage::OnDetached::kEventName; 153 : system_storage::OnDetached::kEventName;
155 if (watching_event_set_.count(other_event_name) == 0) { 154 if (watching_event_set_.count(other_event_name) == 0) {
156 StorageMonitor::GetInstance()->RemoveObserver(this); 155 StorageMonitor::GetInstance()->RemoveObserver(this);
157 has_storage_monitor_observer_ = false; 156 has_storage_monitor_observer_ = false;
158 } 157 }
159 } 158 }
160 } 159 }
161 160
162 void SystemInfoEventRouter::OnRemovableStorageAttached( 161 void SystemInfoEventRouter::OnRemovableStorageAttached(
163 const storage_monitor::StorageInfo& info) { 162 const storage_monitor::StorageInfo& info) {
164 StorageUnitInfo unit; 163 StorageUnitInfo unit;
(...skipping 27 matching lines...) Expand all
192 OnDisplayChanged(); 191 OnDisplayChanged();
193 } 192 }
194 193
195 void SystemInfoEventRouter::OnDisplayChanged() { 194 void SystemInfoEventRouter::OnDisplayChanged() {
196 scoped_ptr<base::ListValue> args(new base::ListValue()); 195 scoped_ptr<base::ListValue> args(new base::ListValue());
197 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); 196 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass());
198 } 197 }
199 198
200 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, 199 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name,
201 scoped_ptr<base::ListValue> args) { 200 scoped_ptr<base::ListValue> args) {
202 g_browser_process->extension_event_router_forwarder()-> 201 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(event_name,
203 BroadcastEventToRenderers(event_name, args.Pass(), GURL()); 202 args.Pass());
204 } 203 }
205 204
206 void AddEventListener(const std::string& event_name) { 205 void AddEventListener(const std::string& event_name) {
207 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); 206 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name);
208 } 207 }
209 208
210 void RemoveEventListener(const std::string& event_name) { 209 void RemoveEventListener(const std::string& event_name) {
211 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); 210 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name);
212 } 211 }
213 212
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 248 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
250 if (IsSystemStorageEvent(details.event_name)) { 249 if (IsSystemStorageEvent(details.event_name)) {
251 StorageMonitor::GetInstance()->EnsureInitialized( 250 StorageMonitor::GetInstance()->EnsureInitialized(
252 base::Bind(&RemoveEventListener, details.event_name)); 251 base::Bind(&RemoveEventListener, details.event_name));
253 } else { 252 } else {
254 RemoveEventListener(details.event_name); 253 RemoveEventListener(details.event_name);
255 } 254 }
256 } 255 }
257 256
258 } // namespace extensions 257 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698