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