OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_info_storage/storage_info_provide
r.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; | 17 using chrome::StorageMonitor; |
18 using api::experimental_system_info_storage::StorageUnitInfo; | 18 using api::system_storage::StorageUnitInfo; |
19 using api::experimental_system_info_storage::STORAGE_UNIT_TYPE_FIXED; | 19 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; |
20 using api::experimental_system_info_storage::STORAGE_UNIT_TYPE_REMOVABLE; | 20 using api::system_storage::STORAGE_UNIT_TYPE_REMOVABLE; |
21 | 21 |
22 namespace systeminfo { | 22 namespace systeminfo { |
23 | 23 |
24 const char kStorageTypeUnknown[] = "unknown"; | 24 const char kStorageTypeUnknown[] = "unknown"; |
25 const char kStorageTypeFixed[] = "fixed"; | 25 const char kStorageTypeFixed[] = "fixed"; |
26 const char kStorageTypeRemovable[] = "removable"; | 26 const char kStorageTypeRemovable[] = "removable"; |
27 | 27 |
28 void BuildStorageUnitInfo(const chrome::StorageInfo& info, | 28 void BuildStorageUnitInfo(const chrome::StorageInfo& info, |
29 StorageUnitInfo* unit) { | 29 StorageUnitInfo* unit) { |
30 unit->id = StorageInfoProvider::Get()->GetTransientIdForDeviceId( | 30 unit->id = StorageInfoProvider::Get()->GetTransientIdForDeviceId( |
31 info.device_id()); | 31 info.device_id()); |
32 unit->name = UTF16ToUTF8(info.name()); | 32 unit->name = UTF16ToUTF8(info.name()); |
33 // TODO(hmin): Might need to take MTP device into consideration. | 33 // TODO(hmin): Might need to take MTP device into consideration. |
34 unit->type = chrome::StorageInfo::IsRemovableDevice(info.device_id()) ? | 34 unit->type = chrome::StorageInfo::IsRemovableDevice(info.device_id()) ? |
35 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; | 35 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; |
36 unit->capacity = static_cast<double>(info.total_size_in_bytes()); | 36 unit->capacity = static_cast<double>(info.total_size_in_bytes()); |
37 unit->available_capacity = 0; | |
38 } | 37 } |
39 | 38 |
40 } // namespace systeminfo | 39 } // namespace systeminfo |
41 | 40 |
42 const int kDefaultPollingIntervalMs = 1000; | 41 const int kDefaultPollingIntervalMs = 1000; |
43 const char kWatchingTokenName[] = "_storage_info_watching_token_"; | 42 const char kWatchingTokenName[] = "_storage_info_watching_token_"; |
44 | 43 |
45 // Static member intialization. | 44 // Static member intialization. |
46 template<> | 45 template<> |
47 base::LazyInstance<scoped_refptr<SystemInfoProvider<StorageUnitInfoList> > > | 46 base::LazyInstance<scoped_refptr<SystemInfoProvider<StorageUnitInfoList> > > |
(...skipping 22 matching lines...) Expand all Loading... |
70 const base::Closure& do_query_info_callback) { | 69 const base::Closure& do_query_info_callback) { |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
72 // Register the |do_query_info_callback| callback to StorageMonitor. | 71 // Register the |do_query_info_callback| callback to StorageMonitor. |
73 // See the comments of StorageMonitor::EnsureInitialized about when the | 72 // See the comments of StorageMonitor::EnsureInitialized about when the |
74 // callback gets run. | 73 // callback gets run. |
75 StorageMonitor::GetInstance()->EnsureInitialized(do_query_info_callback); | 74 StorageMonitor::GetInstance()->EnsureInitialized(do_query_info_callback); |
76 } | 75 } |
77 | 76 |
78 bool StorageInfoProvider::QueryInfo() { | 77 bool StorageInfoProvider::QueryInfo() { |
79 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 78 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
80 for (StorageUnitInfoList::iterator it = info_.begin(); | 79 // No task to do in worker pool. |
81 it != info_.end(); ++it) { | |
82 int64 amount = GetStorageFreeSpaceFromTransientId((*it)->id); | |
83 if (amount > 0) | |
84 (*it)->available_capacity = static_cast<double>(amount); | |
85 } | |
86 | |
87 return true; | 80 return true; |
88 } | 81 } |
89 | 82 |
90 std::vector<chrome::StorageInfo> StorageInfoProvider::GetAllStorages() const { | 83 std::vector<chrome::StorageInfo> StorageInfoProvider::GetAllStorages() const { |
91 return StorageMonitor::GetInstance()->GetAllAvailableStorages(); | 84 return StorageMonitor::GetInstance()->GetAllAvailableStorages(); |
92 } | 85 } |
93 | 86 |
94 void StorageInfoProvider::GetAllStoragesIntoInfoList() { | 87 void StorageInfoProvider::GetAllStoragesIntoInfoList() { |
95 info_.clear(); | 88 info_.clear(); |
96 std::vector<chrome::StorageInfo> storage_list = GetAllStorages(); | 89 std::vector<chrome::StorageInfo> storage_list = GetAllStorages(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 const std::string& transient_id) const { | 261 const std::string& transient_id) const { |
269 return StorageMonitor::GetInstance()->GetDeviceIdForTransientId(transient_id); | 262 return StorageMonitor::GetInstance()->GetDeviceIdForTransientId(transient_id); |
270 } | 263 } |
271 | 264 |
272 // static | 265 // static |
273 StorageInfoProvider* StorageInfoProvider::Get() { | 266 StorageInfoProvider* StorageInfoProvider::Get() { |
274 return StorageInfoProvider::GetInstance<StorageInfoProvider>(); | 267 return StorageInfoProvider::GetInstance<StorageInfoProvider>(); |
275 } | 268 } |
276 | 269 |
277 } // namespace extensions | 270 } // namespace extensions |
OLD | NEW |