Skip to content

Commit

Permalink
[Cleanup] Pass a callback as a function argument, rather than caching…
Browse files Browse the repository at this point in the history
… it as a class variable.

This clarifies its lifetime and usage expectations.

BUG=none
TEST=none
R=asvitkine@chromium.org

Review URL: https://codereview.chromium.org/1302253002

Cr-Commit-Position: refs/heads/master@{#345100}
  • Loading branch information
ishermandom authored and Commit bot committed Aug 24, 2015
1 parent 110780e commit 878949c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions components/metrics/drive_metrics_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/base_paths.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/logging.h"
Expand Down Expand Up @@ -33,15 +34,13 @@ void DriveMetricsProvider::ProvideSystemProfileMetrics(
hardware->mutable_user_data_drive());
}

void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done) {
got_metrics_callback_ = done;

void DriveMetricsProvider::GetDriveMetrics(const base::Closure& done_callback) {
base::PostTaskAndReplyWithResult(
file_thread_.get(), FROM_HERE,
base::Bind(&DriveMetricsProvider::GetDriveMetricsOnFileThread,
local_state_path_key_),
base::Bind(&DriveMetricsProvider::GotDriveMetrics,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr(), done_callback));
}

DriveMetricsProvider::SeekPenaltyResponse::SeekPenaltyResponse()
Expand Down Expand Up @@ -81,10 +80,11 @@ void DriveMetricsProvider::QuerySeekPenalty(
}

void DriveMetricsProvider::GotDriveMetrics(
const base::Closure& done_callback,
const DriveMetricsProvider::DriveMetrics& metrics) {
DCHECK(thread_checker_.CalledOnValidThread());
metrics_ = metrics;
got_metrics_callback_.Run();
done_callback.Run();
}

void DriveMetricsProvider::FillDriveMetrics(
Expand Down
12 changes: 6 additions & 6 deletions components/metrics/drive_metrics_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
#define COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_

#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -37,7 +37,7 @@ class DriveMetricsProvider : public metrics::MetricsProvider {
metrics::SystemProfileProto* system_profile_proto) override;

// Called to start gathering metrics.
void GetDriveMetrics(const base::Closure& done);
void GetDriveMetrics(const base::Closure& done_callback);

private:
FRIEND_TEST_ALL_PREFIXES(DriveMetricsProviderTest, HasSeekPenalty);
Expand Down Expand Up @@ -69,7 +69,10 @@ class DriveMetricsProvider : public metrics::MetricsProvider {
SeekPenaltyResponse* response);

// Called when metrics are done being gathered from the FILE thread.
void GotDriveMetrics(const DriveMetrics& metrics);
// |done_callback| is the callback that should be called once all metrics are
// gathered.
void GotDriveMetrics(const base::Closure& done_callback,
const DriveMetrics& metrics);

// Fills |drive| with information from successful |response|s.
void FillDriveMetrics(const SeekPenaltyResponse& response,
Expand All @@ -86,9 +89,6 @@ class DriveMetricsProvider : public metrics::MetricsProvider {
// Information gathered about various important drives.
DriveMetrics metrics_;

// Called when metrics are done being collected.
base::Closure got_metrics_callback_;

base::ThreadChecker thread_checker_;
base::WeakPtrFactory<DriveMetricsProvider> weak_ptr_factory_;

Expand Down

0 comments on commit 878949c

Please sign in to comment.