summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 01:09:30 +0000
committerrdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-06 01:09:30 +0000
commita8dfa1d09afb7dff17eca7997ee7d2c55bc446ae (patch)
tree258d8ae795f05935a7db34806d760d40f0a3ff23 /chrome/browser
parentf78f20b0864f635b3e45c6abc8ab86878ab85af6 (diff)
downloadchromium_src-a8dfa1d09afb7dff17eca7997ee7d2c55bc446ae.zip
chromium_src-a8dfa1d09afb7dff17eca7997ee7d2c55bc446ae.tar.gz
chromium_src-a8dfa1d09afb7dff17eca7997ee7d2c55bc446ae.tar.bz2
CPM Event Construction
This provides code for cpm event construction, which will be used by other cpm classes. BUG=130212 TEST=NONE Review URL: https://chromiumcodereview.appspot.com/10542013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140682 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/performance_monitor/event.cc30
-rw-r--r--chrome/browser/performance_monitor/event.h68
-rw-r--r--chrome/browser/performance_monitor/performance_monitor_util.cc171
-rw-r--r--chrome/browser/performance_monitor/performance_monitor_util.h84
4 files changed, 353 insertions, 0 deletions
diff --git a/chrome/browser/performance_monitor/event.cc b/chrome/browser/performance_monitor/event.cc
new file mode 100644
index 0000000..84d10d6f
--- /dev/null
+++ b/chrome/browser/performance_monitor/event.cc
@@ -0,0 +1,30 @@
+// 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/performance_monitor/event.h"
+
+namespace performance_monitor {
+
+Event::Event(const EventType& type,
+ const base::Time& time,
+ scoped_ptr<base::DictionaryValue> data)
+ : type_(type), time_(time), data_(data.release()) {
+}
+
+Event::~Event() {
+}
+
+scoped_ptr<Event> Event::FromValue(scoped_ptr<base::DictionaryValue> data) {
+ int type = 0;
+ if (!data->GetInteger(std::string("type"), &type))
+ return scoped_ptr<Event>();
+ double time = 0.0;
+ if (!data->GetDouble(std::string("time"), &time))
+ return scoped_ptr<Event>();
+ return scoped_ptr<Event>(new Event(static_cast<EventType>(type),
+ base::Time::FromInternalValue((int64)time),
+ data.Pass()));
+}
+
+} // namespace performance_monitor
diff --git a/chrome/browser/performance_monitor/event.h b/chrome/browser/performance_monitor/event.h
new file mode 100644
index 0000000..fc02b52
--- /dev/null
+++ b/chrome/browser/performance_monitor/event.h
@@ -0,0 +1,68 @@
+// 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.
+
+#ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
+#define CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
+
+#include "base/values.h"
+#include "base/time.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace performance_monitor {
+
+// IMPORTANT: This is used as an indication of the event type within the
+// performance monitor database; do not change the order! If you add new events
+// to this list, place them above EVENT_NUMBER_OF_EVENTS.
+enum EventType {
+ EVENT_UNDEFINED,
+ EVENT_EXTENSION_INSTALL,
+ EVENT_EXTENSION_UNINSTALL,
+ EVENT_EXTENSION_UPDATE,
+ EVENT_EXTENSION_ENABLE,
+ EVENT_EXTENSION_UNLOAD,
+ EVENT_CHROME_UPDATE,
+ EVENT_RENDERER_FREEZE,
+ EVENT_RENDERER_CRASH,
+ EVENT_OOM_CRASH,
+ EVENT_UNCLEAN_SHUTDOWN,
+ EVENT_NUMBER_OF_EVENTS
+};
+
+// The wrapper class for the JSON-generated event classes for the performance
+// monitor. This class is used so we can pass around events in a single class,
+// rather than having a variety of different types (since JSON does not
+// currently support inheritance). Since the class will occasionally need to
+// be compared against other events, we construct it with type and time. Other
+// information should not be needed commonly, and is stored in a JSON-generated
+// DictionaryValue.
+class Event {
+ public:
+ Event(const EventType& type,
+ const base::Time& time,
+ scoped_ptr<base::DictionaryValue> data);
+ virtual ~Event();
+
+ // Construct an event from the given DictionaryValue; takes ownership of
+ // |data|.
+ static scoped_ptr<Event> FromValue(scoped_ptr<base::DictionaryValue> data);
+
+ // Accessors
+ EventType type() const { return type_; }
+ base::Time time() const { return time_; }
+ base::DictionaryValue* data() const { return data_.get(); }
+
+ private:
+
+ // The type of the event.
+ EventType type_;
+ // The time at which the event was recorded.
+ base::Time time_;
+ // The full JSON-generated value representing the information of the event;
+ // these data are described in chrome/browser/performance_monitor/events.json.
+ scoped_ptr<base::DictionaryValue> data_;
+};
+
+} // namespace performance_monitor
+
+#endif // CHROME_BROWSER_PERFORMANCE_MONITOR_EVENT_H_
diff --git a/chrome/browser/performance_monitor/performance_monitor_util.cc b/chrome/browser/performance_monitor/performance_monitor_util.cc
new file mode 100644
index 0000000..18cd15a
--- /dev/null
+++ b/chrome/browser/performance_monitor/performance_monitor_util.cc
@@ -0,0 +1,171 @@
+// 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/performance_monitor/performance_monitor_util.h"
+
+#include "base/json/json_writer.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/string_number_conversions.h"
+#include "chrome/browser/performance_monitor/events.h"
+
+namespace performance_monitor {
+namespace util {
+
+scoped_ptr<Event> CreateExtensionInstallEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description) {
+ events::ExtensionInstall event;
+ event.type = EVENT_EXTENSION_INSTALL;
+ event.time = static_cast<double>(time.ToInternalValue());
+ event.extension_id = id;
+ event.extension_name = name;
+ event.extension_url = url;
+ event.extension_location = location;
+ event.extension_version = version;
+ event.extension_description = description;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_EXTENSION_INSTALL, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateExtensionUninstallEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description) {
+ events::ExtensionUninstall event;
+ event.type = EVENT_EXTENSION_UNINSTALL;
+ event.time = static_cast<double>(time.ToInternalValue());
+ event.extension_id = id;
+ event.extension_name = name;
+ event.extension_url = url;
+ event.extension_location = location;
+ event.extension_version = version;
+ event.extension_description = description;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_EXTENSION_UNINSTALL, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateExtensionUnloadEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description,
+ const extension_misc::UnloadedExtensionReason& reason) {
+ events::ExtensionUnload event;
+ event.type = EVENT_EXTENSION_UNLOAD;
+ event.time = static_cast<double>(time.ToInternalValue());
+ event.extension_id = id;
+ event.extension_name = name;
+ event.extension_url = url;
+ event.extension_location = location;
+ event.extension_version = version;
+ event.extension_description = description;
+ event.unload_reason = reason;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_EXTENSION_UNLOAD, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateExtensionEnableEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description) {
+ events::ExtensionEnable event;
+ event.type = EVENT_EXTENSION_ENABLE;
+ event.time = static_cast<double>(time.ToInternalValue());
+ event.extension_id = id;
+ event.extension_name = name;
+ event.extension_url = url;
+ event.extension_location = location;
+ event.extension_version = version;
+ event.extension_description = description;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_EXTENSION_ENABLE, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateExtensionUpdateEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description) {
+ events::ExtensionUpdate event;
+ event.type = EVENT_EXTENSION_UPDATE;
+ event.time = static_cast<double>(time.ToInternalValue());
+ event.extension_id = id;
+ event.extension_name = name;
+ event.extension_url = url;
+ event.extension_location = location;
+ event.extension_version = version;
+ event.extension_description = description;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_EXTENSION_UPDATE, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateRendererFreezeEvent(
+ const base::Time& time,
+ const std::string& url) {
+ events::RendererFreeze event;
+ event.type = EVENT_RENDERER_FREEZE;
+ event.time = static_cast<double>(time.ToInternalValue());
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_RENDERER_FREEZE, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateCrashEvent(
+ const base::Time& time,
+ const EventType& type,
+ const std::string& url) {
+ events::RendererFreeze event;
+ event.type = type;
+ event.time = static_cast<double>(time.ToInternalValue());
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ type, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateUncleanShutdownEvent(const base::Time& time) {
+ events::UncleanShutdown event;
+ event.type = EVENT_UNCLEAN_SHUTDOWN;
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_UNCLEAN_SHUTDOWN, time, value.Pass()));
+}
+
+scoped_ptr<Event> CreateChromeUpdateEvent(
+ const base::Time& time,
+ const std::string& old_version,
+ const std::string& new_version) {
+ events::ChromeUpdate event;
+ event.type = EVENT_CHROME_UPDATE;
+ event.time = static_cast<double>(time.ToInternalValue());
+ scoped_ptr<base::DictionaryValue> value = event.ToValue();
+ return scoped_ptr<Event>(new Event(
+ EVENT_CHROME_UPDATE, time, value.Pass()));
+}
+
+} // namespace util
+} // namespace performance_monitor
diff --git a/chrome/browser/performance_monitor/performance_monitor_util.h b/chrome/browser/performance_monitor/performance_monitor_util.h
new file mode 100644
index 0000000..a2c1d3a
--- /dev/null
+++ b/chrome/browser/performance_monitor/performance_monitor_util.h
@@ -0,0 +1,84 @@
+// 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.
+
+#ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_UTIL_H_
+#define CHROME_BROWSER_PERFORMANCE_MONITOR_UTIL_H_
+
+#include "base/time.h"
+#include "chrome/browser/performance_monitor/event.h"
+#include "chrome/common/extensions/extension_constants.h"
+
+namespace performance_monitor {
+namespace util {
+
+// These are a collection of methods designed to create an event to store the
+// pertinent information, given all the fields. Please use these methods to
+// create any PerformanceMonitor events, as this will ensure strong-typing
+// guards that performance_monitor::Event() will not.
+scoped_ptr<Event> CreateExtensionInstallEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description);
+
+scoped_ptr<Event> CreateExtensionUnloadEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description,
+ const extension_misc::UnloadedExtensionReason& reason);
+
+scoped_ptr<Event> CreateExtensionUninstallEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description);
+
+scoped_ptr<Event> CreateExtensionEnableEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description);
+
+scoped_ptr<Event> CreateExtensionUpdateEvent(
+ const base::Time& time,
+ const std::string& id,
+ const std::string& name,
+ const std::string& url,
+ const int& location,
+ const std::string& version,
+ const std::string& description);
+
+scoped_ptr<Event> CreateRendererFreezeEvent(
+ const base::Time& time,
+ const std::string& url);
+
+scoped_ptr<Event> CreateCrashEvent(
+ const base::Time& time,
+ const EventType& type,
+ const std::string& url);
+
+scoped_ptr<Event> CreateUncleanShutdownEvent(const base::Time& time);
+
+scoped_ptr<Event> CreateChromeUpdateEvent(
+ const base::Time& time,
+ const std::string& old_version,
+ const std::string& new_version);
+
+} // namespace util
+} // namespace performance_monitor
+
+#endif // CHROME_BROWSER_PERFORMANCE_MONITOR_UTIL_H__