Home | History | Annotate | Download | only in performance_monitor
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/webui/performance_monitor/performance_monitor_l10n.h"
      6 
      7 #include "grit/chromium_strings.h"
      8 #include "grit/generated_resources.h"
      9 #include "ui/base/l10n/l10n_util.h"
     10 
     11 namespace performance_monitor {
     12 
     13 // Aggregation-Related
     14 base::string16 GetLocalizedStringFromAggregationMethod(
     15     const AggregationMethod method) {
     16   int string_id = 0;
     17   switch (method) {
     18     case AGGREGATION_METHOD_NONE:
     19       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_NONE_NAME;
     20       break;
     21     case AGGREGATION_METHOD_MEDIAN:
     22       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_MEDIAN_NAME;
     23       break;
     24     case AGGREGATION_METHOD_MEAN:
     25       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_MEAN_NAME;
     26       break;
     27     default:
     28       NOTREACHED();
     29   }
     30 
     31   return l10n_util::GetStringUTF16(string_id);
     32 }
     33 
     34 base::string16 GetLocalizedStringForAggregationMethodDescription(
     35     const AggregationMethod method) {
     36   int string_id = 0;
     37   switch (method) {
     38     case AGGREGATION_METHOD_NONE:
     39       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_NONE_DESCRIPTION;
     40       break;
     41     case AGGREGATION_METHOD_MEDIAN:
     42       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_MEDIAN_DESCRIPTION;
     43       break;
     44     case AGGREGATION_METHOD_MEAN:
     45       string_id = IDS_PERFORMANCE_MONITOR_AGGREGATION_MEAN_DESCRIPTION;
     46       break;
     47     default:
     48       NOTREACHED();
     49   }
     50 
     51   return l10n_util::GetStringUTF16(string_id);
     52 }
     53 
     54 // Event-Related
     55 base::string16 GetLocalizedStringFromEventCategory(
     56     const EventCategory category) {
     57   int string_id = 0;
     58   switch (category) {
     59     case EVENT_CATEGORY_CHROME:
     60       string_id = IDS_PRODUCT_NAME;
     61       break;
     62     case EVENT_CATEGORY_EXTENSIONS:
     63       string_id = IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY;
     64       break;
     65     case EVENT_CATEGORY_EXCEPTIONS:
     66       string_id = IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY;
     67       break;
     68     default:
     69       NOTREACHED();
     70   }
     71 
     72   return l10n_util::GetStringUTF16(string_id);
     73 }
     74 
     75 base::string16 GetLocalizedStringForEventCategoryDescription(
     76     const EventCategory category) {
     77   int string_id = 0;
     78   switch (category) {
     79     case EVENT_CATEGORY_EXTENSIONS:
     80       string_id = IDS_PERFORMANCE_MONITOR_EXTENSIONS_EVENT_CATEGORY_DESCRIPTION;
     81       break;
     82     case EVENT_CATEGORY_CHROME:
     83       string_id = IDS_PERFORMANCE_MONITOR_CHROME_EVENT_CATEGORY_DESCRIPTION;
     84       break;
     85     case EVENT_CATEGORY_EXCEPTIONS:
     86       string_id = IDS_PERFORMANCE_MONITOR_EXCEPTIONS_EVENT_CATEGORY_DESCRIPTION;
     87       break;
     88     default:
     89       NOTREACHED();
     90   }
     91 
     92   return l10n_util::GetStringFUTF16(
     93       string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
     94 }
     95 
     96 base::string16 GetLocalizedStringFromEventType(const EventType type) {
     97   int string_id = 0;
     98 
     99   switch (type) {
    100     case EVENT_EXTENSION_INSTALL:
    101       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT;
    102       break;
    103     case EVENT_EXTENSION_UNINSTALL:
    104       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT;
    105       break;
    106     case EVENT_EXTENSION_UPDATE:
    107       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT;
    108       break;
    109     case EVENT_EXTENSION_ENABLE:
    110       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT;
    111       break;
    112     case EVENT_EXTENSION_DISABLE:
    113       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT;
    114       break;
    115     case EVENT_CHROME_UPDATE:
    116       string_id = IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT;
    117       break;
    118     case EVENT_RENDERER_HANG:
    119       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_HANG_EVENT;
    120       break;
    121     case EVENT_RENDERER_CRASH:
    122       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT;
    123       break;
    124     case EVENT_RENDERER_KILLED:
    125       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_KILLED_EVENT;
    126       break;
    127     case EVENT_UNCLEAN_EXIT:
    128       string_id = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT;
    129       break;
    130     default:
    131       NOTREACHED();
    132   }
    133 
    134   return l10n_util::GetStringUTF16(string_id);
    135 }
    136 
    137 base::string16 GetLocalizedStringForEventTypeDescription(const EventType type) {
    138   int string_id1 = 0;
    139   int string_id2 = 0;
    140 
    141   switch (type) {
    142     case EVENT_EXTENSION_INSTALL:
    143       string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_DESCRIPTION;
    144       break;
    145     case EVENT_EXTENSION_UNINSTALL:
    146       string_id1 =
    147           IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_DESCRIPTION;
    148       break;
    149     case EVENT_EXTENSION_UPDATE:
    150       string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_DESCRIPTION;
    151       break;
    152     case EVENT_EXTENSION_ENABLE:
    153       string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_DESCRIPTION;
    154       break;
    155     case EVENT_EXTENSION_DISABLE:
    156       string_id1 = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_DESCRIPTION;
    157       break;
    158     case EVENT_CHROME_UPDATE:
    159       string_id1 = IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_DESCRIPTION;
    160       string_id2 = IDS_SHORT_PRODUCT_NAME;
    161       break;
    162     case EVENT_RENDERER_HANG:
    163       string_id1 = IDS_PERFORMANCE_MONITOR_RENDERER_HANG_EVENT_DESCRIPTION;
    164       break;
    165     case EVENT_RENDERER_CRASH:
    166       string_id1 = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_DESCRIPTION;
    167       string_id2 = IDS_SAD_TAB_TITLE;
    168       break;
    169     case EVENT_RENDERER_KILLED:
    170       string_id1 = IDS_PERFORMANCE_MONITOR_RENDERER_KILLED_EVENT_DESCRIPTION;
    171       string_id2 = IDS_KILLED_TAB_TITLE;
    172       break;
    173     case EVENT_UNCLEAN_EXIT:
    174       string_id1 = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_DESCRIPTION;
    175       string_id2 = IDS_SHORT_PRODUCT_NAME;
    176       break;
    177     default:
    178       NOTREACHED();
    179   }
    180 
    181   return string_id2 ?
    182          l10n_util::GetStringFUTF16(
    183              string_id1, l10n_util::GetStringUTF16(string_id2)) :
    184          l10n_util::GetStringUTF16(string_id1);
    185 }
    186 
    187 base::string16 GetLocalizedStringForEventTypeMouseover(const EventType type) {
    188   if (type == EVENT_CHROME_UPDATE) {
    189     return l10n_util::GetStringFUTF16(
    190         IDS_PERFORMANCE_MONITOR_CHROME_UPDATE_EVENT_MOUSEOVER,
    191         l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
    192   }
    193 
    194   int string_id = 0;
    195   switch (type) {
    196     case EVENT_EXTENSION_INSTALL:
    197       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_INSTALL_EVENT_MOUSEOVER;
    198       break;
    199     case EVENT_EXTENSION_UNINSTALL:
    200       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UNINSTALL_EVENT_MOUSEOVER;
    201       break;
    202     case EVENT_EXTENSION_UPDATE:
    203       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_UPDATE_EVENT_MOUSEOVER;
    204       break;
    205     case EVENT_EXTENSION_ENABLE:
    206       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ENABLE_EVENT_MOUSEOVER;
    207       break;
    208     case EVENT_EXTENSION_DISABLE:
    209       string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DISABLE_EVENT_MOUSEOVER;
    210       break;
    211     case EVENT_RENDERER_HANG:
    212       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_HANG_EVENT_MOUSEOVER;
    213       break;
    214     case EVENT_RENDERER_CRASH:
    215       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_CRASH_EVENT_MOUSEOVER;
    216       break;
    217     case EVENT_RENDERER_KILLED:
    218       string_id = IDS_PERFORMANCE_MONITOR_RENDERER_KILLED_EVENT_MOUSEOVER;
    219       break;
    220     case EVENT_UNCLEAN_EXIT:
    221       string_id = IDS_PERFORMANCE_MONITOR_UNCLEAN_EXIT_EVENT_MOUSEOVER;
    222       break;
    223     default:
    224       NOTREACHED();
    225   }
    226 
    227   return l10n_util::GetStringUTF16(string_id);
    228 }
    229 
    230 base::string16 GetLocalizedStringFromEventProperty(
    231     const std::string& property) {
    232   int string_id = 0;
    233 
    234   if (property == "extensionId")
    235     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_ID_MOUSEOVER;
    236   else if (property == "extensionName")
    237     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_NAME_MOUSEOVER;
    238   else if (property == "extensionUrl")
    239     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_URL_MOUSEOVER;
    240   else if (property == "extensionLocation")
    241     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_LOCATION_MOUSEOVER;
    242   else if (property == "extensionVersion")
    243     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_VERSION_MOUSEOVER;
    244   else if (property == "extensionDescription")
    245     string_id = IDS_PERFORMANCE_MONITOR_EXTENSION_DESCRIPTION_MOUSEOVER;
    246   else if (property == "previousVersion")
    247     string_id = IDS_PERFORMANCE_MONITOR_PREVIOUS_VERSION_MOUSEOVER;
    248   else if (property == "currentVersion")
    249     string_id = IDS_PERFORMANCE_MONITOR_CURRENT_VERSION_MOUSEOVER;
    250   else if (property == "url")
    251     string_id = IDS_PERFORMANCE_MONITOR_URL_MOUSEOVER;
    252   else if (property == "profileName")
    253     string_id = IDS_PERFORMANCE_MONITOR_PROFILE_NAME_MOUSEOVER;
    254   else
    255     NOTREACHED();
    256 
    257   return l10n_util::GetStringUTF16(string_id);
    258 }
    259 
    260 // Metric-Related
    261 base::string16 GetLocalizedStringFromMetricCategory(
    262     const MetricCategory category) {
    263   int string_id = 0;
    264 
    265   switch (category) {
    266     case METRIC_CATEGORY_CPU:
    267       string_id = IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY;
    268       break;
    269     case METRIC_CATEGORY_MEMORY:
    270       string_id = IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY;
    271       break;
    272     case METRIC_CATEGORY_TIMING:
    273       string_id = IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY;
    274       break;
    275     case METRIC_CATEGORY_NETWORK:
    276       string_id = IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY;
    277       break;
    278     default:
    279       NOTREACHED();
    280   }
    281 
    282   return l10n_util::GetStringUTF16(string_id);
    283 }
    284 
    285 base::string16 GetLocalizedStringForMetricCategoryDescription(
    286     const MetricCategory category) {
    287   int string_id = 0;
    288 
    289   switch (category) {
    290     case METRIC_CATEGORY_CPU:
    291       string_id = IDS_PERFORMANCE_MONITOR_CPU_METRIC_CATEGORY_DESCRIPTION;
    292       break;
    293     case METRIC_CATEGORY_MEMORY:
    294       string_id = IDS_PERFORMANCE_MONITOR_MEMORY_METRIC_CATEGORY_DESCRIPTION;
    295       break;
    296     case METRIC_CATEGORY_TIMING:
    297       string_id = IDS_PERFORMANCE_MONITOR_TIMING_METRIC_CATEGORY_DESCRIPTION;
    298       break;
    299     case METRIC_CATEGORY_NETWORK:
    300       string_id = IDS_PERFORMANCE_MONITOR_NETWORK_METRIC_CATEGORY_DESCRIPTION;
    301       break;
    302     default:
    303       NOTREACHED();
    304   }
    305 
    306   return l10n_util::GetStringFUTF16(
    307       string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
    308 }
    309 
    310 base::string16 GetLocalizedStringFromMetricType(const MetricType type) {
    311   int string_id = 0;
    312 
    313   switch (type) {
    314     case METRIC_CPU_USAGE:
    315       string_id = IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC;
    316       break;
    317     case METRIC_PRIVATE_MEMORY_USAGE:
    318       string_id = IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC;
    319       break;
    320     case METRIC_SHARED_MEMORY_USAGE:
    321       string_id = IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC;
    322       break;
    323     case METRIC_STARTUP_TIME:
    324       string_id = IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC;
    325       break;
    326     case METRIC_TEST_STARTUP_TIME:
    327       string_id = IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC;
    328       break;
    329     case METRIC_SESSION_RESTORE_TIME:
    330       string_id = IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC;
    331       break;
    332     case METRIC_PAGE_LOAD_TIME:
    333       string_id = IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC;
    334       break;
    335     case METRIC_NETWORK_BYTES_READ:
    336       string_id = IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC;
    337       break;
    338     default:
    339       NOTREACHED();
    340   }
    341 
    342   return l10n_util::GetStringUTF16(string_id);
    343 }
    344 
    345 base::string16 GetLocalizedStringForMetricTypeDescription(
    346     const MetricType type) {
    347   int string_id = 0;
    348 
    349   switch (type) {
    350     case METRIC_CPU_USAGE:
    351       string_id = IDS_PERFORMANCE_MONITOR_CPU_USAGE_METRIC_DESCRIPTION;
    352       break;
    353     case METRIC_PRIVATE_MEMORY_USAGE:
    354       string_id =
    355           IDS_PERFORMANCE_MONITOR_PRIVATE_MEMORY_USAGE_METRIC_DESCRIPTION;
    356       break;
    357     case METRIC_SHARED_MEMORY_USAGE:
    358       string_id =
    359           IDS_PERFORMANCE_MONITOR_SHARED_MEMORY_USAGE_METRIC_DESCRIPTION;
    360       break;
    361     case METRIC_STARTUP_TIME:
    362       string_id = IDS_PERFORMANCE_MONITOR_STARTUP_TIME_METRIC_DESCRIPTION;
    363       break;
    364     case METRIC_TEST_STARTUP_TIME:
    365       string_id = IDS_PERFORMANCE_MONITOR_TEST_STARTUP_TIME_METRIC_DESCRIPTION;
    366       break;
    367     default:
    368       break;
    369   }
    370 
    371   if (string_id) {
    372     return l10n_util::GetStringFUTF16(
    373         string_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
    374   }
    375 
    376   switch (type) {
    377     case METRIC_SESSION_RESTORE_TIME:
    378       string_id =
    379           IDS_PERFORMANCE_MONITOR_SESSION_RESTORE_TIME_METRIC_DESCRIPTION;
    380       break;
    381     case METRIC_PAGE_LOAD_TIME:
    382       string_id = IDS_PERFORMANCE_MONITOR_PAGE_LOAD_TIME_METRIC_DESCRIPTION;
    383       break;
    384     case METRIC_NETWORK_BYTES_READ:
    385       string_id = IDS_PERFORMANCE_MONITOR_NETWORK_BYTES_READ_METRIC_DESCRIPTION;
    386       break;
    387     default:
    388       NOTREACHED();
    389   }
    390 
    391   return l10n_util::GetStringUTF16(string_id);
    392 }
    393 
    394 // Miscellaneous
    395 base::string16 GetLocalizedStringFromUnit(const Unit unit) {
    396   int string_id = 0;
    397 
    398   switch (unit) {
    399     case UNIT_BYTES:
    400       string_id = IDS_PERFORMANCE_MONITOR_BYTES_UNIT;
    401       break;
    402     case UNIT_KILOBYTES:
    403       string_id = IDS_PERFORMANCE_MONITOR_KILOBYTES_UNIT;
    404       break;
    405     case UNIT_MEGABYTES:
    406       string_id = IDS_PERFORMANCE_MONITOR_MEGABYTES_UNIT;
    407       break;
    408     case UNIT_GIGABYTES:
    409       string_id = IDS_PERFORMANCE_MONITOR_GIGABYTES_UNIT;
    410       break;
    411     case UNIT_TERABYTES:
    412       string_id = IDS_PERFORMANCE_MONITOR_TERABYTES_UNIT;
    413       break;
    414     case UNIT_MICROSECONDS:
    415       string_id = IDS_PERFORMANCE_MONITOR_MICROSECONDS_UNIT;
    416       break;
    417     case UNIT_MILLISECONDS:
    418       string_id = IDS_PERFORMANCE_MONITOR_MILLISECONDS_UNIT;
    419       break;
    420     case UNIT_SECONDS:
    421       string_id = IDS_PERFORMANCE_MONITOR_SECONDS_UNIT;
    422       break;
    423     case UNIT_MINUTES:
    424       string_id = IDS_PERFORMANCE_MONITOR_MINUTES_UNIT;
    425       break;
    426     case UNIT_HOURS:
    427       string_id = IDS_PERFORMANCE_MONITOR_HOURS_UNIT;
    428       break;
    429     case UNIT_DAYS:
    430       string_id = IDS_PERFORMANCE_MONITOR_DAYS_UNIT;
    431       break;
    432     case UNIT_WEEKS:
    433       string_id = IDS_PERFORMANCE_MONITOR_WEEKS_UNIT;
    434       break;
    435     case UNIT_MONTHS:
    436       string_id = IDS_PERFORMANCE_MONITOR_MONTHS_UNIT;
    437       break;
    438     case UNIT_YEARS:
    439       string_id = IDS_PERFORMANCE_MONITOR_YEARS_UNIT;
    440       break;
    441     case UNIT_PERCENT:
    442       string_id = IDS_PERFORMANCE_MONITOR_PERCENT_UNIT;
    443       break;
    444     default:
    445       NOTREACHED();
    446   }
    447 
    448   return l10n_util::GetStringUTF16(string_id);
    449 }
    450 
    451 }  // namespace performance_monitor
    452