| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 is | 10 // A MetricsService instance is typically created at application startup. It is |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 registry->RegisterListPref(prefs::kMetricsInitialLogs); | 253 registry->RegisterListPref(prefs::kMetricsInitialLogs); |
| 254 registry->RegisterListPref(prefs::kMetricsOngoingLogs); | 254 registry->RegisterListPref(prefs::kMetricsOngoingLogs); |
| 255 | 255 |
| 256 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); | 256 registry->RegisterInt64Pref(prefs::kUninstallLaunchCount, 0); |
| 257 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); | 257 registry->RegisterInt64Pref(prefs::kUninstallMetricsUptimeSec, 0); |
| 258 } | 258 } |
| 259 | 259 |
| 260 MetricsService::MetricsService(MetricsStateManager* state_manager, | 260 MetricsService::MetricsService(MetricsStateManager* state_manager, |
| 261 MetricsServiceClient* client, | 261 MetricsServiceClient* client, |
| 262 PrefService* local_state) | 262 PrefService* local_state) |
| 263 : log_manager_(local_state, kUploadLogAvoidRetransmitSize), | 263 : log_store_(local_state, kUploadLogAvoidRetransmitSize), |
| 264 histogram_snapshot_manager_(this), | 264 histogram_snapshot_manager_(this), |
| 265 state_manager_(state_manager), | 265 state_manager_(state_manager), |
| 266 client_(client), | 266 client_(client), |
| 267 local_state_(local_state), | 267 local_state_(local_state), |
| 268 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), | 268 clean_exit_beacon_(client->GetRegistryBackupKey(), local_state), |
| 269 recording_state_(UNSET), | 269 recording_state_(UNSET), |
| 270 reporting_active_(false), | 270 reporting_active_(false), |
| 271 test_mode_active_(false), | 271 test_mode_active_(false), |
| 272 state_(INITIALIZED), | 272 state_(INITIALIZED), |
| 273 log_upload_in_progress_(false), | 273 log_upload_in_progress_(false), |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); | 531 local_state_->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
| 532 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); | 532 local_state_->SetInteger(prefs::kStabilityLaunchCount, 0); |
| 533 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); | 533 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, true); |
| 534 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); | 534 local_state_->SetInteger(prefs::kStabilityDeferredCount, 0); |
| 535 // Note: kStabilityDiscardCount is not cleared as its intent is to measure | 535 // Note: kStabilityDiscardCount is not cleared as its intent is to measure |
| 536 // the number of times data is discarded, even across versions. | 536 // the number of times data is discarded, even across versions. |
| 537 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); | 537 local_state_->SetInteger(prefs::kStabilityVersionMismatchCount, 0); |
| 538 } | 538 } |
| 539 | 539 |
| 540 void MetricsService::PushExternalLog(const std::string& log) { | 540 void MetricsService::PushExternalLog(const std::string& log) { |
| 541 log_manager_.StoreLog(log, MetricsLog::ONGOING_LOG); | 541 log_store_.StoreLog(log, MetricsLog::ONGOING_LOG); |
| 542 } | 542 } |
| 543 | 543 |
| 544 void MetricsService::UpdateMetricsUsagePrefs(const std::string& service_name, | 544 void MetricsService::UpdateMetricsUsagePrefs(const std::string& service_name, |
| 545 int message_size, | 545 int message_size, |
| 546 bool is_cellular) { | 546 bool is_cellular) { |
| 547 DCHECK(thread_checker_.CalledOnValidThread()); | 547 DCHECK(thread_checker_.CalledOnValidThread()); |
| 548 if (data_use_tracker_) { | 548 if (data_use_tracker_) { |
| 549 data_use_tracker_->UpdateMetricsUsagePrefs(service_name, | 549 data_use_tracker_->UpdateMetricsUsagePrefs(service_name, |
| 550 message_size, | 550 message_size, |
| 551 is_cellular); | 551 is_cellular); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 573 int64_t previous_buildtime = | 573 int64_t previous_buildtime = |
| 574 local_state_->GetInt64(prefs::kStabilityStatsBuildTime); | 574 local_state_->GetInt64(prefs::kStabilityStatsBuildTime); |
| 575 std::string previous_version = | 575 std::string previous_version = |
| 576 local_state_->GetString(prefs::kStabilityStatsVersion); | 576 local_state_->GetString(prefs::kStabilityStatsVersion); |
| 577 if (previous_buildtime != buildtime || previous_version != version) { | 577 if (previous_buildtime != buildtime || previous_version != version) { |
| 578 local_state_->SetString(prefs::kStabilityStatsVersion, version); | 578 local_state_->SetString(prefs::kStabilityStatsVersion, version); |
| 579 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); | 579 local_state_->SetInt64(prefs::kStabilityStatsBuildTime, buildtime); |
| 580 version_changed = true; | 580 version_changed = true; |
| 581 } | 581 } |
| 582 | 582 |
| 583 log_manager_.LoadPersistedUnsentLogs(); | 583 log_store_.LoadPersistedUnsentLogs(); |
| 584 | 584 |
| 585 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); | 585 session_id_ = local_state_->GetInteger(prefs::kMetricsSessionID); |
| 586 | 586 |
| 587 if (!clean_exit_beacon_.exited_cleanly()) { | 587 if (!clean_exit_beacon_.exited_cleanly()) { |
| 588 IncrementPrefValue(prefs::kStabilityCrashCount); | 588 IncrementPrefValue(prefs::kStabilityCrashCount); |
| 589 // Reset flag, and wait until we call LogNeedForCleanShutdown() before | 589 // Reset flag, and wait until we call LogNeedForCleanShutdown() before |
| 590 // monitoring. | 590 // monitoring. |
| 591 clean_exit_beacon_.WriteBeaconValue(true); | 591 clean_exit_beacon_.WriteBeaconValue(true); |
| 592 ExecutionPhaseManager manager(local_state_); | 592 ExecutionPhaseManager manager(local_state_); |
| 593 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", | 593 UMA_HISTOGRAM_SPARSE_SLOWLY("Chrome.Browser.CrashedExecutionPhase", |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 RecordCurrentEnvironment(current_log); | 767 RecordCurrentEnvironment(current_log); |
| 768 base::TimeDelta incremental_uptime; | 768 base::TimeDelta incremental_uptime; |
| 769 base::TimeDelta uptime; | 769 base::TimeDelta uptime; |
| 770 GetUptimes(local_state_, &incremental_uptime, &uptime); | 770 GetUptimes(local_state_, &incremental_uptime, &uptime); |
| 771 current_log->RecordStabilityMetrics(metrics_providers_, incremental_uptime, | 771 current_log->RecordStabilityMetrics(metrics_providers_, incremental_uptime, |
| 772 uptime); | 772 uptime); |
| 773 | 773 |
| 774 current_log->RecordGeneralMetrics(metrics_providers_); | 774 current_log->RecordGeneralMetrics(metrics_providers_); |
| 775 RecordCurrentHistograms(); | 775 RecordCurrentHistograms(); |
| 776 DVLOG(1) << "Generated an ongoing log."; | 776 DVLOG(1) << "Generated an ongoing log."; |
| 777 log_manager_.FinishCurrentLog(); | 777 log_manager_.FinishCurrentLog(&log_store_); |
| 778 } | 778 } |
| 779 | 779 |
| 780 void MetricsService::PushPendingLogsToPersistentStorage() { | 780 void MetricsService::PushPendingLogsToPersistentStorage() { |
| 781 if (state_ < SENDING_LOGS) | 781 if (state_ < SENDING_LOGS) |
| 782 return; // We didn't and still don't have time to get plugin list etc. | 782 return; // We didn't and still don't have time to get plugin list etc. |
| 783 | 783 |
| 784 CloseCurrentLog(); | 784 CloseCurrentLog(); |
| 785 log_manager_.PersistUnsentLogs(); | 785 log_store_.PersistUnsentLogs(); |
| 786 } | 786 } |
| 787 | 787 |
| 788 //------------------------------------------------------------------------------ | 788 //------------------------------------------------------------------------------ |
| 789 // Transmission of logs methods | 789 // Transmission of logs methods |
| 790 | 790 |
| 791 void MetricsService::StartSchedulerIfNecessary() { | 791 void MetricsService::StartSchedulerIfNecessary() { |
| 792 // Never schedule cutting or uploading of logs in test mode. | 792 // Never schedule cutting or uploading of logs in test mode. |
| 793 if (test_mode_active_) | 793 if (test_mode_active_) |
| 794 return; | 794 return; |
| 795 | 795 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 826 rotation_scheduler_->RotationFinished(); | 826 rotation_scheduler_->RotationFinished(); |
| 827 } else { | 827 } else { |
| 828 scheduler_->Stop(); | 828 scheduler_->Stop(); |
| 829 scheduler_->UploadCancelled(); | 829 scheduler_->UploadCancelled(); |
| 830 } | 830 } |
| 831 return; | 831 return; |
| 832 } | 832 } |
| 833 | 833 |
| 834 // If there are unsent logs, send the next one. If not, start the asynchronous | 834 // If there are unsent logs, send the next one. If not, start the asynchronous |
| 835 // process of finalizing the current log for upload. | 835 // process of finalizing the current log for upload. |
| 836 if (state_ == SENDING_LOGS && log_manager_.has_unsent_logs()) { | 836 if (state_ == SENDING_LOGS && log_store_.has_unsent_logs()) { |
| 837 if (upload_scheduler_) { | 837 if (upload_scheduler_) { |
| 838 upload_scheduler_->Start(); | 838 upload_scheduler_->Start(); |
| 839 rotation_scheduler_->RotationFinished(); | 839 rotation_scheduler_->RotationFinished(); |
| 840 } else { | 840 } else { |
| 841 SendNextLog(); | 841 SendNextLog(); |
| 842 } | 842 } |
| 843 } else { | 843 } else { |
| 844 // There are no logs left to send, so start creating a new one. | 844 // There are no logs left to send, so start creating a new one. |
| 845 client_->CollectFinalMetricsForLog( | 845 client_->CollectFinalMetricsForLog( |
| 846 base::Bind(&MetricsService::OnFinalLogInfoCollectionDone, | 846 base::Bind(&MetricsService::OnFinalLogInfoCollectionDone, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 DCHECK_EQ(SENDING_LOGS, state_); | 893 DCHECK_EQ(SENDING_LOGS, state_); |
| 894 if (!reporting_active()) { | 894 if (!reporting_active()) { |
| 895 if (upload_scheduler_) { | 895 if (upload_scheduler_) { |
| 896 upload_scheduler_->StopAndUploadCancelled(); | 896 upload_scheduler_->StopAndUploadCancelled(); |
| 897 } else { | 897 } else { |
| 898 scheduler_->Stop(); | 898 scheduler_->Stop(); |
| 899 scheduler_->UploadCancelled(); | 899 scheduler_->UploadCancelled(); |
| 900 } | 900 } |
| 901 return; | 901 return; |
| 902 } | 902 } |
| 903 if (!log_manager_.has_unsent_logs()) { | 903 if (!log_store_.has_unsent_logs()) { |
| 904 // Should only get here if serializing the log failed somehow. | 904 // Should only get here if serializing the log failed somehow. |
| 905 if (upload_scheduler_) { | 905 if (upload_scheduler_) { |
| 906 upload_scheduler_->Stop(); | 906 upload_scheduler_->Stop(); |
| 907 // Reset backoff interval | 907 // Reset backoff interval |
| 908 upload_scheduler_->UploadFinished(true); | 908 upload_scheduler_->UploadFinished(true); |
| 909 } else { | 909 } else { |
| 910 // Just tell the scheduler it was uploaded and wait for the next log | 910 // Just tell the scheduler it was uploaded and wait for the next log |
| 911 // interval. | 911 // interval. |
| 912 scheduler_->UploadFinished(true, log_manager_.has_unsent_logs()); | 912 scheduler_->UploadFinished(true, log_store_.has_unsent_logs()); |
| 913 } | 913 } |
| 914 return; | 914 return; |
| 915 } | 915 } |
| 916 if (!log_manager_.has_staged_log()) | 916 if (!log_store_.has_staged_log()) |
| 917 log_manager_.StageNextLogForUpload(); | 917 log_store_.StageNextLog(); |
| 918 | 918 |
| 919 // Proceed to stage the log for upload if log size satisfies cellular log | 919 // Proceed to stage the log for upload if log size satisfies cellular log |
| 920 // upload constrains. | 920 // upload constrains. |
| 921 bool upload_canceled = false; | 921 bool upload_canceled = false; |
| 922 bool is_cellular_logic = client_->IsUMACellularUploadLogicEnabled(); | 922 bool is_cellular_logic = client_->IsUMACellularUploadLogicEnabled(); |
| 923 if (is_cellular_logic && data_use_tracker_ && | 923 if (is_cellular_logic && data_use_tracker_ && |
| 924 !data_use_tracker_->ShouldUploadLogOnCellular( | 924 !data_use_tracker_->ShouldUploadLogOnCellular( |
| 925 log_manager_.staged_log_hash().size())) { | 925 log_store_.staged_log_hash().size())) { |
| 926 if (upload_scheduler_) { | 926 if (upload_scheduler_) { |
| 927 upload_scheduler_->UploadOverDataUsageCap(); | 927 upload_scheduler_->UploadOverDataUsageCap(); |
| 928 } else { | 928 } else { |
| 929 scheduler_->UploadCancelled(); | 929 scheduler_->UploadCancelled(); |
| 930 } | 930 } |
| 931 upload_canceled = true; | 931 upload_canceled = true; |
| 932 } else { | 932 } else { |
| 933 SendStagedLog(); | 933 SendStagedLog(); |
| 934 } | 934 } |
| 935 if (is_cellular_logic) { | 935 if (is_cellular_logic) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 // Note: Some stability providers may record stability stats via histograms, | 973 // Note: Some stability providers may record stability stats via histograms, |
| 974 // so this call has to be after BeginLoggingWithLog(). | 974 // so this call has to be after BeginLoggingWithLog(). |
| 975 log_manager_.current_log()->RecordStabilityMetrics( | 975 log_manager_.current_log()->RecordStabilityMetrics( |
| 976 metrics_providers_, base::TimeDelta(), base::TimeDelta()); | 976 metrics_providers_, base::TimeDelta(), base::TimeDelta()); |
| 977 RecordCurrentStabilityHistograms(); | 977 RecordCurrentStabilityHistograms(); |
| 978 | 978 |
| 979 // Note: RecordGeneralMetrics() intentionally not called since this log is for | 979 // Note: RecordGeneralMetrics() intentionally not called since this log is for |
| 980 // stability stats from a previous session only. | 980 // stability stats from a previous session only. |
| 981 | 981 |
| 982 DVLOG(1) << "Generated an stability log."; | 982 DVLOG(1) << "Generated an stability log."; |
| 983 log_manager_.FinishCurrentLog(); | 983 log_manager_.FinishCurrentLog(&log_store_); |
| 984 log_manager_.ResumePausedLog(); | 984 log_manager_.ResumePausedLog(); |
| 985 | 985 |
| 986 // Store unsent logs, including the stability log that was just saved, so | 986 // Store unsent logs, including the stability log that was just saved, so |
| 987 // that they're not lost in case of a crash before upload time. | 987 // that they're not lost in case of a crash before upload time. |
| 988 log_manager_.PersistUnsentLogs(); | 988 log_store_.PersistUnsentLogs(); |
| 989 | 989 |
| 990 return true; | 990 return true; |
| 991 } | 991 } |
| 992 | 992 |
| 993 void MetricsService::PrepareInitialMetricsLog() { | 993 void MetricsService::PrepareInitialMetricsLog() { |
| 994 DCHECK_EQ(INIT_TASK_DONE, state_); | 994 DCHECK_EQ(INIT_TASK_DONE, state_); |
| 995 | 995 |
| 996 RecordCurrentEnvironment(initial_metrics_log_.get()); | 996 RecordCurrentEnvironment(initial_metrics_log_.get()); |
| 997 base::TimeDelta incremental_uptime; | 997 base::TimeDelta incremental_uptime; |
| 998 base::TimeDelta uptime; | 998 base::TimeDelta uptime; |
| 999 GetUptimes(local_state_, &incremental_uptime, &uptime); | 999 GetUptimes(local_state_, &incremental_uptime, &uptime); |
| 1000 | 1000 |
| 1001 // Histograms only get written to the current log, so make the new log current | 1001 // Histograms only get written to the current log, so make the new log current |
| 1002 // before writing them. | 1002 // before writing them. |
| 1003 log_manager_.PauseCurrentLog(); | 1003 log_manager_.PauseCurrentLog(); |
| 1004 log_manager_.BeginLoggingWithLog(std::move(initial_metrics_log_)); | 1004 log_manager_.BeginLoggingWithLog(std::move(initial_metrics_log_)); |
| 1005 | 1005 |
| 1006 // Note: Some stability providers may record stability stats via histograms, | 1006 // Note: Some stability providers may record stability stats via histograms, |
| 1007 // so this call has to be after BeginLoggingWithLog(). | 1007 // so this call has to be after BeginLoggingWithLog(). |
| 1008 MetricsLog* current_log = log_manager_.current_log(); | 1008 MetricsLog* current_log = log_manager_.current_log(); |
| 1009 current_log->RecordStabilityMetrics(metrics_providers_, base::TimeDelta(), | 1009 current_log->RecordStabilityMetrics(metrics_providers_, base::TimeDelta(), |
| 1010 base::TimeDelta()); | 1010 base::TimeDelta()); |
| 1011 current_log->RecordGeneralMetrics(metrics_providers_); | 1011 current_log->RecordGeneralMetrics(metrics_providers_); |
| 1012 RecordCurrentHistograms(); | 1012 RecordCurrentHistograms(); |
| 1013 | 1013 |
| 1014 DVLOG(1) << "Generated an initial log."; | 1014 DVLOG(1) << "Generated an initial log."; |
| 1015 log_manager_.FinishCurrentLog(); | 1015 log_manager_.FinishCurrentLog(&log_store_); |
| 1016 log_manager_.ResumePausedLog(); | 1016 log_manager_.ResumePausedLog(); |
| 1017 | 1017 |
| 1018 // Store unsent logs, including the initial log that was just saved, so | 1018 // Store unsent logs, including the initial log that was just saved, so |
| 1019 // that they're not lost in case of a crash before upload time. | 1019 // that they're not lost in case of a crash before upload time. |
| 1020 log_manager_.PersistUnsentLogs(); | 1020 log_store_.PersistUnsentLogs(); |
| 1021 | 1021 |
| 1022 state_ = SENDING_LOGS; | 1022 state_ = SENDING_LOGS; |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 void MetricsService::SendStagedLog() { | 1025 void MetricsService::SendStagedLog() { |
| 1026 DCHECK(log_manager_.has_staged_log()); | 1026 DCHECK(log_store_.has_staged_log()); |
| 1027 if (!log_manager_.has_staged_log()) | 1027 if (!log_store_.has_staged_log()) |
| 1028 return; | 1028 return; |
| 1029 | 1029 |
| 1030 DCHECK(!log_upload_in_progress_); | 1030 DCHECK(!log_upload_in_progress_); |
| 1031 log_upload_in_progress_ = true; | 1031 log_upload_in_progress_ = true; |
| 1032 | 1032 |
| 1033 if (!log_uploader_) { | 1033 if (!log_uploader_) { |
| 1034 log_uploader_ = client_->CreateUploader( | 1034 log_uploader_ = client_->CreateUploader( |
| 1035 client_->GetMetricsServerUrl(), | 1035 client_->GetMetricsServerUrl(), |
| 1036 metrics::kDefaultMetricsMimeType, | 1036 metrics::kDefaultMetricsMimeType, |
| 1037 base::Bind(&MetricsService::OnLogUploadComplete, | 1037 base::Bind(&MetricsService::OnLogUploadComplete, |
| 1038 self_ptr_factory_.GetWeakPtr())); | 1038 self_ptr_factory_.GetWeakPtr())); |
| 1039 } | 1039 } |
| 1040 const std::string hash = | 1040 const std::string hash = base::HexEncode(log_store_.staged_log_hash().data(), |
| 1041 base::HexEncode(log_manager_.staged_log_hash().data(), | 1041 log_store_.staged_log_hash().size()); |
| 1042 log_manager_.staged_log_hash().size()); | 1042 log_uploader_->UploadLog(log_store_.staged_log(), hash); |
| 1043 log_uploader_->UploadLog(log_manager_.staged_log(), hash); | |
| 1044 | 1043 |
| 1045 if (!upload_scheduler_) | 1044 if (!upload_scheduler_) |
| 1046 HandleIdleSinceLastTransmission(true); | 1045 HandleIdleSinceLastTransmission(true); |
| 1047 } | 1046 } |
| 1048 | 1047 |
| 1049 | 1048 |
| 1050 void MetricsService::OnLogUploadComplete(int response_code) { | 1049 void MetricsService::OnLogUploadComplete(int response_code) { |
| 1051 DVLOG(1) << "OnLogUploadComplete:" << response_code; | 1050 DVLOG(1) << "OnLogUploadComplete:" << response_code; |
| 1052 if (!upload_scheduler_) | 1051 if (!upload_scheduler_) |
| 1053 DCHECK_EQ(SENDING_LOGS, state_); | 1052 DCHECK_EQ(SENDING_LOGS, state_); |
| 1054 DCHECK(log_upload_in_progress_); | 1053 DCHECK(log_upload_in_progress_); |
| 1055 log_upload_in_progress_ = false; | 1054 log_upload_in_progress_ = false; |
| 1056 | 1055 |
| 1057 // Log a histogram to track response success vs. failure rates. | 1056 // Log a histogram to track response success vs. failure rates. |
| 1058 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", | 1057 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", |
| 1059 ResponseCodeToStatus(response_code), | 1058 ResponseCodeToStatus(response_code), |
| 1060 NUM_RESPONSE_STATUSES); | 1059 NUM_RESPONSE_STATUSES); |
| 1061 | 1060 |
| 1062 bool upload_succeeded = response_code == 200; | 1061 bool upload_succeeded = response_code == 200; |
| 1063 | 1062 |
| 1064 // Provide boolean for error recovery (allow us to ignore response_code). | 1063 // Provide boolean for error recovery (allow us to ignore response_code). |
| 1065 bool discard_log = false; | 1064 bool discard_log = false; |
| 1066 const size_t log_size = log_manager_.staged_log().length(); | 1065 const size_t log_size = log_store_.staged_log().length(); |
| 1067 if (upload_succeeded) { | 1066 if (upload_succeeded) { |
| 1068 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); | 1067 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); |
| 1069 } else if (log_size > kUploadLogAvoidRetransmitSize) { | 1068 } else if (log_size > kUploadLogAvoidRetransmitSize) { |
| 1070 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", | 1069 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", |
| 1071 static_cast<int>(log_size)); | 1070 static_cast<int>(log_size)); |
| 1072 discard_log = true; | 1071 discard_log = true; |
| 1073 } else if (response_code == 400) { | 1072 } else if (response_code == 400) { |
| 1074 // Bad syntax. Retransmission won't work. | 1073 // Bad syntax. Retransmission won't work. |
| 1075 discard_log = true; | 1074 discard_log = true; |
| 1076 } | 1075 } |
| 1077 | 1076 |
| 1078 if (upload_succeeded || discard_log) { | 1077 if (upload_succeeded || discard_log) { |
| 1079 log_manager_.DiscardStagedLog(); | 1078 log_store_.DiscardStagedLog(); |
| 1080 // Store the updated list to disk now that the removed log is uploaded. | 1079 // Store the updated list to disk now that the removed log is uploaded. |
| 1081 log_manager_.PersistUnsentLogs(); | 1080 log_store_.PersistUnsentLogs(); |
| 1082 } | 1081 } |
| 1083 | 1082 |
| 1084 // Error 400 indicates a problem with the log, not with the server, so | 1083 // Error 400 indicates a problem with the log, not with the server, so |
| 1085 // don't consider that a sign that the server is in trouble. | 1084 // don't consider that a sign that the server is in trouble. |
| 1086 bool server_is_healthy = upload_succeeded || response_code == 400; | 1085 bool server_is_healthy = upload_succeeded || response_code == 400; |
| 1087 if (upload_scheduler_) { | 1086 if (upload_scheduler_) { |
| 1088 if (!log_manager_.has_unsent_logs()) { | 1087 if (!log_store_.has_unsent_logs()) { |
| 1089 DVLOG(1) << "Stopping upload_scheduler_"; | 1088 DVLOG(1) << "Stopping upload_scheduler_"; |
| 1090 upload_scheduler_->Stop(); | 1089 upload_scheduler_->Stop(); |
| 1091 } | 1090 } |
| 1092 upload_scheduler_->UploadFinished(server_is_healthy); | 1091 upload_scheduler_->UploadFinished(server_is_healthy); |
| 1093 } else { | 1092 } else { |
| 1094 scheduler_->UploadFinished(server_is_healthy, | 1093 scheduler_->UploadFinished(server_is_healthy, log_store_.has_unsent_logs()); |
| 1095 log_manager_.has_unsent_logs()); | |
| 1096 } | 1094 } |
| 1097 } | 1095 } |
| 1098 | 1096 |
| 1099 void MetricsService::IncrementPrefValue(const char* path) { | 1097 void MetricsService::IncrementPrefValue(const char* path) { |
| 1100 int value = local_state_->GetInteger(path); | 1098 int value = local_state_->GetInteger(path); |
| 1101 local_state_->SetInteger(path, value + 1); | 1099 local_state_->SetInteger(path, value + 1); |
| 1102 } | 1100 } |
| 1103 | 1101 |
| 1104 void MetricsService::IncrementLongPrefsValue(const char* path) { | 1102 void MetricsService::IncrementLongPrefsValue(const char* path) { |
| 1105 int64_t value = local_state_->GetInt64(path); | 1103 int64_t value = local_state_->GetInt64(path); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 // Redundant setting to assure that we always reset this value at shutdown | 1247 // Redundant setting to assure that we always reset this value at shutdown |
| 1250 // (and that we don't use some alternate path, and not call LogCleanShutdown). | 1248 // (and that we don't use some alternate path, and not call LogCleanShutdown). |
| 1251 clean_shutdown_status_ = CLEANLY_SHUTDOWN; | 1249 clean_shutdown_status_ = CLEANLY_SHUTDOWN; |
| 1252 client_->OnLogCleanShutdown(); | 1250 client_->OnLogCleanShutdown(); |
| 1253 clean_exit_beacon_.WriteBeaconValue(true); | 1251 clean_exit_beacon_.WriteBeaconValue(true); |
| 1254 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); | 1252 SetExecutionPhase(ExecutionPhase::SHUTDOWN_COMPLETE, local_state_); |
| 1255 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, end_completed); | 1253 local_state_->SetBoolean(prefs::kStabilitySessionEndCompleted, end_completed); |
| 1256 } | 1254 } |
| 1257 | 1255 |
| 1258 } // namespace metrics | 1256 } // namespace metrics |
| OLD | NEW |