diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 21:09:41 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 21:09:41 +0000 |
commit | 16c4c44cfa3569daca521e4886855ff0f6cc7569 (patch) | |
tree | 892c7bf222166153d6ab47c3168c6b1736fdd56e | |
parent | 3ed181d0d0feb9797ac6f9c2854f1ff1a9bf91a8 (diff) | |
download | chromium_src-16c4c44cfa3569daca521e4886855ff0f6cc7569.zip chromium_src-16c4c44cfa3569daca521e4886855ff0f6cc7569.tar.gz chromium_src-16c4c44cfa3569daca521e4886855ff0f6cc7569.tar.bz2 |
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
14 files changed, 1007 insertions, 258 deletions
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 (<ph name="PUBLIC_EXPONENT_NUM_BITS">$3<ex>24</ex></ph> bits): Instant: <ph name="INSTANT_PREVIEW_NAME">$1<ex>http://www.google.com/</ex></ph> </message> + <!-- Performance Monitor page --> + <!-- Event-Related --> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY" desc="Text displayed for the Extensions events category title."> + Extensions + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the Extension event category."> + Events that are related to any extensions that are (or have been) installed in <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT" desc="Text displayed for the Extension Install event title."> + Installs + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Extension Install event checkbox."> + Occurrences when an extension was installed + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Extension Install event."> + Extension Installed + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT" desc="Text displayed for the Extension Uninstall event title."> + Uninstalls + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Extension Uninstall event checkbox."> + Occurrences when an extension was uninstalled + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Extension Uninstall event."> + Extension Uninstalled + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT" desc="Text displayed for the Extension Update event title."> + Updates + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Extension Update event checkbox."> + Occurrences when an extension was updated + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Extension Update event."> + Extension Updated + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT" desc="Text displayed for the Extension Enable event title."> + Enables + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Extension Enable event checkbox."> + Occurrences when an extension was enabled + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Extension Enable event."> + Extension Enabled + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT" desc="Text displayed for the Extension Disable event title."> + Disables + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Extension Disable event checkbox."> + Occurrences when an extension was disabled + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Extension Disable event."> + Extension Disabled + </message> + <message name="IDS_PERFORMANCE_MONITOR_CHROME_EVENT_CATEGORY" desc="Text displayed for the Chrome/Chromium events category title"> + <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_CHROME_EVENT_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the Chrome event category."> + Events that are related to the <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> system. + </message> + <message name="IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT" desc="Text displayed for the Chrome Update event title."> + Updates + </message> + <message name="IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Chrome Update event checkbox."> + Occurrences when the version of <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> changed + </message> + <message name="IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_MOUSEOVER" desc="Text displayed on mouseover of a Chrome Update event."> + <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> Updated + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY" desc="Text displayed for the Exceptions events' category title"> + Exceptions + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the Exceptions event category."> + Events relating to <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> crashes and failures + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT" desc="Text displayed for the Renderer Freeze event title."> + Renderer Freezes + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Renderer Freeze event checkbox."> + Occurrences when a tab became unresponsive + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_FREEZE_EVENT_MOUSEOVER" desc="Text displayed on mouseover of a Renderer Freeze event."> + Renderer Froze + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT" desc="Text displayed for the Renderer Crash event title."> + Renderer Crashes + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Renderer Crash event checkbox."> + Occurrences when a tab crashed ("<ph name="IDS_SAD_TAB_TITLE">$1<ex>Aw, Snap!</ex></ph>") + </message> + <message name="IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_MOUSEOVER" desc="Text dispalyed on mouseover of a Renderer Crash event."> + Renderer Crashed + </message> + <message name="IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT" desc="Text displayed for the Killed By OS Crash event title."> + Process Kills + </message> + <message name="IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Killed By OS Crash event checkbox."> + Occurrences when the OS killed a tab's process ("<ph name="IDS_KILLED_TAB_TITLE">$1<ex>He's dead, Jim!</ex></ph>") + </message> + <message name="IDS_PERFORMANCE_MONITOR_KILLED_BY_OS_CRASH_EVENT_MOUSEOVER" desc="Text displayed on mouseover of a Killed By OS Crash event."> + Process Killed + </message> + <message name="IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT" desc="Text displayed for the Unclean Exit event title."> + Unclean Exits + </message> + <message name="IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_DESCRIPTION" desc="Text displayed on mouseover of the Unclean Exit event checkbox."> + Occurrences when <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> did not shut down correctly + </message> + <message name="IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_MOUSEOVER" desc="Text displayed on mouseover of an Unclean Exit event."> + Unclean Exit + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_ID_MOUSEOVER" desc="Text displayed for the Extension ID field of an event mouseover."> + Extension ID + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_NAME_MOUSEOVER" desc="Text displayed for the Extension Name field of an event mouseover."> + Extension Name + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_URL_MOUSEOVER" desc="Text displayed for the Extension URL field of an event mouseover."> + Extension URL + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_LOCATION_MOUSEOVER" desc="Text displayed for the Extension Location field of an event mouseover."> + Extension Location + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_VERSION_MOUSEOVER" desc="Text displayed for the Extension Version field of an event mouseover."> + Extension Version + </message> + <message name="IDS_PERFORMANCE_MONITOR_EXTENSION_DESCRIPTION_MOUSEOVER" desc="Text displayed for the Extension Description field of an event mouseover."> + Extension Description + </message> + <message name="IDS_PERFORMANCE_MONITOR_PREVIOUS_VERSION_MOUSEOVER" desc="Text displayed for the Previous Version field of an event mouseover."> + Previous Version + </message> + <message name="IDS_PERFORMANCE_MONITOR_CURRENT_VERSION_MOUSEOVER" desc="Text displayed for the Current Version field of an event mouseover."> + Current Version + </message> + <message name="IDS_PERFORMANCE_MONITOR_URL_MOUSEOVER" desc="Text displayed for the URL field of an event mouseover."> + URL + </message> + <message name="IDS_PERFORMANCE_MONITOR_PROFILE_NAME_MOUSEOVER" desc="Text displayed for the Profile Name field of an event mouseover."> + Profile Name + </message> + <!--- Metric-Related --> + <message name="IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY" desc="Text displayed for the CPU metrics' category title"> + CPU + </message> + <message name="IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the CPU metric category."> + Metrics relating to the effect of <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> on the system's CPU + </message> + <message name="IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC" desc="Text displayed for the CPU Usage metric title."> + CPU Usage + </message> + <message name="IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC_DESCRIPTION" desc="Text displayed for mouseover of the CPU Usage metric."> + The combined CPU usage of all processes related to <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY" desc="Text displayed for the Memory metrics' category title"> + Memory + </message> + <message name="IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY_DESCRIPTION" desc = "Text displayed on mouseover of the Memory metric category."> + Metrics relating to the effect of <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> on the system's memory + </message> + <message name="IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC" desc="Text displayed for the Private Memory Usage metric title."> + Private Memory Usage + </message> + <message name="IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Private Memory Usage metric."> + The combined private memory usage of all processes related to <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC" desc="Text displayed for the Shared Memory Usage metric title."> + Shared Memory Usage + </message> + <message name="IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Shared Memory Usage metric."> + The combined shared memory usage of all processes related to <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY" desc="Text displayed for the Timing metrics' category title"> + Timing + </message> + <message name="IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the Timing metric category."> + Metrics relating to the speed with which <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> performs requested actions + </message> + <message name="IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC" desc="Text displayed for the Startup Time metric title."> + Startups + </message> + <message name="IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Startup Time metric."> + The time it takes to fully start <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC" desc="Text displayed for the Test Startup Time metric title."> + Test Startups + </message> + <message name="IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Test Startup Time metric."> + The time it takes to fully start <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> in a testing environment + </message> + <message name="IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC" desc="Text displayed for the Session Restore Time metric title."> + Session Restores + </message> + <message name="IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC_DESCRIPTION" desc="Text dispalyed on mouseover of the Session Restore Time metric."> + The time it takes to restore a previous browsing session + </message> + <message name="IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC" desc="Text displayed for the Page Load Time metric title."> + Page Loads + </message> + <message name="IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Page Load Time metric."> + The time it takes to load a web page + </message> + <message name="IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY" desc="Text displayed for the Network metrics' category title."> + Network + </message> + <message name="IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY_DESCRIPTION" desc="Text displayed on mouseover of the Network metric category."> + Metrics related to the network usage of <ph name="SHORT_PRODUCT_NAME">$1<ex>Chrome</ex></ph> + </message> + <message name="IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC" desc="Text displayed for the Network Bytes Read metric title."> + Bytes Read + </message> + <message name="IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC_DESCRIPTION" desc="Text displayed on mouseover of the Network Bytes Read metric."> + The number of bytes read across the network + </message> + <!-- Units --> + <message name="IDS_PERFORMANCE_MONITOR_BYTES_UNIT" desc="Text displayed for when a unit is in bytes."> + Bytes + </message> + <message name="IDS_PERFORMANCE_MONITOR_KILOBYTES_UNIT" desc="Text displayed for when a unit is in kilobytes."> + Kilobytes + </message> + <message name="IDS_PERFORMANCE_MONITOR_MEGABYTES_UNIT" desc="Text displayed for when a unit is in megabytes."> + Megabytes + </message> + <message name="IDS_PERFORMANCE_MONITOR_GIGABYTES_UNIT" desc="Text displayed for when a unit is in gigabytes."> + Gigabytes + </message> + <message name="IDS_PERFORMANCE_MONITOR_TERABYTES_UNIT" desc="Text displayed for when a unit is in terabytes."> + Terabytes + </message> + <message name="IDS_PERFORMANCE_MONITOR_MICROSECONDS_UNIT" desc="Text displayed for when a unit is in microseconds."> + Microseconds + </message> + <message name="IDS_PERFORMANCE_MONITOR_MILLISECONDS_UNIT" desc="Text displayed for when a unit is in milliseconds."> + Milliseconds + </message> + <message name="IDS_PERFORMANCE_MONITOR_SECONDS_UNIT" desc="Text displayed for when a unit is in seconds."> + Seconds + </message> + <message name="IDS_PERFORMANCE_MONITOR_MINUTES_UNIT" desc="Text displayed for when a unit is in minutes."> + Minutes + </message> + <message name="IDS_PERFORMANCE_MONITOR_HOURS_UNIT" desc="Text displayed for when a unit is in hours."> + Hours + </message> + <message name="IDS_PERFORMANCE_MONITOR_DAYS_UNIT" desc="Text displayed for when a unit is in days."> + Days + </message> + <message name="IDS_PERFORMANCE_MONITOR_WEEKS_UNIT" desc="Text displayed for when a unit is in weeks."> + Weeks + </message> + <message name="IDS_PERFORMANCE_MONITOR_MONTHS_UNIT" desc="Text displayed for when a unit is in months."> + Months + </message> + <message name="IDS_PERFORMANCE_MONITOR_YEARS_UNIT" desc="Text displayed for when a unit is in years."> + Years + </message> + <message name="IDS_PERFORMANCE_MONITOR_PERCENT_UNIT" desc="Text displayed for when a unit is in percent."> + Percent + </message> + <!-- Theme preview info bar --> <message name="IDS_THEME_INSTALL_INFOBAR_LABEL" desc="Text displayed on an infobar when a theme has been installed."> Installed theme "<ph name="THEME_NAME">$1<ex>Snowflake Theme</ex></ph>". 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 <string> - -#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 <string> + +#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<MetricType> GetMetricSetForCategory(MetricCategory category) { + std::set<MetricType> 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<EventType> GetEventSetForCategory(EventCategory category) { + std::set<EventType> 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<ListValue> GetMetricDetailsForCategory(MetricCategory category) { + scoped_ptr<ListValue> value(new ListValue()); + std::set<MetricType> metric_set = GetMetricSetForCategory(category); + for (std::set<MetricType>::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<DictionaryValue> GetMetricCategory(MetricCategory category) { + scoped_ptr<DictionaryValue> 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<ListValue> GetEventTypesForCategory(EventCategory category) { + scoped_ptr<ListValue> value(new ListValue()); + std::set<EventType> event_set = GetEventSetForCategory(category); + for (std::set<EventType>::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<DictionaryValue> GetEventCategory(EventCategory category) { + scoped_ptr<DictionaryValue> 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<int64>(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<Value*>(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<int>(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<EventType>(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<EventCategory>(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<int>(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<MetricType>(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<MetricCategory>(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', |