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

Unified Diff: components/cronet/histogram_manager.cc

Issue 1882563004: [Cronet] Make HistogramManager public APIs thread-safe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make lock specific to GetDeltas() Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/histogram_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/histogram_manager.cc
diff --git a/components/cronet/histogram_manager.cc b/components/cronet/histogram_manager.cc
index 4ec3adffb30b5cf39c9b07f8d0e8aeace32d04ef..bb2ced02619053421439fb42c1001104769609a2 100644
--- a/components/cronet/histogram_manager.cc
+++ b/components/cronet/histogram_manager.cc
@@ -53,18 +53,21 @@ void HistogramManager::InconsistencyDetectedInLoggedCount(int amount) {
}
bool HistogramManager::GetDeltas(std::vector<uint8_t>* data) {
- // Clear the protobuf between calls.
- uma_proto_.Clear();
- // "false" to StatisticsRecorder::begin() indicates to *not* include
- // histograms held in persistent storage on the assumption that they will be
- // visible to the recipient through other means.
- histogram_snapshot_manager_.PrepareDeltas(
- base::StatisticsRecorder::begin(false), base::StatisticsRecorder::end(),
- base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
- int32_t data_size = uma_proto_.ByteSize();
- data->resize(data_size);
- if (uma_proto_.SerializeToArray(&(*data)[0], data_size))
- return true;
+ if (get_deltas_lock_.Try()) {
+ base::AutoLock lock(get_deltas_lock_, base::AutoLock::AlreadyAcquired());
+ // Clear the protobuf between calls.
+ uma_proto_.Clear();
+ // "false" to StatisticsRecorder::begin() indicates to *not* include
+ // histograms held in persistent storage on the assumption that they will be
+ // visible to the recipient through other means.
+ histogram_snapshot_manager_.PrepareDeltas(
+ base::StatisticsRecorder::begin(false), base::StatisticsRecorder::end(),
+ base::Histogram::kNoFlags, base::Histogram::kUmaTargetedHistogramFlag);
+ int32_t data_size = uma_proto_.ByteSize();
+ data->resize(data_size);
+ if (uma_proto_.SerializeToArray(&(*data)[0], data_size))
+ return true;
+ }
data->clear();
return false;
}
« no previous file with comments | « components/cronet/histogram_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698