Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
| 6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
| 7 // | 7 // |
| 8 // OVERVIEW | 8 // OVERVIEW |
| 9 // | 9 // |
| 10 // A MetricsService instance is typically created at application startup. It | 10 // A MetricsService instance is typically created at application startup. It |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 #include "chrome/common/child_process_logging.h" | 171 #include "chrome/common/child_process_logging.h" |
| 172 #include "chrome/common/chrome_notification_types.h" | 172 #include "chrome/common/chrome_notification_types.h" |
| 173 #include "chrome/common/chrome_switches.h" | 173 #include "chrome/common/chrome_switches.h" |
| 174 #include "chrome/common/guid.h" | 174 #include "chrome/common/guid.h" |
| 175 #include "chrome/common/metrics_log_manager.h" | 175 #include "chrome/common/metrics_log_manager.h" |
| 176 #include "chrome/common/pref_names.h" | 176 #include "chrome/common/pref_names.h" |
| 177 #include "chrome/common/render_messages.h" | 177 #include "chrome/common/render_messages.h" |
| 178 #include "content/browser/load_notification_details.h" | 178 #include "content/browser/load_notification_details.h" |
| 179 #include "content/browser/plugin_service.h" | 179 #include "content/browser/plugin_service.h" |
| 180 #include "content/browser/renderer_host/render_process_host.h" | 180 #include "content/browser/renderer_host/render_process_host.h" |
| 181 #include "content/common/child_process_info.h" | |
| 182 #include "content/public/browser/notification_service.h" | 181 #include "content/public/browser/notification_service.h" |
| 183 #include "content/public/common/url_fetcher.h" | 182 #include "content/public/common/url_fetcher.h" |
| 184 #include "webkit/plugins/npapi/plugin_list.h" | 183 #include "webkit/plugins/npapi/plugin_list.h" |
| 185 #include "webkit/plugins/webplugininfo.h" | 184 #include "webkit/plugins/webplugininfo.h" |
| 186 | 185 |
| 187 // TODO(port): port browser_distribution.h. | 186 // TODO(port): port browser_distribution.h. |
| 188 #if !defined(OS_POSIX) | 187 #if !defined(OS_POSIX) |
| 189 #include "chrome/installer/util/browser_distribution.h" | 188 #include "chrome/installer/util/browser_distribution.h" |
| 190 #endif | 189 #endif |
| 191 | 190 |
| (...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1351 break; | 1350 break; |
| 1352 | 1351 |
| 1353 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: | 1352 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: |
| 1354 stats.instances++; | 1353 stats.instances++; |
| 1355 break; | 1354 break; |
| 1356 | 1355 |
| 1357 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: | 1356 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
| 1358 stats.process_crashes++; | 1357 stats.process_crashes++; |
| 1359 // Exclude plugin crashes from the count below because we report them via | 1358 // Exclude plugin crashes from the count below because we report them via |
| 1360 // a separate UMA metric. | 1359 // a separate UMA metric. |
| 1361 if (child_details->type() != ChildProcessInfo::PLUGIN_PROCESS) { | 1360 if (!IsPluginProcess(child_details->type())) { |
| 1362 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | 1361 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
| 1363 } | 1362 } |
| 1364 break; | 1363 break; |
| 1365 | 1364 |
| 1366 default: | 1365 default: |
| 1367 NOTREACHED() << "Unexpected notification type " << type; | 1366 NOTREACHED() << "Unexpected notification type " << type; |
| 1368 return; | 1367 return; |
| 1369 } | 1368 } |
| 1370 } | 1369 } |
| 1371 | 1370 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1468 } | 1467 } |
| 1469 | 1468 |
| 1470 // Now go through and add dictionaries for plugins that didn't already have | 1469 // Now go through and add dictionaries for plugins that didn't already have |
| 1471 // reports in Local State. | 1470 // reports in Local State. |
| 1472 for (std::map<string16, ChildProcessStats>::iterator cache_iter = | 1471 for (std::map<string16, ChildProcessStats>::iterator cache_iter = |
| 1473 child_process_stats_buffer_.begin(); | 1472 child_process_stats_buffer_.begin(); |
| 1474 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { | 1473 cache_iter != child_process_stats_buffer_.end(); ++cache_iter) { |
| 1475 ChildProcessStats stats = cache_iter->second; | 1474 ChildProcessStats stats = cache_iter->second; |
| 1476 | 1475 |
| 1477 // Insert only plugins information into the plugins list. | 1476 // Insert only plugins information into the plugins list. |
| 1478 if (ChildProcessInfo::PLUGIN_PROCESS != stats.process_type) | 1477 if (!IsPluginProcess(stats.process_type)) |
| 1479 continue; | 1478 continue; |
| 1480 | 1479 |
| 1481 // TODO(viettrungluu): remove conversion | 1480 // TODO(viettrungluu): remove conversion |
| 1482 std::string plugin_name = UTF16ToUTF8(cache_iter->first); | 1481 std::string plugin_name = UTF16ToUTF8(cache_iter->first); |
| 1483 | 1482 |
| 1484 DictionaryValue* plugin_dict = new DictionaryValue; | 1483 DictionaryValue* plugin_dict = new DictionaryValue; |
| 1485 | 1484 |
| 1486 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); | 1485 plugin_dict->SetString(prefs::kStabilityPluginName, plugin_name); |
| 1487 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, | 1486 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, |
| 1488 stats.process_launches); | 1487 stats.process_launches); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1514 pref->SetBoolean(path, value); | 1513 pref->SetBoolean(path, value); |
| 1515 RecordCurrentState(pref); | 1514 RecordCurrentState(pref); |
| 1516 } | 1515 } |
| 1517 | 1516 |
| 1518 void MetricsService::RecordCurrentState(PrefService* pref) { | 1517 void MetricsService::RecordCurrentState(PrefService* pref) { |
| 1519 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); | 1518 pref->SetInt64(prefs::kStabilityLastTimestampSec, Time::Now().ToTimeT()); |
| 1520 | 1519 |
| 1521 RecordPluginChanges(pref); | 1520 RecordPluginChanges(pref); |
| 1522 } | 1521 } |
| 1523 | 1522 |
| 1523 // static | |
| 1524 bool MetricsService::IsPluginProcess(ChildProcessInfo::ProcessType type) { | |
| 1525 switch (type) { | |
| 1526 case ChildProcessInfo::PLUGIN_PROCESS: | |
| 1527 #if defined(OS_CHROMEOS) | |
| 1528 case ChildProcessInfo::PPAPI_PLUGIN_PROCESS: | |
|
jar (doing other things)
2011/11/08 22:16:31
Could you just use a traditional logical ||, and n
petkov
2011/11/09 14:21:07
Done.
| |
| 1529 #endif | |
| 1530 return true; | |
| 1531 default: | |
| 1532 break; | |
| 1533 } | |
| 1534 return false; | |
| 1535 } | |
| 1536 | |
| 1524 static bool IsSingleThreaded() { | 1537 static bool IsSingleThreaded() { |
| 1525 static base::PlatformThreadId thread_id = 0; | 1538 static base::PlatformThreadId thread_id = 0; |
| 1526 if (!thread_id) | 1539 if (!thread_id) |
| 1527 thread_id = base::PlatformThread::CurrentId(); | 1540 thread_id = base::PlatformThread::CurrentId(); |
| 1528 return base::PlatformThread::CurrentId() == thread_id; | 1541 return base::PlatformThread::CurrentId() == thread_id; |
| 1529 } | 1542 } |
| 1530 | 1543 |
| 1531 #if defined(OS_CHROMEOS) | 1544 #if defined(OS_CHROMEOS) |
| 1532 void MetricsService::StartExternalMetrics() { | 1545 void MetricsService::StartExternalMetrics() { |
| 1533 external_metrics_ = new chromeos::ExternalMetrics; | 1546 external_metrics_ = new chromeos::ExternalMetrics; |
| 1534 external_metrics_->Start(); | 1547 external_metrics_->Start(); |
| 1535 } | 1548 } |
| 1536 #endif | 1549 #endif |
| 1537 | 1550 |
| 1538 // static | 1551 // static |
| 1539 bool MetricsServiceHelper::IsMetricsReportingEnabled() { | 1552 bool MetricsServiceHelper::IsMetricsReportingEnabled() { |
| 1540 bool result = false; | 1553 bool result = false; |
| 1541 const PrefService* local_state = g_browser_process->local_state(); | 1554 const PrefService* local_state = g_browser_process->local_state(); |
| 1542 if (local_state) { | 1555 if (local_state) { |
| 1543 const PrefService::Preference* uma_pref = | 1556 const PrefService::Preference* uma_pref = |
| 1544 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1557 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
| 1545 if (uma_pref) { | 1558 if (uma_pref) { |
| 1546 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1559 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
| 1547 DCHECK(success); | 1560 DCHECK(success); |
| 1548 } | 1561 } |
| 1549 } | 1562 } |
| 1550 return result; | 1563 return result; |
| 1551 } | 1564 } |
| OLD | NEW |