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

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

Issue 16707002: [SystemInfo API] Rewrite storage info provider using storage monitor impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add explicit destructors in UnitTestStorageInfoProvider to avoid build error. Created 7 years, 5 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..884bbf22d1d05fa98d490b6fe3023c78303c56d1
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
@@ -0,0 +1,99 @@
+// 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/strings/utf_string_conversions.h"
+
+namespace extensions {
+
+using api::experimental_system_info_storage::ParseStorageUnitType;
+using api::experimental_system_info_storage::StorageUnitInfo;
+using systeminfo::kStorageTypeFixed;
+using systeminfo::kStorageTypeRemovable;
+using systeminfo::kStorageTypeUnknown;
+
+// Watching interval for testing.
+const size_t kTestingIntervalMS = 10;
+
+TestStorageInfoProvider::TestStorageInfoProvider(
+ const struct TestStorageUnitInfo* testing_data, size_t n)
+ : testing_data_(testing_data, testing_data + n) {
+ SetWatchingIntervalForTesting(kTestingIntervalMS);
+}
+
+TestStorageInfoProvider::~TestStorageInfoProvider() {
+}
+
+// static
+chrome::StorageInfo TestStorageInfoProvider::BuildStorageInfo(
+ const TestStorageUnitInfo& unit) {
+ chrome::StorageInfo info(
+ unit.device_id,
+ UTF8ToUTF16(unit.name),
+ base::FilePath::StringType(), /* no location */
+ string16(), /* no storage label */
+ string16(), /* no storage vendor */
+ string16(), /* no storage model */
+ unit.capacity);
+ return info;
+}
+
+bool TestStorageInfoProvider::QueryInfo(extensions::StorageInfo* info) {
+ info->clear();
+ for (size_t i = 0; i < testing_data_.size(); ++i) {
+ linked_ptr<StorageUnitInfo> unit(new StorageUnitInfo());
+ unit->id = testing_data_[i].transient_id;
+ unit->name = testing_data_[i].name;
+ unit->type = ParseStorageUnitType(testing_data_[i].type);
+ unit->capacity = testing_data_[i].capacity;
+ unit->available_capacity = testing_data_[i].available_capacity;
+ info->push_back(unit);
+ }
+ 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::GetStorageFreeSpaceFromTransientId(
+ const std::string& transient_id) {
+ int64 available_capacity = -1;
+ for (size_t i = 0; i < testing_data_.size(); ++i) {
+ if (testing_data_[i].transient_id == transient_id) {
+ available_capacity = testing_data_[i].available_capacity;
+ // 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;
+ break;
+ }
+ }
+ return available_capacity;
+}
+
+std::string TestStorageInfoProvider::GetTransientIdForDeviceId(
+ const std::string& device_id) const {
+ for (size_t i = 0; i < testing_data_.size(); ++i) {
+ if (testing_data_[i].device_id == device_id)
+ return testing_data_[i].transient_id;
+ }
+ return std::string();
+}
+
+std::string TestStorageInfoProvider::GetDeviceIdForTransientId(
+ const std::string& transient_id) const {
+ for (size_t i = 0; i < testing_data_.size(); ++i) {
+ if (testing_data_[i].transient_id == transient_id)
+ return testing_data_[i].device_id;
+ }
+ return std::string();
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698