| 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_storage/storage_info_provider.h" | 5 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 81 StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
| 82 | 82 |
| 83 std::vector<chrome::StorageInfo>::const_iterator it = storage_list.begin(); | 83 std::vector<chrome::StorageInfo>::const_iterator it = storage_list.begin(); |
| 84 for (; it != storage_list.end(); ++it) { | 84 for (; it != storage_list.end(); ++it) { |
| 85 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); | 85 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); |
| 86 systeminfo::BuildStorageUnitInfo(*it, unit.get()); | 86 systeminfo::BuildStorageUnitInfo(*it, unit.get()); |
| 87 info_.push_back(unit); | 87 info_.push_back(unit); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 double StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( |
| 92 const std::string& transient_id) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 94 std::vector<chrome::StorageInfo> storage_list = |
| 95 StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
| 96 |
| 97 std::string device_id = |
| 98 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( |
| 99 transient_id); |
| 100 |
| 101 // Lookup the matched storage info by |device_id|. |
| 102 for (std::vector<chrome::StorageInfo>::const_iterator it = |
| 103 storage_list.begin(); |
| 104 it != storage_list.end(); ++it) { |
| 105 if (device_id == it->device_id()) |
| 106 return static_cast<double>(base::SysInfo::AmountOfFreeDiskSpace( |
| 107 base::FilePath(it->location()))); |
| 108 } |
| 109 |
| 110 return -1; |
| 111 } |
| 112 |
| 91 // static | 113 // static |
| 92 StorageInfoProvider* StorageInfoProvider::Get() { | 114 StorageInfoProvider* StorageInfoProvider::Get() { |
| 93 if (provider_.Get().get() == NULL) | 115 if (provider_.Get().get() == NULL) |
| 94 provider_.Get() = new StorageInfoProvider(); | 116 provider_.Get() = new StorageInfoProvider(); |
| 95 return provider_.Get(); | 117 return provider_.Get(); |
| 96 } | 118 } |
| 97 | 119 |
| 98 } // namespace extensions | 120 } // namespace extensions |
| OLD | NEW |