| 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" |
| 11 #include "chrome/browser/storage_monitor/storage_monitor.h" | 11 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 using chrome::StorageMonitor; | |
| 18 using api::system_storage::StorageUnitInfo; | 17 using api::system_storage::StorageUnitInfo; |
| 19 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; | 18 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; |
| 20 using api::system_storage::STORAGE_UNIT_TYPE_REMOVABLE; | 19 using api::system_storage::STORAGE_UNIT_TYPE_REMOVABLE; |
| 21 | 20 |
| 22 namespace systeminfo { | 21 namespace systeminfo { |
| 23 | 22 |
| 24 void BuildStorageUnitInfo(const chrome::StorageInfo& info, | 23 void BuildStorageUnitInfo(const StorageInfo& info, |
| 25 StorageUnitInfo* unit) { | 24 StorageUnitInfo* unit) { |
| 26 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 25 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
| 27 info.device_id()); | 26 info.device_id()); |
| 28 unit->name = UTF16ToUTF8(info.name()); | 27 unit->name = UTF16ToUTF8(info.name()); |
| 29 // TODO(hmin): Might need to take MTP device into consideration. | 28 // TODO(hmin): Might need to take MTP device into consideration. |
| 30 unit->type = chrome::StorageInfo::IsRemovableDevice(info.device_id()) ? | 29 unit->type = StorageInfo::IsRemovableDevice(info.device_id()) ? |
| 31 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; | 30 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; |
| 32 unit->capacity = static_cast<double>(info.total_size_in_bytes()); | 31 unit->capacity = static_cast<double>(info.total_size_in_bytes()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 } // namespace systeminfo | 34 } // namespace systeminfo |
| 36 | 35 |
| 37 // Static member intialization. | 36 // Static member intialization. |
| 38 base::LazyInstance<scoped_refptr<StorageInfoProvider> > | 37 base::LazyInstance<scoped_refptr<StorageInfoProvider> > |
| 39 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | 38 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
| 40 | 39 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 70 | 69 |
| 71 bool StorageInfoProvider::QueryInfo() { | 70 bool StorageInfoProvider::QueryInfo() { |
| 72 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 71 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 73 // No info to query since we get all available storage devices' info in | 72 // No info to query since we get all available storage devices' info in |
| 74 // |PrepareQueryOnUIThread()|. | 73 // |PrepareQueryOnUIThread()|. |
| 75 return true; | 74 return true; |
| 76 } | 75 } |
| 77 | 76 |
| 78 void StorageInfoProvider::GetAllStoragesIntoInfoList() { | 77 void StorageInfoProvider::GetAllStoragesIntoInfoList() { |
| 79 info_.clear(); | 78 info_.clear(); |
| 80 std::vector<chrome::StorageInfo> storage_list = | 79 std::vector<StorageInfo> storage_list = |
| 81 StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 80 StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
| 82 | 81 |
| 83 std::vector<chrome::StorageInfo>::const_iterator it = storage_list.begin(); | 82 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin(); |
| 84 for (; it != storage_list.end(); ++it) { | 83 it != storage_list.end(); ++it) { |
| 85 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); | 84 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); |
| 86 systeminfo::BuildStorageUnitInfo(*it, unit.get()); | 85 systeminfo::BuildStorageUnitInfo(*it, unit.get()); |
| 87 info_.push_back(unit); | 86 info_.push_back(unit); |
| 88 } | 87 } |
| 89 } | 88 } |
| 90 | 89 |
| 91 // static | 90 // static |
| 92 StorageInfoProvider* StorageInfoProvider::Get() { | 91 StorageInfoProvider* StorageInfoProvider::Get() { |
| 93 if (provider_.Get().get() == NULL) | 92 if (provider_.Get().get() == NULL) |
| 94 provider_.Get() = new StorageInfoProvider(); | 93 provider_.Get() = new StorageInfoProvider(); |
| 95 return provider_.Get(); | 94 return provider_.Get(); |
| 96 } | 95 } |
| 97 | 96 |
| 98 } // namespace extensions | 97 } // namespace extensions |
| OLD | NEW |