Chromium Code Reviews| Index: chrome/browser/extensions/system_info_event_router.cc |
| diff --git a/chrome/browser/extensions/system_info_event_router.cc b/chrome/browser/extensions/system_info_event_router.cc |
| index f6dc20a1bcdbf7c01eb9c9a815c88cdb10aadfcc..f0658bd5af89cf5ff221b433033bb09cbedefa01 100644 |
| --- a/chrome/browser/extensions/system_info_event_router.cc |
| +++ b/chrome/browser/extensions/system_info_event_router.cc |
| @@ -56,8 +56,12 @@ void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { |
| // Start watching the |event_name| event if the first event listener arrives. |
| // For systemInfo.storage event. |
| if (IsStorageEvent(event_name)) { |
| - // TODO (hongbo): Start watching storage device information via calling |
| - // SystemMonitor::StartWatchingStorage. |
| + StorageInfoProvider::Get()->AddObserver(this); |
| + StorageInfo info; |
| + if (StorageInfoProvider::Get()->QueryInfo(&info)) { |
| + for (StorageInfo::iterator it = info.begin(); it != info.end(); ++it) |
| + StorageInfoProvider::Get()->StartWatching((*it)->id); |
| + } |
| return; |
| } |
| @@ -79,8 +83,12 @@ void SystemInfoEventRouter::RemoveEventListener( |
| // In case of the last event listener is removed, we need to stop watching |
| // it to avoid unnecessary overhead. |
| if (IsStorageEvent(event_name)) { |
| - // TODO(hongbo): Stop watching storage device information via calling |
| - // SystemMonitor::StopWatchingStorage. |
| + StorageInfo info; |
| + if (StorageInfoProvider::Get()->QueryInfo(&info)) { |
| + for (StorageInfo::iterator it = info.begin(); it != info.end(); ++it) |
| + StorageInfoProvider::Get()->StopWatching((*it)->id); |
| + } |
| + StorageInfoProvider::Get()->RemoveObserver(this); |
| return; |
| } |
| if (IsCpuEvent(event_name)) { |
| @@ -94,19 +102,12 @@ bool SystemInfoEventRouter::IsSystemInfoEvent(const std::string& event_name) { |
| return event_name.compare(0, prefix.size(), prefix) == 0; |
| } |
| -void SystemInfoEventRouter::OnStorageAvailableCapacityChanged( |
| - const std::string& id, int64 available_capacity) { |
| - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| - base::Bind(&SystemInfoEventRouter::OnStorageAvailableCapacityChanged, |
| - base::Unretained(this), id, available_capacity)); |
| - return; |
| - } |
| - |
| - // We are on the UI thread now. |
| +// Called on UI thread since the observer is added from UI thread. |
| +void SystemInfoEventRouter::OnStorageFreeSpaceChanged( |
| + const std::string& id, double new_value, double old_value) { |
|
benwells
2013/01/31 04:04:57
I don't understand why the threading stuff changed
Hongbo Min
2013/02/01 07:06:50
Since the observers of StorageInfoProvider are hol
benwells
2013/02/04 04:21:41
Oh wow, I didn't realize that class was so smart.
|
| StorageChangeInfo info; |
| info.id = id; |
| - info.available_capacity = static_cast<double>(available_capacity); |
| + info.available_capacity = static_cast<double>(new_value); |
| scoped_ptr<base::ListValue> args(new base::ListValue()); |
| args->Append(info.ToValue().release()); |