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

Unified Diff: chrome/browser/extensions/mock_system_info_watcher.cc

Issue 10836341: Add the basic code skeleton for system info event router (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add mock implementation for onAdded and onRemoved events Created 8 years, 4 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/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

Powered by Google App Engine
This is Rietveld 408576698