Index: chrome/browser/extensions/mock_system_info_watcher.cc |
diff --git a/chrome/browser/extensions/mock_system_info_watcher.cc b/chrome/browser/extensions/mock_system_info_watcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed0f2b019d1ab5676fb0bbae2e45232f4483321d |
--- /dev/null |
+++ b/chrome/browser/extensions/mock_system_info_watcher.cc |
@@ -0,0 +1,69 @@ |
+// Copyright (c) 2012 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/mock_system_info_watcher.h" |
+ |
+#include "chrome/browser/extensions/event_names.h" |
+ |
+namespace extensions { |
+ |
+namespace { |
+ |
+const int kDefaultInterval = 200; // default interval is 200ms. |
+const int kAvailableCapacityBase = 10000; |
+const int kChangeStep = 10; |
+ |
+} |
+ |
+MockSystemInfoWatcher::MockSystemInfoWatcher() { |
+} |
+ |
+MockSystemInfoWatcher::~MockSystemInfoWatcher() { |
+} |
+ |
+bool MockSystemInfoWatcher::PlatformStartWatching( |
+ const std::string& event_name) { |
+ // If the |event_name| event is already watched. |
+ if (IsWatching(event_name)) |
+ return true; |
+ |
+ if (event_name.compare( |
+ event_names::kOnStorageAvailableCapacityChanged) == 0) { |
+ // Start the timer to emulate storage.onChanged event. |
+ timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds(kDefaultInterval), |
+ this, &MockSystemInfoWatcher::OnTimeoutEvent); |
+ } |
+ return true; |
+} |
+ |
+bool MockSystemInfoWatcher::PlatformStopWatching( |
+ const std::string& event_name) { |
+ if (!IsWatching(event_name)) |
+ return false; |
+ |
+ if (event_name.compare( |
+ event_names::kOnStorageAvailableCapacityChanged) == 0) { |
+ timer_.Stop(); |
+ } |
+ return true; |
+} |
+ |
+void MockSystemInfoWatcher::OnTimeoutEvent() { |
+ static int count = 0; |
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnStorageDeviceAvailableCapacityChanged("/dev/sda1", |
+ kAvailableCapacityBase - kChangeStep*count)); |
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnStorageDeviceAdded("/dev/sda2", "removable", 4096, 2048)); |
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnStorageDeviceRemoved("/dev/sda2")); |
+ |
+ ++count; |
+} |
+ |
+} // namespace extensions |