Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 void DispatchStorageAttachedEvent(const chrome::StorageInfo& info, | 88 void DispatchStorageAttachedEvent(const chrome::StorageInfo& info, |
| 89 int64 avail_bytes); | 89 int64 avail_bytes); |
| 90 | 90 |
| 91 // Called from any thread to dispatch the systemInfo event to all extension | 91 // Called from any thread to dispatch the systemInfo event to all extension |
| 92 // processes cross multiple profiles. | 92 // processes cross multiple profiles. |
| 93 void DispatchEvent(const std::string& event_name, | 93 void DispatchEvent(const std::string& event_name, |
| 94 scoped_ptr<base::ListValue> args); | 94 scoped_ptr<base::ListValue> args); |
| 95 | 95 |
| 96 // The callbacks of querying storage info to start and stop watching the | 96 // The callbacks of querying storage info to start and stop watching the |
| 97 // storages. Called from UI thread. | 97 // storages. Called from UI thread. |
| 98 void StartWatchingStorages(const StorageInfo& info, bool success); | 98 void StartWatchingStorages(bool success); |
| 99 void StopWatchingStorages(const StorageInfo& info, bool success); | 99 void StopWatchingStorages(bool success); |
| 100 | 100 |
| 101 // Called to dispatch the systemInfo.display.onDisplayChanged event. | 101 // Called to dispatch the systemInfo.display.onDisplayChanged event. |
| 102 void OnDisplayChanged(); | 102 void OnDisplayChanged(); |
| 103 | 103 |
| 104 // Used to record the event names being watched. | 104 // Used to record the event names being watched. |
| 105 std::multiset<std::string> watching_event_set_; | 105 std::multiset<std::string> watching_event_set_; |
| 106 | 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); | 107 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); |
| 108 }; | 108 }; |
| 109 | 109 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 120 chrome::StorageMonitor::GetInstance()->AddObserver(this); | 120 chrome::StorageMonitor::GetInstance()->AddObserver(this); |
| 121 } | 121 } |
| 122 | 122 |
| 123 SystemInfoEventRouter::~SystemInfoEventRouter() { | 123 SystemInfoEventRouter::~SystemInfoEventRouter() { |
| 124 StorageInfoProvider::Get()->RemoveObserver(this); | 124 StorageInfoProvider::Get()->RemoveObserver(this); |
| 125 if (chrome::StorageMonitor* storage_monitor = | 125 if (chrome::StorageMonitor* storage_monitor = |
| 126 chrome::StorageMonitor::GetInstance()) | 126 chrome::StorageMonitor::GetInstance()) |
| 127 storage_monitor->RemoveObserver(this); | 127 storage_monitor->RemoveObserver(this); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SystemInfoEventRouter::StartWatchingStorages( | 130 void SystemInfoEventRouter::StartWatchingStorages(bool success) { |
|
Greg Billock
2013/07/08 18:05:06
It looks like this should just forward the call di
Haojian Wu
2013/07/09 13:45:04
Done.
| |
| 131 const StorageInfo& info, bool success) { | |
| 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 133 if (!success) | 132 if (!success) |
| 134 return; | 133 return; |
| 135 | 134 |
| 135 const StorageInfo& info = StorageInfoProvider::Get()->storage_info(); | |
| 136 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { | 136 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { |
| 137 StorageInfoProvider::Get()->StartWatching((*it)->id); | 137 StorageInfoProvider::Get()->StartWatching((*it)->id); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void SystemInfoEventRouter::StopWatchingStorages( | 141 void SystemInfoEventRouter::StopWatchingStorages(bool success) { |
|
Greg Billock
2013/07/08 18:05:06
Same here.
Haojian Wu
2013/07/09 13:45:04
Done.
| |
| 142 const StorageInfo& info, bool success) { | |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 144 if (!success) | 143 if (!success) |
| 145 return; | 144 return; |
| 146 | 145 |
| 146 const StorageInfo& info = StorageInfoProvider::Get()->storage_info(); | |
| 147 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { | 147 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { |
| 148 StorageInfoProvider::Get()->StopWatching((*it)->id); | 148 StorageInfoProvider::Get()->StopWatching((*it)->id); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { | 152 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 154 | 154 |
| 155 watching_event_set_.insert(event_name); | 155 watching_event_set_.insert(event_name); |
| 156 if (watching_event_set_.count(event_name) > 1) | 156 if (watching_event_set_.count(event_name) > 1) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 312 |
| 313 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { | 313 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 314 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); | 314 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { | 317 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 318 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); | 318 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace extensions | 321 } // namespace extensions |
| OLD | NEW |