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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 #include "base/threading/platform_thread.h" | 167 #include "base/threading/platform_thread.h" |
168 #include "base/threading/thread.h" | 168 #include "base/threading/thread.h" |
169 #include "base/utf_string_conversions.h" | 169 #include "base/utf_string_conversions.h" |
170 #include "base/values.h" | 170 #include "base/values.h" |
171 #include "chrome/browser/bookmarks/bookmark_model.h" | 171 #include "chrome/browser/bookmarks/bookmark_model.h" |
172 #include "chrome/browser/browser_process.h" | 172 #include "chrome/browser/browser_process.h" |
173 #include "chrome/browser/memory_details.h" | 173 #include "chrome/browser/memory_details.h" |
174 #include "chrome/browser/metrics/histogram_synchronizer.h" | 174 #include "chrome/browser/metrics/histogram_synchronizer.h" |
175 #include "chrome/browser/metrics/metrics_log.h" | 175 #include "chrome/browser/metrics/metrics_log.h" |
176 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" | 176 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" |
| 177 #include "chrome/browser/net/network_stats.h" |
177 #include "chrome/browser/prefs/pref_service.h" | 178 #include "chrome/browser/prefs/pref_service.h" |
178 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 179 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
179 #include "chrome/browser/profiles/profile.h" | 180 #include "chrome/browser/profiles/profile.h" |
180 #include "chrome/browser/search_engines/template_url_service.h" | 181 #include "chrome/browser/search_engines/template_url_service.h" |
181 #include "chrome/browser/ui/browser_list.h" | 182 #include "chrome/browser/ui/browser_list.h" |
182 #include "chrome/common/child_process_logging.h" | 183 #include "chrome/common/child_process_logging.h" |
183 #include "chrome/common/chrome_switches.h" | 184 #include "chrome/common/chrome_switches.h" |
184 #include "chrome/common/guid.h" | 185 #include "chrome/common/guid.h" |
185 #include "chrome/common/pref_names.h" | 186 #include "chrome/common/pref_names.h" |
186 #include "chrome/common/render_messages.h" | 187 #include "chrome/common/render_messages.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 432 |
432 local_state->ClearPref(prefs::kMetricsInitialLogs); | 433 local_state->ClearPref(prefs::kMetricsInitialLogs); |
433 local_state->ClearPref(prefs::kMetricsOngoingLogs); | 434 local_state->ClearPref(prefs::kMetricsOngoingLogs); |
434 } | 435 } |
435 | 436 |
436 MetricsService::MetricsService() | 437 MetricsService::MetricsService() |
437 : recording_active_(false), | 438 : recording_active_(false), |
438 reporting_active_(false), | 439 reporting_active_(false), |
439 state_(INITIALIZED), | 440 state_(INITIALIZED), |
440 current_fetch_(NULL), | 441 current_fetch_(NULL), |
| 442 io_thread_(NULL), |
441 idle_since_last_transmission_(false), | 443 idle_since_last_transmission_(false), |
442 next_window_id_(0), | 444 next_window_id_(0), |
443 ALLOW_THIS_IN_INITIALIZER_LIST(log_sender_factory_(this)), | 445 ALLOW_THIS_IN_INITIALIZER_LIST(log_sender_factory_(this)), |
444 ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)), | 446 ALLOW_THIS_IN_INITIALIZER_LIST(state_saver_factory_(this)), |
445 waiting_for_asynchronus_reporting_step_(false) { | 447 waiting_for_asynchronus_reporting_step_(false) { |
446 DCHECK(IsSingleThreaded()); | 448 DCHECK(IsSingleThreaded()); |
447 InitializeMetricsState(); | 449 InitializeMetricsState(); |
448 | 450 |
449 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 451 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
450 base::Unretained(this)); | 452 base::Unretained(this)); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 // private methods | 689 // private methods |
688 //------------------------------------------------------------------------------ | 690 //------------------------------------------------------------------------------ |
689 | 691 |
690 | 692 |
691 //------------------------------------------------------------------------------ | 693 //------------------------------------------------------------------------------ |
692 // Initialization methods | 694 // Initialization methods |
693 | 695 |
694 void MetricsService::InitializeMetricsState() { | 696 void MetricsService::InitializeMetricsState() { |
695 #if defined(OS_POSIX) | 697 #if defined(OS_POSIX) |
696 server_url_ = L"https://clients4.google.com/firefox/metrics/collect"; | 698 server_url_ = L"https://clients4.google.com/firefox/metrics/collect"; |
| 699 // TODO(rtenneti): Return the network stats server name. |
| 700 network_stats_server_ = ""; |
697 #else | 701 #else |
698 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 702 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
699 server_url_ = dist->GetStatsServerURL(); | 703 server_url_ = dist->GetStatsServerURL(); |
| 704 network_stats_server_ = dist->GetNetworkStatsServer(); |
700 #endif | 705 #endif |
701 | 706 |
702 PrefService* pref = g_browser_process->local_state(); | 707 PrefService* pref = g_browser_process->local_state(); |
703 DCHECK(pref); | 708 DCHECK(pref); |
704 | 709 |
705 if ((pref->GetInt64(prefs::kStabilityStatsBuildTime) | 710 if ((pref->GetInt64(prefs::kStabilityStatsBuildTime) |
706 != MetricsLog::GetBuildTime()) || | 711 != MetricsLog::GetBuildTime()) || |
707 (pref->GetString(prefs::kStabilityStatsVersion) | 712 (pref->GetString(prefs::kStabilityStatsVersion) |
708 != MetricsLog::GetVersionString())) { | 713 != MetricsLog::GetVersionString())) { |
709 // This is a new version, so we don't want to confuse the stats about the | 714 // This is a new version, so we don't want to confuse the stats about the |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 // getting updated) every n minutes. | 790 // getting updated) every n minutes. |
786 ScheduleNextStateSave(); | 791 ScheduleNextStateSave(); |
787 } | 792 } |
788 | 793 |
789 void MetricsService::OnInitTaskComplete( | 794 void MetricsService::OnInitTaskComplete( |
790 const std::string& hardware_class, | 795 const std::string& hardware_class, |
791 const std::vector<webkit::npapi::WebPluginInfo>& plugins) { | 796 const std::vector<webkit::npapi::WebPluginInfo>& plugins) { |
792 DCHECK(state_ == INIT_TASK_SCHEDULED); | 797 DCHECK(state_ == INIT_TASK_SCHEDULED); |
793 hardware_class_ = hardware_class; | 798 hardware_class_ = hardware_class; |
794 plugins_ = plugins; | 799 plugins_ = plugins; |
| 800 io_thread_ = g_browser_process->io_thread(); |
795 if (state_ == INIT_TASK_SCHEDULED) | 801 if (state_ == INIT_TASK_SCHEDULED) |
796 state_ = INIT_TASK_DONE; | 802 state_ = INIT_TASK_DONE; |
797 } | 803 } |
798 | 804 |
799 std::string MetricsService::GenerateClientID() { | 805 std::string MetricsService::GenerateClientID() { |
800 return guid::GenerateGUID(); | 806 return guid::GenerateGUID(); |
801 } | 807 } |
802 | 808 |
803 //------------------------------------------------------------------------------ | 809 //------------------------------------------------------------------------------ |
804 // State save methods | 810 // State save methods |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 | 1364 |
1359 if (unsent_logs()) | 1365 if (unsent_logs()) |
1360 DCHECK(state_ < SENDING_CURRENT_LOGS); | 1366 DCHECK(state_ < SENDING_CURRENT_LOGS); |
1361 } | 1367 } |
1362 | 1368 |
1363 // Error 400 indicates a problem with the log, not with the server, so | 1369 // Error 400 indicates a problem with the log, not with the server, so |
1364 // don't consider that a sign that the server is in trouble. | 1370 // don't consider that a sign that the server is in trouble. |
1365 bool server_is_healthy = upload_succeeded || response_code == 400; | 1371 bool server_is_healthy = upload_succeeded || response_code == 400; |
1366 | 1372 |
1367 scheduler_->UploadFinished(server_is_healthy, unsent_logs()); | 1373 scheduler_->UploadFinished(server_is_healthy, unsent_logs()); |
| 1374 |
| 1375 // Collect network stats if UMA upload succeeded. |
| 1376 if (server_is_healthy && io_thread_) |
| 1377 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_); |
1368 } | 1378 } |
1369 | 1379 |
1370 void MetricsService::LogBadResponseCode() { | 1380 void MetricsService::LogBadResponseCode() { |
1371 VLOG(1) << "Verify your metrics logs are formatted correctly. Verify server " | 1381 VLOG(1) << "Verify your metrics logs are formatted correctly. Verify server " |
1372 "is active at " << server_url_; | 1382 "is active at " << server_url_; |
1373 if (!pending_log()) { | 1383 if (!pending_log()) { |
1374 VLOG(1) << "METRICS: Recorder shutdown during log transmission."; | 1384 VLOG(1) << "METRICS: Recorder shutdown during log transmission."; |
1375 } else { | 1385 } else { |
1376 VLOG(1) << "METRICS: transmission retry being scheduled for " | 1386 VLOG(1) << "METRICS: transmission retry being scheduled for " |
1377 << compressed_log_; | 1387 << compressed_log_; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 thread_id = base::PlatformThread::CurrentId(); | 1694 thread_id = base::PlatformThread::CurrentId(); |
1685 return base::PlatformThread::CurrentId() == thread_id; | 1695 return base::PlatformThread::CurrentId() == thread_id; |
1686 } | 1696 } |
1687 | 1697 |
1688 #if defined(OS_CHROMEOS) | 1698 #if defined(OS_CHROMEOS) |
1689 void MetricsService::StartExternalMetrics() { | 1699 void MetricsService::StartExternalMetrics() { |
1690 external_metrics_ = new chromeos::ExternalMetrics; | 1700 external_metrics_ = new chromeos::ExternalMetrics; |
1691 external_metrics_->Start(); | 1701 external_metrics_->Start(); |
1692 } | 1702 } |
1693 #endif | 1703 #endif |
OLD | NEW |