Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: components/metrics/metrics_service.cc

Issue 290103005: Remove the provisional store and just store the staged log when writing to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/metrics/metrics_log_manager_unittest.cc ('k') | components/metrics/persisted_logs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 RecordCurrentHistograms(); 766 RecordCurrentHistograms();
767 current_log->RecordGeneralMetrics(metrics_providers_.get()); 767 current_log->RecordGeneralMetrics(metrics_providers_.get());
768 768
769 log_manager_.FinishCurrentLog(); 769 log_manager_.FinishCurrentLog();
770 } 770 }
771 771
772 void MetricsService::PushPendingLogsToPersistentStorage() { 772 void MetricsService::PushPendingLogsToPersistentStorage() {
773 if (state_ < SENDING_INITIAL_STABILITY_LOG) 773 if (state_ < SENDING_INITIAL_STABILITY_LOG)
774 return; // We didn't and still don't have time to get plugin list etc. 774 return; // We didn't and still don't have time to get plugin list etc.
775 775
776 if (log_manager_.has_staged_log()) {
777 // We may race here, and send second copy of the log later.
778 metrics::PersistedLogs::StoreType store_type;
779 if (log_upload_in_progress_)
780 store_type = metrics::PersistedLogs::PROVISIONAL_STORE;
781 else
782 store_type = metrics::PersistedLogs::NORMAL_STORE;
783 log_manager_.StoreStagedLogAsUnsent(store_type);
784 }
785 DCHECK(!log_manager_.has_staged_log());
786 CloseCurrentLog(); 776 CloseCurrentLog();
787 log_manager_.PersistUnsentLogs(); 777 log_manager_.PersistUnsentLogs();
788 778
789 // If there was a staged and/or current log, then there is now at least one 779 // If there was a staged and/or current log, then there is now at least one
790 // log waiting to be uploaded. 780 // log waiting to be uploaded.
791 if (log_manager_.has_unsent_logs()) 781 if (log_manager_.has_unsent_logs())
792 state_ = SENDING_OLD_LOGS; 782 state_ = SENDING_OLD_LOGS;
793 } 783 }
794 784
795 //------------------------------------------------------------------------------ 785 //------------------------------------------------------------------------------
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 1018
1029 void MetricsService::OnLogUploadComplete(int response_code) { 1019 void MetricsService::OnLogUploadComplete(int response_code) {
1030 DCHECK(log_upload_in_progress_); 1020 DCHECK(log_upload_in_progress_);
1031 log_upload_in_progress_ = false; 1021 log_upload_in_progress_ = false;
1032 1022
1033 // Log a histogram to track response success vs. failure rates. 1023 // Log a histogram to track response success vs. failure rates.
1034 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", 1024 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf",
1035 ResponseCodeToStatus(response_code), 1025 ResponseCodeToStatus(response_code),
1036 NUM_RESPONSE_STATUSES); 1026 NUM_RESPONSE_STATUSES);
1037 1027
1038 // If the upload was provisionally stored, drop it now that the upload is
1039 // known to have gone through.
1040 log_manager_.DiscardLastProvisionalStore();
1041
1042 bool upload_succeeded = response_code == 200; 1028 bool upload_succeeded = response_code == 200;
1043 1029
1044 // Provide boolean for error recovery (allow us to ignore response_code). 1030 // Provide boolean for error recovery (allow us to ignore response_code).
1045 bool discard_log = false; 1031 bool discard_log = false;
1046 const size_t log_size = log_manager_.staged_log().length(); 1032 const size_t log_size = log_manager_.staged_log().length();
1047 if (!upload_succeeded && log_size > kUploadLogAvoidRetransmitSize) { 1033 if (!upload_succeeded && log_size > kUploadLogAvoidRetransmitSize) {
1048 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded", 1034 UMA_HISTOGRAM_COUNTS("UMA.Large Rejected Log was Discarded",
1049 static_cast<int>(log_size)); 1035 static_cast<int>(log_size));
1050 discard_log = true; 1036 discard_log = true;
1051 } else if (response_code == 400) { 1037 } else if (response_code == 400) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 RecordCurrentState(local_state_); 1191 RecordCurrentState(local_state_);
1206 } 1192 }
1207 1193
1208 void MetricsService::RecordCurrentState(PrefService* pref) { 1194 void MetricsService::RecordCurrentState(PrefService* pref) {
1209 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec, 1195 pref->SetInt64(metrics::prefs::kStabilityLastTimestampSec,
1210 Time::Now().ToTimeT()); 1196 Time::Now().ToTimeT());
1211 1197
1212 for (size_t i = 0; i < metrics_providers_.size(); ++i) 1198 for (size_t i = 0; i < metrics_providers_.size(); ++i)
1213 metrics_providers_[i]->RecordCurrentState(); 1199 metrics_providers_[i]->RecordCurrentState();
1214 } 1200 }
OLDNEW
« no previous file with comments | « components/metrics/metrics_log_manager_unittest.cc ('k') | components/metrics/persisted_logs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698