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 "extensions/browser/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 "components/storage_monitor/storage_info.h" | 11 #include "components/storage_monitor/storage_info.h" |
12 #include "components/storage_monitor/storage_monitor.h" | 12 #include "components/storage_monitor/storage_monitor.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 | 14 |
15 using storage_monitor::StorageInfo; | 15 using storage_monitor::StorageInfo; |
16 using storage_monitor::StorageMonitor; | 16 using storage_monitor::StorageMonitor; |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 using content::BrowserThread; | 20 using content::BrowserThread; |
21 using api::system_storage::StorageUnitInfo; | 21 using core_api::system_storage::StorageUnitInfo; |
22 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; | 22 using core_api::system_storage::STORAGE_UNIT_TYPE_FIXED; |
23 using api::system_storage::STORAGE_UNIT_TYPE_REMOVABLE; | 23 using core_api::system_storage::STORAGE_UNIT_TYPE_REMOVABLE; |
24 | 24 |
25 namespace systeminfo { | 25 namespace systeminfo { |
26 | 26 |
27 void BuildStorageUnitInfo(const StorageInfo& info, | 27 void BuildStorageUnitInfo(const StorageInfo& info, StorageUnitInfo* unit) { |
28 StorageUnitInfo* unit) { | |
29 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 28 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
30 info.device_id()); | 29 info.device_id()); |
31 unit->name = base::UTF16ToUTF8(info.GetDisplayName(false)); | 30 unit->name = base::UTF16ToUTF8(info.GetDisplayName(false)); |
32 // TODO(hmin): Might need to take MTP device into consideration. | 31 // TODO(hmin): Might need to take MTP device into consideration. |
33 unit->type = StorageInfo::IsRemovableDevice(info.device_id()) ? | 32 unit->type = StorageInfo::IsRemovableDevice(info.device_id()) |
34 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; | 33 ? STORAGE_UNIT_TYPE_REMOVABLE |
| 34 : STORAGE_UNIT_TYPE_FIXED; |
35 unit->capacity = static_cast<double>(info.total_size_in_bytes()); | 35 unit->capacity = static_cast<double>(info.total_size_in_bytes()); |
36 } | 36 } |
37 | 37 |
38 } // namespace systeminfo | 38 } // namespace systeminfo |
39 | 39 |
40 // Static member intialization. | 40 // Static member intialization. |
41 base::LazyInstance<scoped_refptr<StorageInfoProvider> > | 41 base::LazyInstance<scoped_refptr<StorageInfoProvider> > |
42 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | 42 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
43 | 43 |
44 StorageInfoProvider::StorageInfoProvider() { | 44 StorageInfoProvider::StorageInfoProvider() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // |PrepareQueryOnUIThread()|. | 77 // |PrepareQueryOnUIThread()|. |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 void StorageInfoProvider::GetAllStoragesIntoInfoList() { | 81 void StorageInfoProvider::GetAllStoragesIntoInfoList() { |
82 info_.clear(); | 82 info_.clear(); |
83 std::vector<StorageInfo> storage_list = | 83 std::vector<StorageInfo> storage_list = |
84 StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 84 StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
85 | 85 |
86 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin(); | 86 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin(); |
87 it != storage_list.end(); ++it) { | 87 it != storage_list.end(); |
| 88 ++it) { |
88 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); | 89 linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo()); |
89 systeminfo::BuildStorageUnitInfo(*it, unit.get()); | 90 systeminfo::BuildStorageUnitInfo(*it, unit.get()); |
90 info_.push_back(unit); | 91 info_.push_back(unit); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 double StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( | 95 double StorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( |
95 const std::string& transient_id) { | 96 const std::string& transient_id) { |
96 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 97 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
97 std::vector<StorageInfo> storage_list = | 98 std::vector<StorageInfo> storage_list = |
98 StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 99 StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
99 | 100 |
100 std::string device_id = | 101 std::string device_id = |
101 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( | 102 StorageMonitor::GetInstance()->GetDeviceIdForTransientId(transient_id); |
102 transient_id); | |
103 | 103 |
104 // Lookup the matched storage info by |device_id|. | 104 // Lookup the matched storage info by |device_id|. |
105 for (std::vector<StorageInfo>::const_iterator it = | 105 for (std::vector<StorageInfo>::const_iterator it = storage_list.begin(); |
106 storage_list.begin(); | 106 it != storage_list.end(); |
107 it != storage_list.end(); ++it) { | 107 ++it) { |
108 if (device_id == it->device_id()) | 108 if (device_id == it->device_id()) |
109 return static_cast<double>(base::SysInfo::AmountOfFreeDiskSpace( | 109 return static_cast<double>( |
110 base::FilePath(it->location()))); | 110 base::SysInfo::AmountOfFreeDiskSpace(base::FilePath(it->location()))); |
111 } | 111 } |
112 | 112 |
113 return -1; | 113 return -1; |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 StorageInfoProvider* StorageInfoProvider::Get() { | 117 StorageInfoProvider* StorageInfoProvider::Get() { |
118 if (provider_.Get().get() == NULL) | 118 if (provider_.Get().get() == NULL) |
119 provider_.Get() = new StorageInfoProvider(); | 119 provider_.Get() = new StorageInfoProvider(); |
120 return provider_.Get().get(); | 120 return provider_.Get().get(); |
121 } | 121 } |
122 | 122 |
123 } // namespace extensions | 123 } // namespace extensions |
OLD | NEW |