Chromium Code Reviews| Index: chrome/browser/metrics/perf_provider_chromeos.cc |
| diff --git a/chrome/browser/metrics/perf_provider_chromeos.cc b/chrome/browser/metrics/perf_provider_chromeos.cc |
| index 6bb48a3bef87c1f86d7d55ec51eae18ae9894c05..ead6f31c0b75bf0b85a18f5b1c0e58fde757e1c2 100644 |
| --- a/chrome/browser/metrics/perf_provider_chromeos.cc |
| +++ b/chrome/browser/metrics/perf_provider_chromeos.cc |
| @@ -72,6 +72,7 @@ enum GetPerfDataOutcome { |
| INCOGNITO_ACTIVE, |
| INCOGNITO_LAUNCHED, |
| PROTOBUF_NOT_PARSED, |
| + ILLEGAL_DATA_RETURNED, |
| NUM_OUTCOMES |
| }; |
| @@ -93,13 +94,16 @@ bool IsNormalUserLoggedIn() { |
| } // namespace |
| - |
| namespace metrics { |
| +namespace { |
| + |
| // This class must be created and used on the UI thread. It watches for any |
| // incognito window being opened from the time it is instantiated to the time it |
| // is destroyed. |
| -class WindowedIncognitoObserver : public chrome::BrowserListObserver { |
| +class WindowedIncognitoObserver |
| + : public chrome::BrowserListObserver, |
| + public PerfProvider::IncognitoObserverInterface { |
| public: |
| WindowedIncognitoObserver() : incognito_launched_(false) { |
| BrowserList::AddObserver(this); |
| @@ -109,7 +113,7 @@ class WindowedIncognitoObserver : public chrome::BrowserListObserver { |
| // This method can be checked to see whether any incognito window has been |
| // opened since the time this object was created. |
| - bool incognito_launched() { |
| + virtual bool incognito_launched() const override { |
| return incognito_launched_; |
| } |
| @@ -123,6 +127,8 @@ class WindowedIncognitoObserver : public chrome::BrowserListObserver { |
| bool incognito_launched_; |
| }; |
| +} // namespace |
| + |
| PerfProvider::PerfProvider() |
| : login_observer_(this), |
| next_profiling_interval_start_(base::TimeTicks::Now()), |
| @@ -321,11 +327,11 @@ void PerfProvider::CollectIfNecessary( |
| base::TimeDelta collection_duration = base::TimeDelta::FromSeconds( |
| kPerfCommandDurationDefaultSeconds); |
| - client->GetPerfData(collection_duration.InSeconds(), |
| - base::Bind(&PerfProvider::ParseProtoIfValid, |
| - weak_factory_.GetWeakPtr(), |
| - base::Passed(&incognito_observer), |
| - base::Passed(&sampled_profile))); |
| + client->GetPerfOutput( |
| + collection_duration.InSeconds(), |
| + base::Bind(&PerfProvider::ParseOutputProtoIfValid, |
| + weak_factory_.GetWeakPtr(), base::Passed(&incognito_observer), |
| + base::Passed(&sampled_profile))); |
| } |
| void PerfProvider::DoPeriodicCollection() { |
| @@ -360,10 +366,12 @@ void PerfProvider::CollectPerfDataAfterSessionRestore( |
| last_session_restore_collection_time_ = base::TimeTicks::Now(); |
| } |
| -void PerfProvider::ParseProtoIfValid( |
| - scoped_ptr<WindowedIncognitoObserver> incognito_observer, |
| +void PerfProvider::ParseOutputProtoIfValid( |
| + scoped_ptr<IncognitoObserverInterface> incognito_observer, |
| scoped_ptr<SampledProfile> sampled_profile, |
| - const std::vector<uint8>& data) { |
| + int result, |
| + const std::vector<uint8>& perf_data, |
| + const std::vector<uint8>& perf_stat) { |
| DCHECK(CalledOnValidThread()); |
| if (incognito_observer->incognito_launched()) { |
| @@ -371,29 +379,43 @@ void PerfProvider::ParseProtoIfValid( |
| return; |
| } |
| - PerfDataProto perf_data_proto; |
| - if (!perf_data_proto.ParseFromArray(data.data(), data.size())) { |
| + if (result != 0 || (perf_data.empty() && perf_stat.empty())) { |
| AddToPerfHistogram(PROTOBUF_NOT_PARSED); |
| return; |
| } |
| - // Populate a profile collection protobuf with the collected perf data and |
| - // extra metadata. |
| - cached_perf_data_.resize(cached_perf_data_.size() + 1); |
| - SampledProfile& collection_data = cached_perf_data_.back(); |
| - collection_data.Swap(sampled_profile.get()); |
| + if (!perf_data.empty() && !perf_stat.empty()) { |
| + AddToPerfHistogram(ILLEGAL_DATA_RETURNED); |
| + return; |
| + } |
| + |
| + if (!perf_data.empty()) { |
| + PerfDataProto perf_data_proto; |
| + if (!perf_data_proto.ParseFromArray(perf_data.data(), perf_data.size())) { |
| + AddToPerfHistogram(PROTOBUF_NOT_PARSED); |
| + return; |
| + } |
| + sampled_profile->set_ms_after_boot( |
| + perf_data_proto.timestamp_sec() * base::Time::kMillisecondsPerSecond); |
| + sampled_profile->mutable_perf_data()->Swap(&perf_data_proto); |
| + } |
| - // Fill out remaining fields of the SampledProfile protobuf. |
| - collection_data.set_ms_after_boot( |
| - perf_data_proto.timestamp_sec() * base::Time::kMillisecondsPerSecond); |
| + if (!perf_stat.empty()) { |
|
Ilya Sherman
2015/07/01 03:09:02
nit: I think it would be clearer to simply write t
Simon Que
2015/07/01 20:22:57
Done.
|
| + PerfStatProto perf_stat_proto; |
| + if (!perf_stat_proto.ParseFromArray(perf_stat.data(), perf_stat.size())) { |
| + AddToPerfHistogram(PROTOBUF_NOT_PARSED); |
| + return; |
| + } |
| + sampled_profile->mutable_perf_stat()->Swap(&perf_stat_proto); |
| + } |
| DCHECK(!login_time_.is_null()); |
| - collection_data. |
| - set_ms_after_login((base::TimeTicks::Now() - login_time_) |
| - .InMilliseconds()); |
| + sampled_profile->set_ms_after_login( |
| + (base::TimeTicks::Now() - login_time_).InMilliseconds()); |
| - // Finally, store the perf data itself. |
| - collection_data.mutable_perf_data()->Swap(&perf_data_proto); |
| + // Add the collected data to the container of collected SampledProfiles. |
| + cached_perf_data_.resize(cached_perf_data_.size() + 1); |
| + cached_perf_data_.back().Swap(sampled_profile.get()); |
| } |
| } // namespace metrics |