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

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: Update Created 7 years, 6 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..2d27dbed34719127b0abf39a2fa94b5f7bcdadd6
--- /dev/null
+++ b/chrome/browser/extensions/api/system_info_storage/test_storage_info_provider.cc
@@ -0,0 +1,97 @@
+// 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"
+
+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.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) {
+ extensions::StorageInfo results;
Jeffrey Yasskin 2013/07/02 23:00:50 Unless there's a reason I'm missing, call info->cl
Haojian Wu 2013/07/03 16:23:49 Done.
+ 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;
+ 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::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|
Jeffrey Yasskin 2013/07/02 23:00:50 But free space can never shrink? That seems like a
Haojian Wu 2013/07/03 16:23:49 There is one test data which the change_step is 0.
Jeffrey Yasskin 2013/07/03 21:44:48 change_step==0 just means the size doesn't change,
Haojian Wu 2013/07/04 00:41:17 Add TODO in TestStorageInfoProvider header.
+ // 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();
+}

Powered by Google App Engine
This is Rietveld 408576698