Chromium Code Reviews| Index: components/metrics/call_stack_profile_metrics_provider.cc |
| diff --git a/components/metrics/call_stack_profile_metrics_provider.cc b/components/metrics/call_stack_profile_metrics_provider.cc |
| index 3dc55b9ea6d00f0a571cd4bcbb528867f03f6a9f..6e01a2fb1f6fb319763734e5845ac72374647205 100644 |
| --- a/components/metrics/call_stack_profile_metrics_provider.cc |
| +++ b/components/metrics/call_stack_profile_metrics_provider.cc |
| @@ -39,8 +39,10 @@ namespace { |
| // with them. |
| struct ProfilesState { |
| ProfilesState(const CallStackProfileParams& params, |
| - const base::StackSamplingProfiler::CallStackProfiles& profiles, |
| + base::StackSamplingProfiler::CallStackProfiles profiles, |
| base::TimeTicks start_timestamp); |
| + ProfilesState(ProfilesState&&); |
| + ProfilesState& operator=(ProfilesState&&); |
| // The metrics-related parameters provided to |
| // CallStackProfileMetricsProvider::GetProfilerCallback(). |
| @@ -54,16 +56,23 @@ struct ProfilesState { |
| // via CallStackProfileMetricsProvider::GetProfilerCallback(). Used to |
| // determine if collection was disabled during the collection of the profile. |
| base::TimeTicks start_timestamp; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ProfilesState); |
|
Alexei Svitkine (slow)
2016/10/24 15:26:22
Indent seems wrong. Run git cl format?
bcwhite
2016/10/24 21:30:30
Done.
|
| }; |
| ProfilesState::ProfilesState( |
| const CallStackProfileParams& params, |
| - const base::StackSamplingProfiler::CallStackProfiles& profiles, |
| + base::StackSamplingProfiler::CallStackProfiles profiles, |
| base::TimeTicks start_timestamp) |
| : params(params), |
| - profiles(profiles), |
| - start_timestamp(start_timestamp) { |
| -} |
| + profiles(std::move(profiles)), |
| + start_timestamp(start_timestamp) {} |
| + |
| +ProfilesState::ProfilesState(ProfilesState&&) = default; |
| + |
| +// Some versions of GCC need this for push_back to work with std::move. |
| +ProfilesState& ProfilesState::operator=(ProfilesState&&) = default; |
| // PendingProfiles ------------------------------------------------------------ |
| @@ -91,8 +100,8 @@ class PendingProfiles { |
| // True if profiles are being collected. |
| bool IsCollectionEnabled() const; |
| - // Adds |profile| to the list of profiles if collection is enabled. |
| - void CollectProfilesIfCollectionEnabled(const ProfilesState& profiles); |
| + // Adds |profiles| to the list of profiles if collection is enabled. |
| + void CollectProfilesIfCollectionEnabled(ProfilesState profiles); |
| // Allows testing against the initial state multiple times. |
| void ResetToDefaultStateForTesting(); |
| @@ -153,7 +162,7 @@ bool PendingProfiles::IsCollectionEnabled() const { |
| } |
| void PendingProfiles::CollectProfilesIfCollectionEnabled( |
| - const ProfilesState& profiles) { |
| + ProfilesState profiles) { |
| base::AutoLock scoped_lock(lock_); |
| // Only collect if collection is not disabled and hasn't been disabled |
| @@ -164,7 +173,7 @@ void PendingProfiles::CollectProfilesIfCollectionEnabled( |
| return; |
| } |
| - profiles_.push_back(profiles); |
| + profiles_.push_back(std::move(profiles)); |
| } |
| void PendingProfiles::ResetToDefaultStateForTesting() { |
| @@ -191,15 +200,14 @@ PendingProfiles::~PendingProfiles() {} |
| void ReceiveCompletedProfilesImpl( |
| const CallStackProfileParams& params, |
| base::TimeTicks start_timestamp, |
| - const StackSamplingProfiler::CallStackProfiles& profiles) { |
| + StackSamplingProfiler::CallStackProfiles profiles) { |
| PendingProfiles::GetInstance()->CollectProfilesIfCollectionEnabled( |
| - ProfilesState(params, profiles, start_timestamp)); |
| + ProfilesState(params, std::move(profiles), start_timestamp)); |
| } |
| // Invoked on an arbitrary thread. Ignores the provided profiles. |
| void IgnoreCompletedProfiles( |
| - const StackSamplingProfiler::CallStackProfiles& profiles) { |
| -} |
| + StackSamplingProfiler::CallStackProfiles profiles) {} |
| // Functions to encode protobufs ---------------------------------------------- |
| @@ -398,8 +406,8 @@ CallStackProfileMetricsProvider::GetProfilerCallback( |
| void CallStackProfileMetricsProvider::ReceiveCompletedProfiles( |
| const CallStackProfileParams& params, |
| base::TimeTicks start_timestamp, |
| - const base::StackSamplingProfiler::CallStackProfiles& profiles) { |
| - ReceiveCompletedProfilesImpl(params, start_timestamp, profiles); |
| + base::StackSamplingProfiler::CallStackProfiles profiles) { |
| + ReceiveCompletedProfilesImpl(params, start_timestamp, std::move(profiles)); |
| } |
| void CallStackProfileMetricsProvider::OnRecordingEnabled() { |