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 "chrome/browser/extensions/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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; | 78 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; |
79 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; | 79 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; |
80 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; | 80 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; |
81 | 81 |
82 // chrome::RemovableStorageObserver implementation. | 82 // chrome::RemovableStorageObserver implementation. |
83 virtual void OnRemovableStorageAttached( | 83 virtual void OnRemovableStorageAttached( |
84 const chrome::StorageInfo& info) OVERRIDE; | 84 const chrome::StorageInfo& info) OVERRIDE; |
85 virtual void OnRemovableStorageDetached( | 85 virtual void OnRemovableStorageDetached( |
86 const chrome::StorageInfo& info) OVERRIDE; | 86 const chrome::StorageInfo& info) OVERRIDE; |
87 | 87 |
88 void DispatchStorageAttachedEvent(const chrome::StorageInfo& info, | |
89 int64 avail_bytes); | |
90 | |
91 // Called from any thread to dispatch the systemInfo event to all extension | 88 // Called from any thread to dispatch the systemInfo event to all extension |
92 // processes cross multiple profiles. | 89 // processes cross multiple profiles. |
93 void DispatchEvent(const std::string& event_name, | 90 void DispatchEvent(const std::string& event_name, |
94 scoped_ptr<base::ListValue> args); | 91 scoped_ptr<base::ListValue> args); |
95 | 92 |
96 // The callbacks of querying storage info to start and stop watching the | 93 // The callbacks of querying storage info to start and stop watching the |
97 // storages. Called from UI thread. | 94 // storages. Called from UI thread. |
98 void StartWatchingStorages(bool success); | 95 void StartWatchingStorages(bool success); |
99 void StopWatchingStorages(bool success); | 96 void StopWatchingStorages(bool success); |
100 | 97 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 info.available_capacity = static_cast<double>(new_value); | 207 info.available_capacity = static_cast<double>(new_value); |
211 | 208 |
212 scoped_ptr<base::ListValue> args(new base::ListValue()); | 209 scoped_ptr<base::ListValue> args(new base::ListValue()); |
213 args->Append(info.ToValue().release()); | 210 args->Append(info.ToValue().release()); |
214 | 211 |
215 DispatchEvent(event_names::kOnStorageAvailableCapacityChanged, args.Pass()); | 212 DispatchEvent(event_names::kOnStorageAvailableCapacityChanged, args.Pass()); |
216 } | 213 } |
217 | 214 |
218 void SystemInfoEventRouter::OnRemovableStorageAttached( | 215 void SystemInfoEventRouter::OnRemovableStorageAttached( |
219 const chrome::StorageInfo& info) { | 216 const chrome::StorageInfo& info) { |
220 base::PostTaskAndReplyWithResult( | |
221 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | |
222 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN), | |
223 FROM_HERE, | |
224 base::Bind(&StorageInfoProvider::GetStorageFreeSpaceFromTransientId, | |
225 StorageInfoProvider::Get(), | |
226 StorageInfoProvider::Get()->GetTransientIdForDeviceId( | |
227 info.device_id())), | |
228 base::Bind(&SystemInfoEventRouter::DispatchStorageAttachedEvent, | |
229 // Since SystemInfoEventRouter is a global lazy instance, this | |
230 // pointer will be alive when the reply comes back. | |
231 base::Unretained(this), | |
232 info)); | |
233 } | |
234 | |
235 void SystemInfoEventRouter::DispatchStorageAttachedEvent( | |
236 const chrome::StorageInfo& info, int64 avail_bytes) { | |
237 StorageUnitInfo unit; | 217 StorageUnitInfo unit; |
238 systeminfo::BuildStorageUnitInfo(info, &unit); | 218 systeminfo::BuildStorageUnitInfo(info, &unit); |
239 | |
240 unit.available_capacity = | |
241 avail_bytes > 0 ? static_cast<double>(avail_bytes) : 0; | |
242 | |
243 scoped_ptr<base::ListValue> args(new base::ListValue); | 219 scoped_ptr<base::ListValue> args(new base::ListValue); |
244 args->Append(unit.ToValue().release()); | 220 args->Append(unit.ToValue().release()); |
245 DispatchEvent(event_names::kOnStorageAttached, args.Pass()); | 221 DispatchEvent(event_names::kOnStorageAttached, args.Pass()); |
246 } | 222 } |
247 | 223 |
248 void SystemInfoEventRouter::OnRemovableStorageDetached( | 224 void SystemInfoEventRouter::OnRemovableStorageDetached( |
249 const chrome::StorageInfo& info) { | 225 const chrome::StorageInfo& info) { |
250 scoped_ptr<base::ListValue> args(new base::ListValue); | 226 scoped_ptr<base::ListValue> args(new base::ListValue); |
251 args->Append(new base::StringValue(StorageInfoProvider::Get()-> | 227 args->Append(new base::StringValue(StorageInfoProvider::Get()-> |
252 GetTransientIdForDeviceId(info.device_id()))); | 228 GetTransientIdForDeviceId(info.device_id()))); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 282 |
307 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { | 283 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { |
308 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); | 284 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); |
309 } | 285 } |
310 | 286 |
311 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 287 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
312 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); | 288 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); |
313 } | 289 } |
314 | 290 |
315 } // namespace extensions | 291 } // namespace extensions |
OLD | NEW |