Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1549)

Unified Diff: chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc

Issue 15896007: [SystemInfo API] Rewrite storage info provider using storage monitor impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix comments from thestig Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
diff --git a/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..91a87b3ab184ffeab7987c4d6a12073d37db09b9
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
@@ -0,0 +1,96 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.h"
+
+#include "base/utf_string_conversions.h"
+
+using extensions::api::experimental_system_info_storage::ParseStorageUnitType;
+using extensions::api::experimental_system_info_storage::StorageUnitInfo;
+using extensions::StorageInfoProvider;
+using extensions::systeminfo::kStorageTypeFixed;
+using extensions::systeminfo::kStorageTypeRemovable;
+using extensions::systeminfo::kStorageTypeUnknown;
+
+// Watching interval for testing.
+const size_t kTestingIntervalMS = 10;
+
+TestStorageInfoProvider::TestStorageInfoProvider(
+ const struct TestUnitInfo testing_data[], size_t n)
+ : testing_data_(testing_data, testing_data + n) {
+ SetWatchingIntervalForTesting(kTestingIntervalMS);
+}
+
+TestStorageInfoProvider::~TestStorageInfoProvider() {
+}
+
+// static
+chrome::StorageInfo TestStorageInfoProvider::BuildStorageInfo(
+ const TestUnitInfo& unit) {
+ chrome::StorageInfo info(
+ unit.id,
+ UTF8ToUTF16(unit.name),
+#if defined(OS_POSIX)
+ unit.location,
+#elif defined(OS_WIN)
+ UTF8ToWide(unit.location),
+#endif
+ string16(), /* no storage label */
+ UTF8ToUTF16(unit.vendor_name),
+ UTF8ToUTF16(unit.model_name),
+ unit.capacity);
+ return info;
+}
+
+bool TestStorageInfoProvider::QueryInfo(extensions::StorageUnitList* info) {
+ extensions::StorageUnitList results;
+ for (size_t i = 0; i < testing_data_.size(); i++) {
+ linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
+ unit->id = testing_data_[i].id;
+ unit->name = testing_data_[i].name;
+ unit->location = testing_data_[i].location;
+ unit->vendor_name = testing_data_[i].vendor_name;
+ unit->model_name = testing_data_[i].model_name;
+ unit->type = ParseStorageUnitType(testing_data_[i].type);
+ unit->capacity = testing_data_[i].capacity;
+ unit->available_capacity = testing_data_[i].available_capacity;
+ results.push_back(unit);
+ }
+ info->swap(results);
+ return true;
+}
+
+std::vector<chrome::StorageInfo>
+TestStorageInfoProvider::GetAllStorages() const {
+ std::vector<chrome::StorageInfo> results;
+ for (size_t i = 0; i < testing_data_.size(); ++i)
+ results.push_back(BuildStorageInfo(testing_data_[i]));
+
+ return results;
+}
+
+int64 TestStorageInfoProvider::GetStorageFreeSpace(
+ const base::FilePath& mount_path) {
+ for (size_t i = 0; i < testing_data_.size(); i++) {
+ if (testing_data_[i].location == mount_path.AsUTF8Unsafe()) {
+ // We simulate free space change by increasing the |available_capacity|
+ // with a fixed change step.
+ testing_data_[i].available_capacity += testing_data_[i].change_step;
+ return testing_data_[i].available_capacity;
+ }
+ }
+ return -1;
+}
+
+bool TestStorageInfoProvider::GetStoragePathFromId(const std::string& id,
+ base::FilePath* mount_path) {
+ for (size_t i = 0; i < testing_data_.size(); i++) {
+ if (testing_data_[i].id == id) {
+ *mount_path = base::FilePath::FromUTF8Unsafe(testing_data_[i].location);
+ return true;
+ }
+ }
+ return false;
+}
+

Powered by Google App Engine
This is Rietveld 408576698