From 16c4c44cfa3569daca521e4886855ff0f6cc7569 Mon Sep 17 00:00:00 2001 From: "rdevlin.cronin@chromium.org" Date: Tue, 4 Sep 2012 21:09:41 +0000 Subject: CPM Localization WebUI change to meet the new spec and add in localization. BUG=130212 TBR=thakis@chromium.org (for gypi changes) Review URL: https://chromiumcodereview.appspot.com/10836321 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154811 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/app/generated_resources.grd | 260 +++++++++++++ .../performance_monitor/database_unittest.cc | 2 +- chrome/browser/performance_monitor/event.cc | 26 -- chrome/browser/performance_monitor/event.h | 7 +- chrome/browser/performance_monitor/metric.h | 3 +- .../browser/performance_monitor/metric_details.cc | 137 ------- .../browser/performance_monitor/metric_details.h | 25 -- .../performance_monitor/performance_monitor.cc | 9 + .../performance_monitor_l10n.cc | 410 +++++++++++++++++++++ .../performance_monitor/performance_monitor_l10n.h | 37 ++ .../performance_monitor_ui_constants.h | 46 +++ .../ui/webui/performance_monitor/web_ui_handler.cc | 290 ++++++++++++--- .../ui/webui/performance_monitor/web_ui_handler.h | 8 +- chrome/chrome_browser.gypi | 5 +- 14 files changed, 1007 insertions(+), 258 deletions(-) delete mode 100644 chrome/browser/performance_monitor/metric_details.cc delete mode 100644 chrome/browser/performance_monitor/metric_details.h create mode 100644 chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.cc create mode 100644 chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h create mode 100644 chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 67a777e..d0b7bcd 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4291,6 +4291,266 @@ Public Exponent ($324 bits): Instant: $1http://www.google.com/ + + + + Extensions + + + Events that are related to any extensions that are (or have been) installed in $1Chrome + + + Installs + + + Occurrences when an extension was installed + + + Extension Installed + + + Uninstalls + + + Occurrences when an extension was uninstalled + + + Extension Uninstalled + + + Updates + + + Occurrences when an extension was updated + + + Extension Updated + + + Enables + + + Occurrences when an extension was enabled + + + Extension Enabled + + + Disables + + + Occurrences when an extension was disabled + + + Extension Disabled + + + $1Google Chrome + + + Events that are related to the $1Chrome system. + + + Updates + + + Occurrences when the version of $1Chrome changed + + + $1Chrome Updated + + + Exceptions + + + Events relating to $1Chrome crashes and failures + + + Renderer Freezes + + + Occurrences when a tab became unresponsive + + + Renderer Froze + + + Renderer Crashes + + + Occurrences when a tab crashed ("$1Aw, Snap!") + + + Renderer Crashed + + + Process Kills + + + Occurrences when the OS killed a tab's process ("$1He's dead, Jim!") + + + Process Killed + + + Unclean Exits + + + Occurrences when $1Chrome did not shut down correctly + + + Unclean Exit + + + Extension ID + + + Extension Name + + + Extension URL + + + Extension Location + + + Extension Version + + + Extension Description + + + Previous Version + + + Current Version + + + URL + + + Profile Name + + + + CPU + + + Metrics relating to the effect of $1Chrome on the system's CPU + + + CPU Usage + + + The combined CPU usage of all processes related to $1Chrome + + + Memory + + + Metrics relating to the effect of $1Chrome on the system's memory + + + Private Memory Usage + + + The combined private memory usage of all processes related to $1Chrome + + + Shared Memory Usage + + + The combined shared memory usage of all processes related to $1Chrome + + + Timing + + + Metrics relating to the speed with which $1Chrome performs requested actions + + + Startups + + + The time it takes to fully start $1Chrome + + + Test Startups + + + The time it takes to fully start $1Chrome in a testing environment + + + Session Restores + + + The time it takes to restore a previous browsing session + + + Page Loads + + + The time it takes to load a web page + + + Network + + + Metrics related to the network usage of $1Chrome + + + Bytes Read + + + The number of bytes read across the network + + + + Bytes + + + Kilobytes + + + Megabytes + + + Gigabytes + + + Terabytes + + + Microseconds + + + Milliseconds + + + Seconds + + + Minutes + + + Hours + + + Days + + + Weeks + + + Months + + + Years + + + Percent + + Installed theme "$1Snowflake Theme". diff --git a/chrome/browser/performance_monitor/database_unittest.cc b/chrome/browser/performance_monitor/database_unittest.cc index 3a18553..4fef765 100644 --- a/chrome/browser/performance_monitor/database_unittest.cc +++ b/chrome/browser/performance_monitor/database_unittest.cc @@ -12,7 +12,7 @@ #include "base/scoped_temp_dir.h" #include "base/time.h" #include "chrome/browser/performance_monitor/database.h" -#include "chrome/browser/performance_monitor/metric_details.h" +#include "chrome/browser/performance_monitor/metric.h" #include "chrome/browser/performance_monitor/performance_monitor_util.h" #include "chrome/common/extensions/extension.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/performance_monitor/event.cc b/chrome/browser/performance_monitor/event.cc index 43738f6..46b48b9 100644 --- a/chrome/browser/performance_monitor/event.cc +++ b/chrome/browser/performance_monitor/event.cc @@ -7,32 +7,6 @@ #include "base/logging.h" namespace performance_monitor { -namespace { - -// Keep this array synced with EventTypes in the header file. -// TODO(mtytel): i18n. -const char* kEventTypeNames[] = { - "Undefined", - "Extension Installs", - "Extension Uninstalls", - "Extension Updates", - "Extension Enables", - "Extension Disables", - "Chrome Updates", - "Renderer Freezes", - "Renderer Crashes", - "Out of Memory Crashes", - "Unclean Shutdowns" -}; -COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kEventTypeNames) == EVENT_NUMBER_OF_EVENTS, - event_names_incorrect_size); - -} // namespace - -const char* EventTypeToString(EventType event_type) { - DCHECK_GT(EVENT_NUMBER_OF_EVENTS, event_type); - return kEventTypeNames[event_type]; -} Event::Event(const EventType& type, const base::Time& time, diff --git a/chrome/browser/performance_monitor/event.h b/chrome/browser/performance_monitor/event.h index 60f4c94..a4fc2c5 100644 --- a/chrome/browser/performance_monitor/event.h +++ b/chrome/browser/performance_monitor/event.h @@ -12,9 +12,10 @@ 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 and add a string to -// kEventTypeNames in the cc file. +// performance monitor database; do not change the order! If you add new +// event types to this list, place them above NUMBER_OF_EVENTS and add the +// appropriate messages/functions in generated_resources.grd and in +// chrome/browser/ui/webui/performance_monitor/l10n_util. enum EventType { EVENT_UNDEFINED, EVENT_EXTENSION_INSTALL, diff --git a/chrome/browser/performance_monitor/metric.h b/chrome/browser/performance_monitor/metric.h index 56d3e48..7d717b9 100644 --- a/chrome/browser/performance_monitor/metric.h +++ b/chrome/browser/performance_monitor/metric.h @@ -13,7 +13,8 @@ namespace performance_monitor { // IMPORTANT: This is used as an indication of the metric type within the // performance monitor database; do not change the order! If you add new // metric types to this list, place them above METRIC_NUMBER_OF_METRICS and add -// the appropriate constants to metric_details. +// the appropriate messages/functions in generated_resources.grd and in +// chrome/browser/ui/webui/performance_monitor/l10n_util. enum MetricType { METRIC_CPU_USAGE, METRIC_PRIVATE_MEMORY_USAGE, diff --git a/chrome/browser/performance_monitor/metric_details.cc b/chrome/browser/performance_monitor/metric_details.cc deleted file mode 100644 index 1bcf966..0000000 --- a/chrome/browser/performance_monitor/metric_details.cc +++ /dev/null @@ -1,137 +0,0 @@ -// 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/metric_details.h" - -#include "base/logging.h" -#include "chrome/browser/performance_monitor/constants.h" - -namespace performance_monitor { -namespace { - -// Metric details follow. -// All metric details have the following constants: -// - Name -// - Description -// - Units -// - TickSize (the smallest possible maximum which will be viewed in the ui.) - -// CPU Usage -const char kMetricCPUUsageName[] = "CPU Usage"; -const char kMetricCPUUsageDescription[] = "The CPU usage measured in percent."; -const char kMetricCPUUsageUnits[] = "percent"; -const double kMetricCPUUsageTickSize = 100.0; - -// Private Memory Usage -const char kMetricPrivateMemoryUsageName[] = "Private Memory Usage"; -const char kMetricPrivateMemoryUsageDescription[] = - "The total private memory usage of all chrome processes measured in bytes."; -const char kMetricPrivateMemoryUsageUnits[] = "bytes"; -const double kMetricPrivateMemoryUsageTickSize = 10000000.0; - -// Shared Memory Usage -const char kMetricSharedMemoryUsageName[] = "Shared Memory Usage"; -const char kMetricSharedMemoryUsageDescription[] = - "The total shared memory usage of all chrome processes measured in bytes."; -const char kMetricSharedMemoryUsageUnits[] = "bytes"; -const double kMetricSharedMemoryUsageTickSize = 10000000.0; - -// Startup Time -const char kMetricStartupTimeName[] = "Startup Time"; -const char kMetricStartupTimeDescription[] = - "The startup time measured in microseconds"; -const char kMetricStartupTimeUnits[] = "microseconds"; -const double kMetricStartupTimeTickSize = 5000000; - -// Test Startup Time -const char kMetricTestStartupTimeName[] = "Test Startup Time"; -const char kMetricTestStartupTimeDescription[] = - "The startup time of test startups measured in microseconds"; -const char kMetricTestStartupTimeUnits[] = "microseconds"; -const double kMetricTestStartupTimeTickSize = 5000000; - -// Session Restore Time -const char kMetricSessionRestoreTimeName[] = "Session Restore Time"; -const char kMetricSessionRestoreTimeDescription[] = - "The session restore time measured in microseconds"; -const char kMetricSessionRestoreTimeUnits[] = "microseconds"; -const double kMetricSessionRestoreTimeTickSize = 5000000; - -// Page Load Time -const char kMetricPageLoadTimeName[] = "Page Load Time"; -const char kMetricPageLoadTimeDescription[] = - "The amount of time taken to load a page measured in microseconds."; -const char kMetricPageLoadTimeUnits[] = "microseconds"; -const double kMetricPageLoadTimeTickSize = 30000000.0; - -// Network Bytes Read -const char kMetricNetworkBytesReadName[] = "Network Bytes Read"; -const char kMetricNetworkBytesReadDescription[] = - "The number of bytes read across the network."; -const char kMetricNetworkBytesReadUnits[] = "bytes"; -const double kMetricNetworkBytesReadTickSize = 2000000.0; - -// Keep this array synced with MetricTypes in the header file. -// TODO(mtytel): i18n. -const MetricDetails kMetricDetailsList[] = { - { - kMetricCPUUsageName, - kMetricCPUUsageDescription, - kMetricCPUUsageUnits, - kMetricCPUUsageTickSize, - }, - { - kMetricPrivateMemoryUsageName, - kMetricPrivateMemoryUsageDescription, - kMetricPrivateMemoryUsageUnits, - kMetricPrivateMemoryUsageTickSize - }, - { - kMetricSharedMemoryUsageName, - kMetricSharedMemoryUsageDescription, - kMetricSharedMemoryUsageUnits, - kMetricSharedMemoryUsageTickSize - }, - { - kMetricStartupTimeName, - kMetricStartupTimeDescription, - kMetricStartupTimeUnits, - kMetricStartupTimeTickSize - }, - { - kMetricTestStartupTimeName, - kMetricTestStartupTimeDescription, - kMetricTestStartupTimeUnits, - kMetricTestStartupTimeTickSize - }, - { - kMetricSessionRestoreTimeName, - kMetricSessionRestoreTimeDescription, - kMetricSessionRestoreTimeUnits, - kMetricSessionRestoreTimeTickSize - }, - { - kMetricPageLoadTimeName, - kMetricPageLoadTimeDescription, - kMetricPageLoadTimeUnits, - kMetricPageLoadTimeTickSize - }, - { - kMetricNetworkBytesReadName, - kMetricNetworkBytesReadDescription, - kMetricNetworkBytesReadUnits, - kMetricNetworkBytesReadTickSize - } -}; -COMPILE_ASSERT(ARRAYSIZE_UNSAFE(kMetricDetailsList) == METRIC_NUMBER_OF_METRICS, - metric_names_incorrect_size); - -} // namespace - -const MetricDetails* GetMetricDetails(MetricType metric_type) { - DCHECK_GT(METRIC_NUMBER_OF_METRICS, metric_type); - return &kMetricDetailsList[metric_type]; -} - -} // namespace performance_monitor diff --git a/chrome/browser/performance_monitor/metric_details.h b/chrome/browser/performance_monitor/metric_details.h deleted file mode 100644 index 4f3b163..0000000 --- a/chrome/browser/performance_monitor/metric_details.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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_METRIC_DETAILS_H_ -#define CHROME_BROWSER_PERFORMANCE_MONITOR_METRIC_DETAILS_H_ - -#include - -#include "chrome/browser/performance_monitor/metric.h" - -namespace performance_monitor { - -struct MetricDetails { - const char* const name; - const char* const description; - const char* const units; - const double tick_size; -}; - -const MetricDetails* GetMetricDetails(MetricType event_type); - -} // namespace performance_monitor - -#endif // CHROME_BROWSER_PERFORMANCE_MONITOR_METRIC_DETAILS_H_ diff --git a/chrome/browser/performance_monitor/performance_monitor.cc b/chrome/browser/performance_monitor/performance_monitor.cc index ff5eebb..8646e1f 100644 --- a/chrome/browser/performance_monitor/performance_monitor.cc +++ b/chrome/browser/performance_monitor/performance_monitor.cc @@ -45,6 +45,8 @@ const uint32 kAccessFlags = base::kProcessAccessDuplicateHandle | base::kProcessAccessTerminate | base::kProcessAccessWaitForTermination; +bool g_started_initialization = false; + std::string TimeToString(base::Time time) { int64 time_int64 = time.ToInternalValue(); return base::Int64ToString(time_int64); @@ -91,6 +93,13 @@ PerformanceMonitor* PerformanceMonitor::GetInstance() { } void PerformanceMonitor::Start() { + CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + // Avoid responding to multiple calls to Start(). + if (g_started_initialization) + return; + + g_started_initialization = true; util::PostTaskToDatabaseThreadAndReply( FROM_HERE, base::Bind(&PerformanceMonitor::InitOnBackgroundThread, diff --git a/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.cc b/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.cc new file mode 100644 index 0000000..02cddbc --- /dev/null +++ b/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.cc @@ -0,0 +1,410 @@ +// 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/ui/webui/performance_monitor/performance_monitor_l10n.h" + +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +namespace performance_monitor { + +// Event-Related +string16 GetLocalizedStringFromEventCategory(const EventCategory category) { + if (category == EVENT_CATEGORY_CHROME) { + return l10n_util::GetStringFUTF16( + IDS_PERFORMANCE_MONITOR_CHROME_EVENT_CATEGORY, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + } + + int string_id = 0; + switch (category) { + case EVENT_CATEGORY_EXTENSIONS: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY; + break; + case EVENT_CATEGORY_EXCEPTIONS: + string_id = IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +string16 GetLocalizedStringForEventCategoryDescription( + const EventCategory category) { + int string_id = 0; + switch (category) { + case EVENT_CATEGORY_EXTENSIONS: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY_DESCRIPTION; + break; + case EVENT_CATEGORY_CHROME: + string_id = IDS_PERFORMANCE_MONITOR_CHROME_EVENT_CATEGORY_DESCRIPTION; + break; + case EVENT_CATEGORY_EXCEPTIONS: + string_id = IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY_DESCRIPTION; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringFUTF16( + string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); +} + +string16 GetLocalizedStringFromEventType(const EventType type) { + int string_id = 0; + + switch (type) { + case EVENT_EXTENSION_INSTALL: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT; + break; + case EVENT_EXTENSION_UNINSTALL: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT; + break; + case EVENT_EXTENSION_UPDATE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT; + break; + case EVENT_EXTENSION_ENABLE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT; + break; + case EVENT_EXTENSION_DISABLE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT; + break; + case EVENT_CHROME_UPDATE: + string_id = IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT; + break; + case EVENT_RENDERER_FREEZE: + string_id = IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT; + break; + case EVENT_RENDERER_CRASH: + string_id = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT; + break; + case EVENT_KILLED_BY_OS_CRASH: + string_id = IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT; + break; + case EVENT_UNCLEAN_EXIT: + string_id = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +string16 GetLocalizedStringForEventTypeDescription(const EventType type) { + int string_id1 = 0; + int string_id2 = 0; + + switch (type) { + case EVENT_EXTENSION_INSTALL: + string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_DESCRIPTION; + break; + case EVENT_EXTENSION_UNINSTALL: + string_id1 = + IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_DESCRIPTION; + break; + case EVENT_EXTENSION_UPDATE: + string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_DESCRIPTION; + break; + case EVENT_EXTENSION_ENABLE: + string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_DESCRIPTION; + break; + case EVENT_EXTENSION_DISABLE: + string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_DESCRIPTION; + break; + case EVENT_CHROME_UPDATE: + string_id1 = IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_DESCRIPTION; + string_id2 = IDS_SHORT_PRODUCT_NAME; + break; + case EVENT_RENDERER_FREEZE: + string_id1 = IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT_DESCRIPTION; + break; + case EVENT_RENDERER_CRASH: + string_id1 = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_DESCRIPTION; + string_id2 = IDS_SAD_TAB_TITLE; + break; + case EVENT_KILLED_BY_OS_CRASH: + string_id1 = IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT_DESCRIPTION; + string_id2 = IDS_KILLED_TAB_TITLE; + break; + case EVENT_UNCLEAN_EXIT: + string_id1 = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_DESCRIPTION; + string_id2 = IDS_SHORT_PRODUCT_NAME; + break; + default: + NOTREACHED(); + } + + return string_id2 ? + l10n_util::GetStringFUTF16( + string_id1, l10n_util::GetStringUTF16(string_id2)) : + l10n_util::GetStringUTF16(string_id1); +} + +string16 GetLocalizedStringForEventTypeMouseover(const EventType type) { + if (type == EVENT_CHROME_UPDATE) { + return l10n_util::GetStringFUTF16( + IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_MOUSEOVER, + l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); + } + + int string_id = 0; + switch (type) { + case EVENT_EXTENSION_INSTALL: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_MOUSEOVER; + break; + case EVENT_EXTENSION_UNINSTALL: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_MOUSEOVER; + break; + case EVENT_EXTENSION_UPDATE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_MOUSEOVER; + break; + case EVENT_EXTENSION_ENABLE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_MOUSEOVER; + break; + case EVENT_EXTENSION_DISABLE: + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_MOUSEOVER; + break; + case EVENT_RENDERER_FREEZE: + string_id = IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT_MOUSEOVER; + break; + case EVENT_RENDERER_CRASH: + string_id = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_MOUSEOVER; + break; + case EVENT_KILLED_BY_OS_CRASH: + string_id = IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT_MOUSEOVER; + break; + case EVENT_UNCLEAN_EXIT: + string_id = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_MOUSEOVER; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +string16 GetLocalizedStringFromEventProperty(const std::string& property) { + int string_id = 0; + + if (property == "extensionId") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ID_MOUSEOVER; + else if (property == "extensionName") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_NAME_MOUSEOVER; + else if (property == "extensionUrl") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_URL_MOUSEOVER; + else if (property == "extensionLocation") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_LOCATION_MOUSEOVER; + else if (property == "extensionVersion") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_VERSION_MOUSEOVER; + else if (property == "extensionDescription") + string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DESCRIPTION_MOUSEOVER; + else if (property == "previousVersion") + string_id = IDS_PERFORMANCE_MONITOR_PREVIOUS_VERSION_MOUSEOVER; + else if (property == "currentVersion") + string_id = IDS_PERFORMANCE_MONITOR_CURRENT_VERSION_MOUSEOVER; + else if (property == "url") + string_id = IDS_PERFORMANCE_MONITOR_URL_MOUSEOVER; + else if (property == "profileName") + string_id = IDS_PERFORMANCE_MONITOR_PROFILE_NAME_MOUSEOVER; + else + NOTREACHED(); + + return l10n_util::GetStringUTF16(string_id); +} + +// Metric-Related +string16 GetLocalizedStringFromMetricCategory( + const MetricCategory category) { + int string_id = 0; + + switch (category) { + case METRIC_CATEGORY_CPU: + string_id = IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY; + break; + case METRIC_CATEGORY_MEMORY: + string_id = IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY; + break; + case METRIC_CATEGORY_TIMING: + string_id = IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY; + break; + case METRIC_CATEGORY_NETWORK: + string_id = IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +string16 GetLocalizedStringForMetricCategoryDescription( + const MetricCategory category) { + int string_id = 0; + + switch (category) { + case METRIC_CATEGORY_CPU: + string_id = IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY_DESCRIPTION; + break; + case METRIC_CATEGORY_MEMORY: + string_id = IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY_DESCRIPTION; + break; + case METRIC_CATEGORY_TIMING: + string_id = IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY_DESCRIPTION; + break; + case METRIC_CATEGORY_NETWORK: + string_id = IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY_DESCRIPTION; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringFUTF16( + string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); +} + +string16 GetLocalizedStringFromMetricType(const MetricType type) { + int string_id = 0; + + switch (type) { + case METRIC_CPU_USAGE: + string_id = IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC; + break; + case METRIC_PRIVATE_MEMORY_USAGE: + string_id = IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC; + break; + case METRIC_SHARED_MEMORY_USAGE: + string_id = IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC; + break; + case METRIC_STARTUP_TIME: + string_id = IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC; + break; + case METRIC_TEST_STARTUP_TIME: + string_id = IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC; + break; + case METRIC_SESSION_RESTORE_TIME: + string_id = IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC; + break; + case METRIC_PAGE_LOAD_TIME: + string_id = IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC; + break; + case METRIC_NETWORK_BYTES_READ: + string_id = IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +string16 GetLocalizedStringForMetricTypeDescription(const MetricType type) { + int string_id = 0; + + switch (type) { + case METRIC_CPU_USAGE: + string_id = IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC_DESCRIPTION; + break; + case METRIC_PRIVATE_MEMORY_USAGE: + string_id = + IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC_DESCRIPTION; + break; + case METRIC_SHARED_MEMORY_USAGE: + string_id = + IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC_DESCRIPTION; + break; + case METRIC_STARTUP_TIME: + string_id = IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC_DESCRIPTION; + break; + case METRIC_TEST_STARTUP_TIME: + string_id = IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC_DESCRIPTION; + break; + default: + break; + } + + if (string_id) { + return l10n_util::GetStringFUTF16( + string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); + } + + switch (type) { + case METRIC_SESSION_RESTORE_TIME: + string_id = + IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC_DESCRIPTION; + break; + case METRIC_PAGE_LOAD_TIME: + string_id = IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC_DESCRIPTION; + break; + case METRIC_NETWORK_BYTES_READ: + string_id = IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC_DESCRIPTION; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +// Miscellaneous +string16 GetLocalizedStringFromUnit(const Unit unit) { + int string_id = 0; + + switch (unit) { + case UNIT_BYTES: + string_id = IDS_PERFORMANCE_MONITOR_BYTES_UNIT; + break; + case UNIT_KILOBYTES: + string_id = IDS_PERFORMANCE_MONITOR_KILOBYTES_UNIT; + break; + case UNIT_MEGABYTES: + string_id = IDS_PERFORMANCE_MONITOR_MEGABYTES_UNIT; + break; + case UNIT_GIGABYTES: + string_id = IDS_PERFORMANCE_MONITOR_GIGABYTES_UNIT; + break; + case UNIT_TERABYTES: + string_id = IDS_PERFORMANCE_MONITOR_TERABYTES_UNIT; + break; + case UNIT_MICROSECONDS: + string_id = IDS_PERFORMANCE_MONITOR_MICROSECONDS_UNIT; + break; + case UNIT_MILLISECONDS: + string_id = IDS_PERFORMANCE_MONITOR_MILLISECONDS_UNIT; + break; + case UNIT_SECONDS: + string_id = IDS_PERFORMANCE_MONITOR_SECONDS_UNIT; + break; + case UNIT_MINUTES: + string_id = IDS_PERFORMANCE_MONITOR_MINUTES_UNIT; + break; + case UNIT_HOURS: + string_id = IDS_PERFORMANCE_MONITOR_HOURS_UNIT; + break; + case UNIT_DAYS: + string_id = IDS_PERFORMANCE_MONITOR_DAYS_UNIT; + break; + case UNIT_WEEKS: + string_id = IDS_PERFORMANCE_MONITOR_WEEKS_UNIT; + break; + case UNIT_MONTHS: + string_id = IDS_PERFORMANCE_MONITOR_MONTHS_UNIT; + break; + case UNIT_YEARS: + string_id = IDS_PERFORMANCE_MONITOR_YEARS_UNIT; + break; + case UNIT_PERCENT: + string_id = IDS_PERFORMANCE_MONITOR_PERCENT_UNIT; + break; + default: + NOTREACHED(); + } + + return l10n_util::GetStringUTF16(string_id); +} + +} // namespace performance_monitor diff --git a/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h b/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h new file mode 100644 index 0000000..a7ef57f --- /dev/null +++ b/chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h @@ -0,0 +1,37 @@ +// 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_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_L10N_H_ +#define CHROME_BROWSER_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_L10N_H_ + +#include + +#include "chrome/browser/performance_monitor/event.h" +#include "chrome/browser/performance_monitor/metric.h" +#include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h" + +namespace performance_monitor { + +// Event-Related +string16 GetLocalizedStringFromEventCategory(const EventCategory category); +string16 GetLocalizedStringForEventCategoryDescription( + const EventCategory category); +string16 GetLocalizedStringFromEventType(const EventType type); +string16 GetLocalizedStringForEventTypeDescription(const EventType type); +string16 GetLocalizedStringForEventTypeMouseover(const EventType type); +string16 GetLocalizedStringFromEventProperty(const std::string& key); + +// Metric-Related +string16 GetLocalizedStringFromMetricCategory(const MetricCategory category); +string16 GetLocalizedStringForMetricCategoryDescription( + const MetricCategory category); +string16 GetLocalizedStringFromMetricType(const MetricType type); +string16 GetLocalizedStringForMetricTypeDescription(const MetricType type); + +// Miscellaneous +string16 GetLocalizedStringFromUnit(const Unit unit); + +} // namespace performance_monitor + +#endif // CHROME_BROWSER_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_L10N_H_ diff --git a/chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h b/chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h new file mode 100644 index 0000000..1978021 --- /dev/null +++ b/chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h @@ -0,0 +1,46 @@ +// 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_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_UI_CONSTANTS_H_ +#define CHROME_BROWSER_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_UI_CONSTANTS_H_ + +namespace performance_monitor { + +enum EventCategory { + EVENT_CATEGORY_EXTENSIONS, + EVENT_CATEGORY_CHROME, + EVENT_CATEGORY_EXCEPTIONS, + EVENT_CATEGORY_NUMBER_OF_CATEGORIES +}; + +enum MetricCategory { + METRIC_CATEGORY_CPU, + METRIC_CATEGORY_MEMORY, + METRIC_CATEGORY_TIMING, + METRIC_CATEGORY_NETWORK, + METRIC_CATEGORY_NUMBER_OF_CATEGORIES +}; + +enum Unit { + UNIT_BYTES, + UNIT_KILOBYTES, + UNIT_MEGABYTES, + UNIT_GIGABYTES, + UNIT_TERABYTES, + UNIT_MICROSECONDS, + UNIT_MILLISECONDS, + UNIT_SECONDS, + UNIT_MINUTES, + UNIT_HOURS, + UNIT_DAYS, + UNIT_WEEKS, + UNIT_MONTHS, + UNIT_YEARS, + UNIT_PERCENT, + UNIT_UNDEFINED +}; + +} // namespace performance_monitor + +#endif // CHROME_BROWSER_UI_WEBUI_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_UI_CONSTANTS_H_ diff --git a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc index 05b8432..841db60 100644 --- a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc +++ b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.cc @@ -11,16 +11,160 @@ #include "chrome/browser/performance_monitor/database.h" #include "chrome/browser/performance_monitor/event.h" #include "chrome/browser/performance_monitor/metric.h" -#include "chrome/browser/performance_monitor/metric_details.h" #include "chrome/browser/performance_monitor/performance_monitor.h" #include "chrome/browser/performance_monitor/performance_monitor_util.h" +#include "chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h" +#include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h" #include "chrome/common/extensions/value_builder.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_ui.h" +using content::BrowserThread; + namespace performance_monitor { namespace { +std::set GetMetricSetForCategory(MetricCategory category) { + std::set metric_set; + switch (category) { + case METRIC_CATEGORY_CPU: + metric_set.insert(METRIC_CPU_USAGE); + break; + case METRIC_CATEGORY_MEMORY: + metric_set.insert(METRIC_SHARED_MEMORY_USAGE); + metric_set.insert(METRIC_PRIVATE_MEMORY_USAGE); + break; + case METRIC_CATEGORY_TIMING: + metric_set.insert(METRIC_STARTUP_TIME); + metric_set.insert(METRIC_TEST_STARTUP_TIME); + metric_set.insert(METRIC_SESSION_RESTORE_TIME); + metric_set.insert(METRIC_PAGE_LOAD_TIME); + break; + case METRIC_CATEGORY_NETWORK: + metric_set.insert(METRIC_NETWORK_BYTES_READ); + break; + default: + NOTREACHED(); + } + return metric_set; +} + +std::set GetEventSetForCategory(EventCategory category) { + std::set event_set; + switch (category) { + case EVENT_CATEGORY_EXTENSIONS: + event_set.insert(EVENT_EXTENSION_INSTALL); + event_set.insert(EVENT_EXTENSION_UNINSTALL); + event_set.insert(EVENT_EXTENSION_UPDATE); + event_set.insert(EVENT_EXTENSION_ENABLE); + event_set.insert(EVENT_EXTENSION_DISABLE); + break; + case EVENT_CATEGORY_CHROME: + event_set.insert(EVENT_CHROME_UPDATE); + break; + case EVENT_CATEGORY_EXCEPTIONS: + event_set.insert(EVENT_RENDERER_FREEZE); + event_set.insert(EVENT_RENDERER_CRASH); + event_set.insert(EVENT_KILLED_BY_OS_CRASH); + event_set.insert(EVENT_UNCLEAN_EXIT); + break; + default: + NOTREACHED(); + } + return event_set; +} + +Unit GetUnitForMetricCategory(MetricCategory category) { + switch (category) { + case METRIC_CATEGORY_CPU: + return UNIT_PERCENT; + case METRIC_CATEGORY_MEMORY: + return UNIT_BYTES; + case METRIC_CATEGORY_TIMING: + return UNIT_MICROSECONDS; + case METRIC_CATEGORY_NETWORK: + return UNIT_BYTES; + default: + NOTREACHED(); + } + return UNIT_UNDEFINED; +} + +// Returns a list of metric details, with one entry per metric. Metric details +// are dictionaries which contain the id representing the metric and localized +// strings for the metric name and metric description. +scoped_ptr GetMetricDetailsForCategory(MetricCategory category) { + scoped_ptr value(new ListValue()); + std::set metric_set = GetMetricSetForCategory(category); + for (std::set::const_iterator iter = metric_set.begin(); + iter != metric_set.end(); ++iter) { + DictionaryValue* metric_details = new DictionaryValue(); + metric_details->SetInteger("metricId", *iter); + metric_details->SetString( + "name", GetLocalizedStringFromMetricType(*iter)); + metric_details->SetString( + "description", GetLocalizedStringForMetricTypeDescription(*iter)); + value->Append(metric_details); + } + return value.Pass(); +} + +// Returns a dictionary for the metric category. Metric categories contain +// an id representing the category; localized strings for the category name, +// the default unit in which the category is measured, and the category's +// description; and the metric details for each metric type in the category. +scoped_ptr GetMetricCategory(MetricCategory category) { + scoped_ptr value(new DictionaryValue()); + value->SetInteger("metricCategoryId", category); + value->SetString( + "name", GetLocalizedStringFromMetricCategory(category)); + value->SetString( + "unit", + GetLocalizedStringFromUnit(GetUnitForMetricCategory(category))); + value->SetString( + "description", + GetLocalizedStringForMetricCategoryDescription(category)); + value->Set("details", GetMetricDetailsForCategory(category).release()); + return value.Pass(); +} + +// Returns a list of event types, with one entry per event. Event types +// are dictionaries which contain the id representing the event and localized +// strings for the event name, event description, and a title suitable for a +// mouseover popup. +scoped_ptr GetEventTypesForCategory(EventCategory category) { + scoped_ptr value(new ListValue()); + std::set event_set = GetEventSetForCategory(category); + for (std::set::const_iterator iter = event_set.begin(); + iter != event_set.end(); ++iter) { + DictionaryValue* event_details = new DictionaryValue(); + event_details->SetInteger("eventId", *iter); + event_details->SetString( + "name", GetLocalizedStringFromEventType(*iter)); + event_details->SetString( + "description", GetLocalizedStringForEventTypeDescription(*iter)); + event_details->SetString( + "popupTitle", GetLocalizedStringForEventTypeMouseover(*iter)); + value->Append(event_details); + } + return value.Pass(); +} + +// Returns a dictionary for the event category. Event categories contain an +// id representing the category, localized strings for the event name and +// event description, and event details for each event type in the category. +scoped_ptr GetEventCategory(EventCategory category) { + scoped_ptr value(new DictionaryValue()); + value->SetInteger("eventCategoryId", category); + value->SetString( + "name", GetLocalizedStringFromEventCategory(category)); + value->SetString( + "description", + GetLocalizedStringForEventCategoryDescription(category)); + value->Set("details", GetEventTypesForCategory(category).release()); + return value.Pass(); +} + // Queries the performance monitor database for active intervals between // |start| and |end| times and appends the results to |results|. void DoGetActiveIntervals(ListValue* results, @@ -37,27 +181,72 @@ void DoGetActiveIntervals(ListValue* results, } } -// Queries the performance monitor database for events of type |event_type| -// between |start| and |end| times and appends the results to |results|. -// TODO(mtytel): Add an internationalized longDescription field to each event. +// Queries the PerformanceMonitor database for events of type |event_type| +// between |start| and |end| times, creates a new event with localized keys +// for display, and appends the results to |results|. void DoGetEvents(ListValue* results, EventType event_type, const base::Time& start, const base::Time& end) { Database* db = PerformanceMonitor::GetInstance()->database(); Database::EventVector events = db->GetEvents(event_type, start, end); - for (Database::EventVector::iterator it = events.begin(); - it != events.end(); ++it) { - results->Append((*it)->data()->DeepCopy()); + for (Database::EventVector::iterator event = events.begin(); + event != events.end(); ++event) { + DictionaryValue* localized_event = new DictionaryValue(); + + for (DictionaryValue::key_iterator key = (*event)->data()->begin_keys(); + key != (*event)->data()->end_keys(); ++key) { + std::string localized_key; + + Value* value = NULL; + + // The property 'eventType' is used computationally on the UI side (and + // not displayed), so it does not need any localization. + if (*key == "eventType") { + Value* old_value = NULL; + (*event)->data()->Get(*key, &old_value); + value = old_value->DeepCopy(); + } else if (*key == "time") { + // The property 'time' is also used computationally, but must be + // converted to JS-style time. + double time = 0.0; + if (!(*event)->data()->GetDouble(std::string("time"), &time)) { + LOG(ERROR) << "Failed to get 'time' field from event."; + continue; + } + value = Value::CreateDoubleValue( + base::Time::FromInternalValue(static_cast(time)).ToJsTime()); + } else { + // All other values are user-facing, so we create a new value for + // localized display. + DictionaryValue* localized_value = new DictionaryValue(); + localized_value->SetString("displayString", + GetLocalizedStringFromEventProperty(*key)); + Value* old_value = NULL; + (*event)->data()->Get(*key, &old_value); + localized_value->SetWithoutPathExpansion("value", + old_value->DeepCopy()); + value = static_cast(localized_value); + } + + localized_event->SetWithoutPathExpansion(*key, value); + } + results->Append(localized_event); } } // Queries the performance monitor database for metrics of type |metric_type| // between |start| and |end| times and appends the results to |results|. -void DoGetMetric(ListValue* results, +void DoGetMetric(DictionaryValue* results, MetricType metric_type, const base::Time& start, const base::Time& end, const base::TimeDelta& resolution) { Database* db = PerformanceMonitor::GetInstance()->database(); + // results->SetDouble("maxValue", db->GetMaxValueForMetric(metric_type)); + results->SetDouble("maxValue", 10.0); + results->SetInteger("metricId", static_cast(metric_type)); + + ListValue* metric_list = new ListValue(); + results->Set("metrics", metric_list); Database::MetricVectorMap metric_vector_map = db->GetStatsForMetricByActivity(metric_type, start, end); @@ -73,16 +262,16 @@ void DoGetMetric(ListValue* results, DictionaryValue* metric_value = new DictionaryValue(); metric_value->SetDouble("time", it->time.ToJsTime()); metric_value->SetDouble("value", it->value); - results->Append(metric_value); + metric_list->Append(metric_value); } } } // namespace WebUIHandler::WebUIHandler() { - // TODO(mtytel): Remove this check when the PerformanceMonitor starts up - // before the WebUI. - if (!PerformanceMonitor::GetInstance()->database()) + // If we are not running the --run-performance-monitor flag, we will not have + // started PerformanceMonitor. + if (!PerformanceMonitor::initialized()) PerformanceMonitor::GetInstance()->Start(); } @@ -92,33 +281,33 @@ void WebUIHandler::RegisterMessages() { web_ui()->RegisterMessageCallback( "getActiveIntervals", base::Bind(&WebUIHandler::HandleGetActiveIntervals, - base::Unretained(this))); + AsWeakPtr())); web_ui()->RegisterMessageCallback( - "getAllEventTypes", - base::Bind(&WebUIHandler::HandleGetAllEventTypes, - base::Unretained(this))); + "getEventTypes", + base::Bind(&WebUIHandler::HandleGetEventTypes, + AsWeakPtr())); web_ui()->RegisterMessageCallback( "getEvents", base::Bind(&WebUIHandler::HandleGetEvents, - base::Unretained(this))); + AsWeakPtr())); web_ui()->RegisterMessageCallback( - "getAllMetricTypes", - base::Bind(&WebUIHandler::HandleGetAllMetricTypes, - base::Unretained(this))); + "getMetricTypes", + base::Bind(&WebUIHandler::HandleGetMetricTypes, + AsWeakPtr())); web_ui()->RegisterMessageCallback( "getMetric", base::Bind(&WebUIHandler::HandleGetMetric, - base::Unretained(this))); + AsWeakPtr())); } void WebUIHandler::ReturnResults(const std::string& function, const Value* results) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); web_ui()->CallJavascriptFunction(function, *results); } void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK_EQ(2u, args->GetSize()); double double_time = 0.0; CHECK(args->GetDouble(0, &double_time)); @@ -135,23 +324,18 @@ void WebUIHandler::HandleGetActiveIntervals(const ListValue* args) { base::Owned(results))); } -void WebUIHandler::HandleGetAllEventTypes(const ListValue* args) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); +void WebUIHandler::HandleGetEventTypes(const ListValue* args) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK_EQ(0u, args->GetSize()); ListValue results; - for (int i = 0; i < EVENT_NUMBER_OF_EVENTS; ++i) { - EventType event_type = static_cast(i); - DictionaryValue* event_type_info = new DictionaryValue(); - event_type_info->SetInteger("eventType", event_type); - event_type_info->SetString("shortDescription", - EventTypeToString(event_type)); - results.Append(event_type_info); - } - ReturnResults("PerformanceMonitor.getAllEventTypesCallback", &results); + for (int i = 0; i < EVENT_CATEGORY_NUMBER_OF_CATEGORIES; ++i) + results.Append(GetEventCategory(static_cast(i)).release()); + + ReturnResults("PerformanceMonitor.getEventTypesCallback", &results); } void WebUIHandler::HandleGetEvents(const ListValue* args) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK_EQ(3u, args->GetSize()); double event = 0; CHECK(args->GetDouble(0, &event)); @@ -164,39 +348,30 @@ void WebUIHandler::HandleGetEvents(const ListValue* args) { base::Time end = base::Time::FromJsTime(double_time); DictionaryValue* results = new DictionaryValue(); - ListValue* points_results = new ListValue(); - results->Set("points", points_results); - results->SetInteger("eventType", event_type); + results->SetInteger("eventId", static_cast(event_type)); + ListValue* events = new ListValue(); + results->Set("events", events); + util::PostTaskToDatabaseThreadAndReply( FROM_HERE, - base::Bind(&DoGetEvents, points_results, event_type, start, end), + base::Bind(&DoGetEvents, events, event_type, start, end), base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), "PerformanceMonitor.getEventsCallback", base::Owned(results))); } -void WebUIHandler::HandleGetAllMetricTypes(const ListValue* args) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); +void WebUIHandler::HandleGetMetricTypes(const ListValue* args) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK_EQ(0u, args->GetSize()); ListValue results; - for (int i = 0; i < METRIC_NUMBER_OF_METRICS; ++i) { - MetricType metric_type = static_cast(i); - const MetricDetails* metric_details = GetMetricDetails(metric_type); - - DictionaryValue* metric_type_info = new DictionaryValue(); - metric_type_info->SetInteger("metricType", metric_type); - metric_type_info->SetString("shortDescription", - metric_details->description); - metric_type_info->SetDouble("tickSize", metric_details->tick_size); - metric_type_info->SetString("units", metric_details->units); - results.Append(metric_type_info); - } + for (int i = 0; i < METRIC_CATEGORY_NUMBER_OF_CATEGORIES; ++i) + results.Append(GetMetricCategory(static_cast(i)).release()); - ReturnResults("PerformanceMonitor.getAllMetricTypesCallback", &results); + ReturnResults("PerformanceMonitor.getMetricTypesCallback", &results); } void WebUIHandler::HandleGetMetric(const ListValue* args) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); CHECK_EQ(4u, args->GetSize()); double metric = 0; CHECK(args->GetDouble(0, &metric)); @@ -214,12 +389,9 @@ void WebUIHandler::HandleGetMetric(const ListValue* args) { base::TimeDelta::FromMilliseconds(resolution_in_milliseconds); DictionaryValue* results = new DictionaryValue(); - results->SetInteger("metricType", metric_type); - ListValue* points_results = new ListValue(); - results->Set("points", points_results); util::PostTaskToDatabaseThreadAndReply( FROM_HERE, - base::Bind(&DoGetMetric, points_results, metric_type, + base::Bind(&DoGetMetric, results, metric_type, start, end, resolution), base::Bind(&WebUIHandler::ReturnResults, AsWeakPtr(), "PerformanceMonitor.getMetricCallback", diff --git a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.h b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.h index 3576c8b..056a40d 100644 --- a/chrome/browser/ui/webui/performance_monitor/web_ui_handler.h +++ b/chrome/browser/ui/webui/performance_monitor/web_ui_handler.h @@ -38,17 +38,17 @@ class WebUIHandler : public content::WebUIMessageHandler, // |args| contains a start and an end time. void HandleGetActiveIntervals(const base::ListValue* args); - // Callback for the "getAllEventTypes" message. + // Callback for the "getEventTypes" message. // |args| is unused. - void HandleGetAllEventTypes(const base::ListValue* args); + void HandleGetEventTypes(const base::ListValue* args); // Callback for the "getEvents" message. // |args| contains an EventType id to collect and a start and end time. void HandleGetEvents(const base::ListValue* args); - // Callback for the "getAllMetricTypes" message. + // Callback for the "getMetricTypes" message. // |args| is unused. - void HandleGetAllMetricTypes(const base::ListValue* args); + void HandleGetMetricTypes(const base::ListValue* args); // Callback for the "getMetric" message. // |args| contains a MetricType id to collect, a start and end time, and a diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index a33ce72..049882a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1170,8 +1170,6 @@ 'browser/performance_monitor/event.h', 'browser/performance_monitor/metric.cc', 'browser/performance_monitor/metric.h', - 'browser/performance_monitor/metric_details.cc', - 'browser/performance_monitor/metric_details.h', 'browser/performance_monitor/performance_monitor.cc', 'browser/performance_monitor/performance_monitor.h', 'browser/performance_monitor/performance_monitor_util.cc', @@ -3754,6 +3752,9 @@ 'browser/ui/webui/options/startup_pages_handler.h', 'browser/ui/webui/options/web_intents_settings_handler.cc', 'browser/ui/webui/options/web_intents_settings_handler.h', + 'browser/ui/webui/performance_monitor/performance_monitor_l10n.cc', + 'browser/ui/webui/performance_monitor/performance_monitor_l10n.h', + 'browser/ui/webui/performance_monitor/performance_monitor_ui_constants.h', 'browser/ui/webui/performance_monitor/web_ui.cc', 'browser/ui/webui/performance_monitor/web_ui.h', 'browser/ui/webui/performance_monitor/web_ui_handler.cc', -- cgit v1.1