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; | 17 using chrome::StorageMonitor; |
18 using api::system_storage::StorageUnitInfo; | 18 using api::system_storage::StorageUnitInfo; |
19 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; | 19 using api::system_storage::STORAGE_UNIT_TYPE_FIXED; |
20 using api::system_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 void BuildStorageUnitInfo(const chrome::StorageInfo& info, | 24 void BuildStorageUnitInfo(const chrome::StorageInfo& info, |
25 StorageUnitInfo* unit) { | 25 StorageUnitInfo* unit) { |
26 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 26 unit->id = StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
27 info.device_id()); | 27 info.device_id()); |
28 unit->name = UTF16ToUTF8(info.name()); | |
29 // TODO(hmin): Might need to take MTP device into consideration. | |
30 unit->type = chrome::StorageInfo::IsRemovableDevice(info.device_id()) ? | |
31 STORAGE_UNIT_TYPE_REMOVABLE : STORAGE_UNIT_TYPE_FIXED; | |
32 unit->capacity = static_cast<double>(info.total_size_in_bytes()); | 28 unit->capacity = static_cast<double>(info.total_size_in_bytes()); |
| 29 |
| 30 if (chrome::StorageInfo::IsRemovableDevice(info.device_id())) { |
| 31 // TODO(hmin): Might need to take MTP device into consideration. |
| 32 unit->name = base::UTF16ToUTF8(info.GetDisplayName(false)); |
| 33 unit->type = STORAGE_UNIT_TYPE_REMOVABLE; |
| 34 } else { |
| 35 unit->name = base::UTF16ToUTF8(info.storage_label()); |
| 36 unit->type = STORAGE_UNIT_TYPE_FIXED; |
| 37 } |
33 } | 38 } |
34 | 39 |
35 } // namespace systeminfo | 40 } // namespace systeminfo |
36 | 41 |
37 // Static member intialization. | 42 // Static member intialization. |
38 base::LazyInstance<scoped_refptr<StorageInfoProvider> > | 43 base::LazyInstance<scoped_refptr<StorageInfoProvider> > |
39 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | 44 StorageInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
40 | 45 |
41 StorageInfoProvider::StorageInfoProvider() { | 46 StorageInfoProvider::StorageInfoProvider() { |
42 } | 47 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 94 } |
90 | 95 |
91 // static | 96 // static |
92 StorageInfoProvider* StorageInfoProvider::Get() { | 97 StorageInfoProvider* StorageInfoProvider::Get() { |
93 if (provider_.Get().get() == NULL) | 98 if (provider_.Get().get() == NULL) |
94 provider_.Get() = new StorageInfoProvider(); | 99 provider_.Get() = new StorageInfoProvider(); |
95 return provider_.Get(); | 100 return provider_.Get(); |
96 } | 101 } |
97 | 102 |
98 } // namespace extensions | 103 } // namespace extensions |
OLD | NEW |