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

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

Issue 10905171: Add systemInfo.cpu.onUpdated event implementation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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/system_info_event_router.cc
diff --git a/chrome/browser/extensions/system_info_event_router.cc b/chrome/browser/extensions/system_info_event_router.cc
index d2c793378f26ec93f0da1e7dbe11cb6ae63cab18..f6dc20a1bcdbf7c01eb9c9a815c88cdb10aadfcc 100644
--- a/chrome/browser/extensions/system_info_event_router.cc
+++ b/chrome/browser/extensions/system_info_event_router.cc
@@ -9,17 +9,34 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "chrome/browser/extensions/event_names.h"
+#include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
#include "chrome/browser/extensions/api/system_info_storage/storage_info_provider.h"
+#include "chrome/common/extensions/api/experimental_system_info_cpu.h"
#include "chrome/common/extensions/api/experimental_system_info_storage.h"
namespace extensions {
+using api::experimental_system_info_cpu::CpuUpdateInfo;
using api::experimental_system_info_storage::StorageUnitInfo;
using api::experimental_system_info_storage::StorageChangeInfo;
using content::BrowserThread;
+namespace {
+
const char kSystemInfoEventPrefix[] = "experimental.systemInfo";
const char kStorageEventPrefix[] = "experimental.systemInfo.storage";
+const char kCpuEventPrefix[] = "experimental.systemInfo.cpu";
+
+static bool IsStorageEvent(const std::string& event_name) {
+ return event_name.compare(0, strlen(kStorageEventPrefix),
+ kStorageEventPrefix) == 0;
+}
+
+static bool IsCpuEvent(const std::string& event_name) {
+ return event_name.compare(0, strlen(kCpuEventPrefix), kCpuEventPrefix) == 0;
+}
+
+} // namespace
// static
SystemInfoEventRouter* SystemInfoEventRouter::GetInstance() {
@@ -37,10 +54,19 @@ void SystemInfoEventRouter::AddEventListener(const std::string& event_name) {
if (watching_event_set_.count(event_name) > 1)
return;
// Start watching the |event_name| event if the first event listener arrives.
- std::string prefix(kStorageEventPrefix);
- if (event_name.compare(0, prefix.size(), kStorageEventPrefix) == 0) {
+ // For systemInfo.storage event.
+ if (IsStorageEvent(event_name)) {
// TODO (hongbo): Start watching storage device information via calling
// SystemMonitor::StartWatchingStorage.
+ return;
+ }
+
+ // For systemInfo.cpu event.
+ if (IsCpuEvent(event_name)) {
+ CpuInfoProvider::Get()->StartSampling(
+ base::Bind(&SystemInfoEventRouter::OnNextCpuSampling,
+ base::Unretained(this)));
benwells 2012/09/21 08:19:50 Will sampling be stopped by the RemoveEventListene
Hongbo Min 2012/09/21 09:00:23 Yes, but mihai mentioned that RemoveEventListener
+ return;
}
}
@@ -52,13 +78,14 @@ void SystemInfoEventRouter::RemoveEventListener(
// In case of the last event listener is removed, we need to stop watching
// it to avoid unnecessary overhead.
- std::string prefix(kStorageEventPrefix);
- if (event_name.compare(
- 0, prefix.size(), kStorageEventPrefix) == 0) {
+ if (IsStorageEvent(event_name)) {
// TODO(hongbo): Stop watching storage device information via calling
// SystemMonitor::StopWatchingStorage.
return;
}
+ if (IsCpuEvent(event_name)) {
+ CpuInfoProvider::Get()->StopSampling();
+ }
}
// static
@@ -102,4 +129,11 @@ void SystemInfoEventRouter::DispatchEvent(const std::string& event_name,
BroadcastEventToRenderers(event_name, args.Pass(), GURL());
}
+void SystemInfoEventRouter::OnNextCpuSampling(scoped_ptr<CpuUpdateInfo> info) {
+ scoped_ptr<base::ListValue> args(new base::ListValue());
+ args->Append(info->ToValue().release());
+
+ DispatchEvent(event_names::kOnCpuUpdated, args.Pass());
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698